:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --ink: #0d1526;
  --ink-2: #26324a;
  --muted: #6b7a90;
  --line: #e4eaf3;
  --line-2: #eef2f8;
  --brand: #1b4dd8;
  --brand-2: #2f6bff;
  --brand-soft: #eaf0ff;
  --teal: #0f9b8e;
  --teal-soft: #e6f7f5;
  --amber: #b7791f;
  --amber-soft: #fdf6e7;
  --red: #c53030;
  --red-soft: #fdecec;
  --green: #1f7a4d;
  --green-soft: #e9f7ef;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(13, 21, 38, .06), 0 1px 3px rgba(13, 21, 38, .04);
  --shadow: 0 6px 24px rgba(13, 21, 38, .07);
  --shadow-lg: 0 24px 60px rgba(13, 21, 38, .18);
  --sidebar: 250px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; }
::selection { background: #cddcff; }

/* ---------------------------------------------------------------- login */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
}
.auth-brand {
  background:
    radial-gradient(900px 500px at -10% -20%, #2f6bff 0%, transparent 55%),
    radial-gradient(700px 500px at 110% 120%, #0f9b8e 0%, transparent 50%),
    linear-gradient(150deg, #0e1a3c 0%, #16295e 55%, #0c1b45 100%);
  color: #fff;
  padding: 56px 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-brand::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(80% 70% at 30% 20%, #000 30%, transparent 100%);
}
.auth-brand > * { position: relative; z-index: 1; }
.auth-brand h1 { font-size: 40px; line-height: 1.12; letter-spacing: -.02em; margin: 0 0 16px; font-weight: 700; }
.auth-brand p { color: #c8d5f2; font-size: 15.5px; max-width: 460px; margin: 0; }
.auth-bullets { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-bullets li { display: flex; gap: 10px; color: #dbe5fa; font-size: 13.5px; align-items: flex-start; }
.auth-bullets svg { flex: 0 0 18px; margin-top: 2px; color: #7ce0d3; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 24px; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; font-size: 13.5px; }

/* ---------------------------------------------------------------- app shell */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; flex: 0 0 auto; }

/* o menu é a única parte que rola: nunca corta itens nem prende a página */
.sidebar > nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  padding-right: 2px;
  margin-right: -2px;
}
.sidebar > nav::-webkit-scrollbar { width: 6px; }
.sidebar > nav::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
.sidebar > nav::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.sidebar > nav::-webkit-scrollbar-track { background: transparent; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(145deg, var(--brand-2), #1237a8);
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 14px rgba(27, 77, 216, .28);
}
.logo-name { font-weight: 700; letter-spacing: -.02em; font-size: 16.5px; }
.logo-sub { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .09em; margin-top: -2px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #94a3b8; padding: 13px 12px 5px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; border-radius: 10px; color: var(--ink-2);
  font-size: 13.5px; font-weight: 500; cursor: pointer; user-select: none;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg { width: 18px; height: 18px; opacity: .72; }
.nav-item:hover { background: #f4f7fd; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-badge { margin-left: auto; background: var(--red-soft); color: var(--red); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { flex: 0 0 auto; margin-top: auto; border-top: 1px solid var(--line-2); padding-top: 10px; }
.user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 12.5px; }
.user-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--muted); }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 64px; display: flex; align-items: center; gap: 14px;
  padding: 0 28px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.page-sub { font-size: 12px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 48px; max-width: 1360px; width: 100%; }

/* ---------------------------------------------------------------- components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { padding: 16px 18px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 12px; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 650; }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }

.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.k4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid.k3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 720px) { .grid.k4, .grid.k3, .grid.k2 { grid-template-columns: 1fr; } }

.kpi { padding: 16px 18px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 550; }
.kpi-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.kpi-icon.teal { background: var(--teal-soft); color: var(--teal); }
.kpi-icon.amber { background: var(--amber-soft); color: var(--amber); }
.kpi-icon.red { background: var(--red-soft); color: var(--red); }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.025em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.kpi-foot strong { color: var(--green); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 550; cursor: pointer;
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(27,77,216,.22); }
.btn.primary:hover { background: #1a45c2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f2f5fb; }
.btn.danger { color: var(--red); border-color: #f3d2d2; background: #fff; }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); font-weight: 400; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 13.5px; font-family: inherit; color: var(--ink); background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #9db9ff; box-shadow: 0 0 0 3px rgba(47,107,255,.12);
}
textarea { min-height: 74px; resize: vertical; }
input[type="checkbox"] { width: auto; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: #94a3b8; }
.search input { padding-left: 34px; }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 650; padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr:hover td { background: #fafcff; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow: auto; max-height: calc(100vh - 250px); }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.badge.gray { background: #f1f4f9; color: #64748b; }
.badge.teal { background: var(--teal-soft); color: var(--teal); }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .35; margin-bottom: 10px; }
.empty h4 { margin: 0 0 4px; color: var(--ink-2); font-size: 14px; }
.empty p { margin: 0 0 14px; font-size: 13px; }

.modal-back {
  position: fixed; inset: 0; background: rgba(13,21,38,.42); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 60; padding: 20px;
  animation: fade .16s ease;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 620px;
  box-shadow: var(--shadow-lg); max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .18s ease;
}
.modal.wide { max-width: 900px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 20px 22px; overflow: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); border-radius: 0 0 16px 16px; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99) } to { opacity: 1; transform: none } }

.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 90; }
.toast {
  background: #0f1a2f; color: #fff; padding: 11px 16px; border-radius: 11px; font-size: 13px;
  box-shadow: var(--shadow); animation: slide .2s ease; max-width: 380px;
}
.toast.err { background: #7f1d1d; }
.toast.ok { background: #0f5132; }
@keyframes slide { from { opacity: 0; transform: translateX(12px) } to { opacity: 1; transform: none } }

.tabs { display: flex; gap: 4px; background: #eef2f9; padding: 4px; border-radius: 11px; }
.tab { padding: 6px 13px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding: 8px 4px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; justify-content: flex-end; height: 100%; }
.chart .bar {
  width: 100%; max-width: 54px; border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #4a80ff, #1b4dd8); min-height: 4px;
  transition: height .5s cubic-bezier(.2,.8,.2,1); position: relative;
}
.chart .bar:hover { filter: brightness(1.06); }
.chart .lbl { font-size: 11px; color: var(--muted); }
.chart .val { font-size: 11px; font-weight: 650; color: var(--ink-2); }

.list { display: grid; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.rank { width: 22px; height: 22px; border-radius: 7px; background: #f1f4f9; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }

.alert { display: flex; gap: 10px; padding: 11px 14px; border-radius: 11px; font-size: 12.8px; background: var(--amber-soft); color: #7c5713; border: 1px solid #f4e3bd; margin-bottom: 12px; }
.alert.info { background: var(--brand-soft); color: #1c3fa8; border-color: #cfe0ff; }

.footnote { font-size: 11.5px; color: var(--muted); margin-top: 10px; }

.skeleton { background: linear-gradient(90deg, #eef2f8 25%, #f7f9fc 37%, #eef2f8 63%); background-size: 400% 100%; animation: sk 1.2s ease infinite; border-radius: 8px; }
@keyframes sk { from { background-position: 100% 50% } to { background-position: 0 50% } }

/* ---------------------------------------------------------------- impressão */
.print-only { display: none; }
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .toolbar, .no-print, .toasts { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .print-only { display: block; }
  .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
  table { font-size: 11px; }
  thead th { background: #f2f2f2 !important; }
  .table-wrap { max-height: none; overflow: visible; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 50;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
}


/* seletor de ambiente (locação / manutenção) */
.amb-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 10px 12px 14px; padding: 4px; border-radius: 10px;
  background: rgba(255,255,255,.06);
}
.amb-switch button {
  border: 0; cursor: pointer; padding: 8px 6px; border-radius: 7px;
  background: transparent; color: inherit; font: inherit; font-size: 12.5px; font-weight: 600;
  opacity: .65; transition: .15s;
}
.amb-switch button:hover { opacity: 1; }
.amb-switch button.on { background: #fff; color: #0f172a; opacity: 1; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
