/* ============================================================
   MarQ Automação — Grupo 3V
   Mesmo sistema visual de /admin/, /quadro/ e /dashboard/: base
   clara, topbar azul-petróleo, oliva como cor de ação.
   ============================================================ */

:root {
  --bg: #f4f1ea;
  --surface: #fffefa;
  --surface-2: #f8f5ee;
  --surface-3: #eee7d9;
  --line: rgba(22, 58, 66, .14);
  --line-strong: rgba(22, 58, 66, .28);
  --text: #173a43;
  --muted: #637a7c;
  --faint: #8d9b9a;
  --brand-blue: #0e3a45;
  --brand-blue-2: #123f4b;
  --brand: #968b66;
  --brand-strong: #7f7554;
  --ok: #2f9d72;
  --ok-bg: rgba(47, 157, 114, .12);
  --ok-border: rgba(47, 157, 114, .28);
  --warn: #c88424;
  --warn-bg: rgba(200, 132, 36, .13);
  --warn-border: rgba(200, 132, 36, .30);
  --danger: #c84f49;
  --danger-bg: rgba(200, 79, 73, .12);
  --danger-border: rgba(200, 79, 73, .30);
  --blue: #1e6f91;
  --shadow: 0 14px 34px rgba(14, 58, 69, .10);
  --r: 10px;
  --sidebar-w: 250px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Cascadia Code", "Fira Code", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(150, 139, 102, .18), transparent 34rem),
    linear-gradient(180deg, #fbfaf6 0, var(--bg) 42%);
  color: var(--text);
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
a { color: inherit; text-decoration: none; }

/* ── Shell: sidebar + main ─────────────────────────────────────── */

.shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(255, 254, 250, .92);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 28px rgba(14, 58, 69, .06);
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 18px 16px;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-2));
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  color: white;
}

.mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .10);
  border: 1px solid rgba(255, 255, 255, .28);
  color: #f3ead3;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .04em;
  flex: 0 0 auto;
}

.sidebar-header strong { display: block; font-size: 14px; line-height: 1.25; }
.sidebar-header span { display: block; color: rgba(255, 255, 255, .72); font-size: 11px; margin-top: 2px; }

.nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 12px;
}

.nav-group-title {
  padding: 16px 16px 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--brand);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1px 8px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 13px;
  color: var(--text);
}

.nav-item:hover {
  background: var(--surface-2);
  border-color: var(--line);
}

.nav-item.active {
  background: var(--brand-blue);
  border-color: var(--brand-blue);
  color: #fff;
  box-shadow: 0 10px 22px rgba(14, 58, 69, .15);
}

.nav-item .icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.token-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
}

.token-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.token-dot.ok { background: var(--ok); }
.token-dot.alerta { background: var(--warn); }
.token-dot.expirado, .token-dot.ausente { background: var(--danger); }

/* ── Main / topbar / page ──────────────────────────────────────── */

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  min-height: 62px;
  padding: 12px 22px;
  background: rgba(255, 254, 250, .92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(14, 58, 69, .07);
}

.topbar h1 { margin: 0; font-size: 18px; }
.topbar .hint { margin: 2px 0 0; }

.top-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.page {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

/* ── Botões / inputs ────────────────────────────────────────────── */

.button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r);
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
}

.button:hover:not(:disabled) { border-color: var(--line-strong); filter: brightness(1.03); }
.button.primary { background: var(--brand); border-color: var(--brand); color: white; }
.button.primary:hover:not(:disabled) { background: var(--brand-strong); }
.button.ghost { background: transparent; }
.button.danger { border-color: var(--danger-border); color: var(--danger); }
.button.small { padding: 5px 8px; font-size: 12px; min-height: 30px; }

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.field { display: grid; gap: 4px; min-width: 130px; }
.field.grow { flex: 1 1 200px; }

.field label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  font-size: 10px;
  font-weight: 800;
}

input, select {
  width: 100%;
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 10px;
  outline: none;
}

input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(150, 139, 102, .14); }

.toggle-field {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text);
  padding-bottom: 8px;
}

.toggle-field input { width: auto; }

.hint { color: var(--muted); font-size: 13px; }

/* ── Cabeçalho de view ─────────────────────────────────────────── */

.view-header { margin: 0 0 16px; }
.view-header h2 { margin: 0; font-size: 22px; }
.view-header p { margin: 5px 0 0; color: var(--muted); font-size: 13px; max-width: 760px; }

