:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #f8f9fc;
  --border: #e4e7f0;
  --text: #121726;
  --text-muted: #666f85;
  --text-faint: #97a0b5;

  --brand: #2b5bff;
  --brand-dark: #1b3fc4;
  --brand-tint: #eef2ff;

  --success: #16a34a;
  --success-tint: #e9f9ee;
  --warning: #b45309;
  --warning-tint: #fef3e0;
  --danger: #dc2626;
  --danger-tint: #fdecec;
  --info: #0369a1;
  --info-tint: #e7f4fb;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(18, 23, 38, 0.06);
  --shadow-md: 0 6px 20px -6px rgba(18, 23, 38, 0.14);
  --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f1a;
    --surface: #121826;
    --surface-alt: #161d2e;
    --border: #232c40;
    --text: #e7eaf2;
    --text-muted: #9aa3ba;
    --text-faint: #636d85;
    --brand-tint: #182341;
    --success-tint: #0e2a1b;
    --warning-tint: #332208;
    --danger-tint: #341414;
    --info-tint: #0f2433;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f1a;
  --surface: #121826;
  --surface-alt: #161d2e;
  --border: #232c40;
  --text: #e7eaf2;
  --text-muted: #9aa3ba;
  --text-faint: #636d85;
  --brand-tint: #182341;
  --success-tint: #0e2a1b;
  --warning-tint: #332208;
  --danger-tint: #341414;
  --info-tint: #0f2433;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--brand-tint); }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform .2s ease;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; flex-shrink: 0; }
.brand .mark svg { width: 18px; height: 18px; }
.brand .name { font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
.brand .sub { font-size: .72rem; color: var(--text-faint); margin-top: 1px; }

nav.navlist { flex: 1; overflow-y: auto; padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.navitem {
  display: flex; align-items: center; gap: 11px;
  border: none; background: none; width: 100%;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .87rem; font-weight: 500;
  cursor: pointer; text-align: left;
}
.navitem svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.navitem:hover { background: var(--surface-alt); color: var(--text); }
.navitem.active { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }
:root[data-theme="dark"] .navitem.active, @media (prefers-color-scheme: dark) { }
.navitem .count {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 20px; min-width: 18px; text-align: center;
}
.navitem .count:empty, .navitem .count.zero { display: none; }

.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border); font-size: .72rem; color: var(--text-faint); }

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
  flex-shrink: 0;
}
header.topbar h1 { font-size: 1.05rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.sync-line { font-size: .78rem; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.dot.stale { background: var(--text-faint); }
.dot.err { background: var(--danger); }

#content { flex: 1; overflow-y: auto; padding: 24px 28px 60px; }
.pane { display: none; }
.pane.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 14px; font-weight: 600; font-size: .83rem; cursor: pointer;
  transition: filter .12s, background .12s;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-success { background: var(--success-tint); color: var(--success); }
.btn-success:hover { filter: brightness(.95); }
.btn-warning { background: var(--warning-tint); color: var(--warning); }
.btn-danger { background: var(--danger-tint); color: var(--danger); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 10px; font-size: .78rem; }
.icon-btn { background: none; border: none; cursor: pointer; display: grid; place-items: center; padding: 6px; border-radius: var(--radius-sm); color: var(--text-muted); }
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }

/* ---------- Cards / stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 18px; position: relative; overflow: hidden;
}
.stat-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent, var(--brand)); }
.stat-card.c-warning { --accent: var(--warning); }
.stat-card.c-danger { --accent: var(--danger); }
.stat-card.c-success { --accent: var(--success); }
.stat-card .label { font-size: .78rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }
.stat-card .value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.stat-card .hint { font-size: .74rem; color: var(--text-faint); margin-top: 4px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: .92rem; font-weight: 700; margin: 0; }
.panel-head .meta { font-size: .76rem; color: var(--text-faint); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-faint); font-weight: 700; padding: 0 10px 8px; }
td { padding: 10px; border-top: 1px solid var(--border); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-alt); }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 20px; font-size: .72rem; font-weight: 700; }
.pill-success { background: var(--success-tint); color: var(--success); }
.pill-warning { background: var(--warning-tint); color: var(--warning); }
.pill-danger { background: var(--danger-tint); color: var(--danger); }
.pill-info { background: var(--info-tint); color: var(--info); }
.pill-neutral { background: var(--surface-alt); color: var(--text-muted); }

/* ---------- Queue layout ---------- */
.queue-layout { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; height: calc(100vh - 172px); }
@media (max-width: 960px) { .queue-layout { grid-template-columns: 1fr; height: auto; } }

.queue-list { overflow-y: auto; height: 100%; padding: 6px; }
.queue-search { position: sticky; top: 0; background: var(--surface); padding-bottom: 10px; z-index: 2; }
.queue-search input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; background: var(--surface-alt);
}
.queue-item {
  padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px; cursor: pointer; background: var(--surface);
}
.queue-item:hover { border-color: var(--brand); }
.queue-item.selected { border-color: var(--brand); background: var(--brand-tint); }
.queue-item .top-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.queue-item .os-id { font-weight: 700; font-size: .88rem; }
.queue-item .client { font-size: .83rem; color: var(--text); margin-bottom: 2px; }
.queue-item .meta { font-size: .76rem; color: var(--text-faint); }

