:root {
  --amber: #f59e0b;
  --amber-2: #d97706;
  --amber-soft: #fef3c7;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --bg: #f8fafc;
  --card: #ffffff;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  font-family:
    Inter,
    "Segoe UI",
    system-ui,
    -apple-system,
    Roboto,
    sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}
a {
  color: inherit;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
.loading {
  padding: 48px;
  color: var(--muted);
  text-align: center;
}

/* Login */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
.login-card .brand {
  margin-bottom: 24px;
}
.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

/* Layout */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
}
.brand img {
  width: 30px;
  height: 30px;
  border-radius: 7px;
}
.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}
.nav a {
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  color: #cbd5e1;
  white-space: nowrap;
}
.nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}
.nav a.active {
  color: var(--ink);
  background: var(--amber);
  font-weight: 600;
}
.user {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cbd5e1;
  white-space: nowrap;
}
.user button {
  background: transparent;
  border: 1px solid #475569;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}
h2 {
  font-size: 20px;
  margin: 0 0 4px;
}
.sub {
  color: var(--muted);
  margin: 0 0 20px;
}
.section {
  margin-top: 28px;
}
.section h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

/* Cards */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi .v {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.kpi .l {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.kpi.warn .v {
  color: var(--amber-2);
}
.kpi.bad .v {
  color: var(--red);
}
.kpi.good .v {
  color: var(--green);
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel.pad {
  padding: 16px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th,
td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f1f5f9;
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tr.click {
  cursor: pointer;
}
tr.click:hover td {
  background: #fffbeb;
}
tfoot td {
  font-weight: 700;
  border-top: 1px solid var(--line-2);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.b-pos {
  background: var(--green-soft);
  color: var(--green);
}
.b-neg {
  background: var(--red-soft);
  color: var(--red);
}
.b-warn {
  background: var(--amber-soft);
  color: var(--amber-2);
}
.b-info {
  background: var(--blue-soft);
  color: var(--blue);
}
.b-muted {
  background: #f1f5f9;
  color: var(--muted);
}

/* Forms */
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
input,
select,
textarea {
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  width: 100%;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}
textarea {
  min-height: 84px;
  resize: vertical;
}
.btn {
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--amber);
  color: var(--ink);
}
.btn:hover {
  background: var(--amber-2);
  color: #fff;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.ghost {
  background: #fff;
  border: 1.5px solid var(--line-2);
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: #f1f5f9;
  color: var(--ink);
}
.btn.danger {
  background: var(--red);
  color: #fff;
}
.btn.block {
  width: 100%;
}
.error {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
}
.hint {
  color: var(--muted);
  font-size: 12px;
}
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters input {
  flex: 1 1 260px;
}
.filters select {
  flex: 0 0 180px;
  width: auto;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.spacer {
  flex: 1;
}
.pager {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 12px;
  color: var(--muted);
}

/* Chart */
.chart {
  width: 100%;
  height: auto;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-2);
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* Ficha */
.ficha {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}
.ficha .avatar {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  background: #e2e8f0;
  display: block;
}
.dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}
.dl div {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.dl dt {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dl dd {
  margin: 2px 0 0;
  font-weight: 600;
}
.docs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.docs figure {
  margin: 0;
  cursor: zoom-in;
}
.docs img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #e2e8f0;
}
.docs figcaption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline li {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.timeline li:last-child {
  border-bottom: 0;
}
.timeline .t {
  font-weight: 600;
}
.timeline .m {
  color: var(--muted);
  font-size: 12px;
}
.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-weight: 600;
}
.alert.ok {
  background: var(--green-soft);
  color: var(--green);
}
.alert.bad {
  background: var(--red-soft);
  color: var(--red);
}

/* Modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  padding: 22px;
}
.modal h3 {
  margin: 0 0 14px;
}
.modal .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
  z-index: 60;
  display: grid;
  place-items: center;
  cursor: zoom-out;
}
.viewer img {
  max-width: 96vw;
  max-height: 94vh;
  object-fit: contain;
}
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 70;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.toast.err {
  background: var(--red);
}

@media (max-width: 860px) {
  .ficha {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 0 12px;
    gap: 12px;
  }
  .user .who {
    display: none;
  }
  main {
    padding: 16px;
  }
}