/* ── Cards de estatística ──────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 0 0 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 15px 16px;
}

.stat-value { display: block; color: var(--brand-blue); font-size: 26px; font-weight: 850; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { display: block; color: var(--muted); font-size: 11px; margin-top: 7px; text-transform: uppercase; letter-spacing: .05em; }

.stat-card.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.stat-card.critical { background: var(--danger-bg); border-color: var(--danger-border); }
.stat-card.ok { background: var(--ok-bg); border-color: var(--ok-border); }
.stat-card.warn .stat-value { color: var(--warn); }
.stat-card.critical .stat-value { color: var(--danger); }
.stat-card.ok .stat-value { color: #167455; }

/* ── Cards genéricos / seções ──────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 16px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .hint { font-size: 12px; }

/* ── Tabelas ────────────────────────────────────────────────────── */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
table.data-table th { color: var(--muted); font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; background: rgba(255,255,255,.5); position: sticky; top: 0; }
table.data-table td { color: var(--text); }
table.data-table td.wrap { white-space: normal; min-width: 220px; }
table.data-table tr:last-child td { border-bottom: 0; }
table.data-table tr.expandable { cursor: pointer; }
table.data-table tr.expandable:hover { background: var(--surface-2); }
table.data-table tr.expand-detail td { background: var(--surface-2); white-space: normal; }

.table-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
.table-toolbar input[type=search] { max-width: 260px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 10px 12px; border-top: 1px solid var(--line); }
.pager span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── Badges / pills ─────────────────────────────────────────────── */

.pill { display: inline-flex; align-items: center; justify-content: center; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; background: var(--surface-3); color: var(--text); white-space: nowrap; }
.pill.critical, .pill.critico { background: var(--danger-bg); color: #9f302b; }
.pill.warn, .pill.atencao { background: var(--warn-bg); color: #8b5d14; }
.pill.ok { background: var(--ok-bg); color: #167455; }
.pill.muted { background: var(--surface-3); color: var(--muted); }

/* ── Progresso (SSE) ────────────────────────────────────────────── */

.progress-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text);
}

.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress-log { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ── Arquivos gerados ───────────────────────────────────────────── */

.file-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text);
}
.file-chip:hover { border-color: var(--brand); color: var(--brand-strong); }
.file-chip .ext { font-weight: 800; color: var(--brand-strong); text-transform: uppercase; }

/* ── Mensagens (Notificar / Alertas preview) ───────────────────── */

.message-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.message-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.message-card-head h4 { margin: 0; font-size: 14px; }
.message-card-head .hint { font-size: 12px; margin-top: 2px; }

.message-body {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
  max-height: 320px;
  overflow-y: auto;
  color: var(--text);
}

/* ── Empty / error states ──────────────────────────────────────── */

.empty-state, .loading-state {
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
  padding: 48px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.empty-state strong { font-size: 16px; }
.empty-state span, .loading-state p { color: var(--muted); font-size: 13px; }

.notice { border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 12px; background: var(--warn-bg); padding: 12px 14px; margin-bottom: 16px; }
.notice.error { border-left-color: var(--danger); background: var(--danger-bg); color: #7a231f; }
.notice.ok { border-left-color: var(--ok); background: var(--ok-bg); }

/* ── Drawer (arquivos gerados) ──────────────────────────────────── */

.drawer-backdrop { position: fixed; inset: 0; background: rgba(14,58,69,.35); z-index: 40; display: none; }
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(14,58,69,.2);
  z-index: 41;
  transform: translateX(100%);
  transition: transform .18s ease;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 14px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 10px; }

/* ── Tokens / bookmarklet ───────────────────────────────────────── */

.tokens-card { max-width: 620px; }
.tokens-steps { padding-left: 1.3rem; color: var(--muted); line-height: 2; margin: 0 0 1.2rem; }
.tokens-steps code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: .85em; }
.bookmarklet-area { text-align: center; padding: 1.4rem; background: var(--surface-2); border-radius: 12px; margin-bottom: 1rem; }
.bookmarklet-btn { display: inline-block; padding: .6rem 1.4rem; background: var(--brand); color: #fff; border-radius: 10px; font-weight: 700; border: 2px dashed rgba(255,255,255,.6); cursor: grab; }
.bookmarklet-hint { color: var(--muted); font-size: .82rem; margin: .6rem 0 0; }

/* ── Scrollbar ──────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; }

/* ── Print ──────────────────────────────────────────────────────── */

@media print {
  .sidebar, .topbar, .form-row, .top-actions, .drawer, .drawer-backdrop { display: none !important; }
  .page { width: 100%; padding: 0; }
}

/* ── Responsivo ─────────────────────────────────────────────────── */

@media (max-width: 980px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-scroll { max-height: 260px; }
}

@media (max-width: 640px) {
  .page { width: min(100% - 20px, 760px); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-row { flex-direction: column; align-items: stretch; }
}