.detail-panel { overflow-y: auto; height: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 22px; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.detail-header h2 { font-size: 1.05rem; margin: 0 0 4px; }
.detail-header .sub { font-size: .82rem; color: var(--text-muted); }

.section { margin-bottom: 20px; }
.section h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; margin: 0 0 10px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; font-size: .86rem; }
.kv-grid .k { color: var(--text-faint); font-size: .76rem; }
.kv-grid .v { font-weight: 600; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo-chip {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 6px;
  text-decoration: none; color: var(--text-muted); font-size: .72rem; text-align: center; background: var(--surface-alt);
}
.photo-chip:hover { border-color: var(--brand); color: var(--brand); }
.photo-chip svg { width: 20px; height: 20px; }

textarea.obs {
  width: 100%; min-height: 72px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; background: var(--surface-alt); resize: vertical; margin-top: 8px;
}
.action-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- States ---------- */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-faint); font-size: .85rem; }
.empty-state svg { width: 36px; height: 36px; margin-bottom: 10px; opacity: .5; }
.skeleton { background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border) 37%, var(--surface-alt) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); height: 58px; margin-bottom: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(43,91,255,.18); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px 26px; box-shadow: var(--shadow-md);
}
.login-card .mark { width: 44px; height: 44px; border-radius: var(--radius-sm); background: var(--brand); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.login-card .mark svg { width: 24px; height: 24px; }
.login-card h1 { font-size: 1.05rem; margin: 0 0 4px; }
.login-card p.sub { font-size: .82rem; color: var(--text-muted); margin: 0 0 20px; }
.field-label { display: block; font-size: .8rem; font-weight: 600; margin: 14px 0 6px; }
.field-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-alt); color: var(--text);
}
.login-error { margin-top: 12px; font-size: .82rem; color: var(--danger); min-height: 1em; }
.login-foot { margin-top: 18px; font-size: .74rem; color: var(--text-faint); text-align: center; }

/* ---------- Modal (troca de senha) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 600; background: rgba(10, 14, 26, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius-lg);
  padding: 26px; box-shadow: var(--shadow-md);
}
.modal-card h2 { font-size: 1rem; margin: 0 0 6px; }
.modal-card p.sub { font-size: .82rem; color: var(--text-muted); margin: 0 0 18px; }

/* ---------- User badge / admin ---------- */
.user-badge { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.user-badge .who { flex: 1; min-width: 0; }
.user-badge .who .nm { font-size: .82rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-badge .who .role { font-size: .72rem; color: var(--text-faint); }
.user-badge button { background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 6px; border-radius: var(--radius-sm); }
.user-badge button:hover { background: var(--surface-alt); color: var(--text); }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px 20px; }
.temp-pass-box {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--success-tint);
  color: var(--success); font-size: .84rem;
}
.temp-pass-box strong { font-size: 1.05rem; letter-spacing: .5px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 22px; right: 22px; max-width: 360px;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: .83rem; box-shadow: var(--shadow-md); z-index: 999;
  opacity: 0; transform: translateY(8px); transition: all .2s ease; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.t-success { background: var(--success); color: #fff; }
#toast.t-error { background: var(--danger); color: #fff; }

/* ---------- Mobile ---------- */
.mobile-topbar { display: none; }
@media (max-width: 760px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); box-shadow: var(--shadow-md); }
  #sidebar.open { transform: translateX(0); }
  .mobile-topbar { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
  header.topbar { display: none; }
  #content { padding: 16px; }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; display: none; }
  .sidebar-scrim.show { display: block; }
}

/* ---------- Setup banner (API não configurada) ---------- */
.setup-banner {
  background: var(--warning-tint); border: 1px solid var(--warning); color: var(--warning);
  border-radius: var(--radius-md); padding: 14px 18px; margin-bottom: 20px; font-size: .85rem;
}
.setup-banner code { background: rgba(0,0,0,.08); padding: 1px 6px; border-radius: 4px; }
