:root {
  --brand: #1f485c;
  --ink: #25313a;
  --muted: #66737d;
  --line: #d9e1e6;
  --soft: #f4f7f9;
  --panel: #ffffff;
  --gray: #4d4d4d;
  --green: #118c4f;
  --warn: #f58220;
  --danger: #dc2626;
  --shadow: 0 16px 40px rgba(31, 72, 92, .12);
}

* { box-sizing: border-box; }
html, body {
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(90deg, var(--brand) 0 270px, #eef3f6 270px 100%);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  background: var(--brand);
  color: #fff;
  padding: 22px 16px;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 270px;
  overflow-y: auto;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  margin-bottom: 24px;
}

.brand img {
  width: 154px;
  height: auto;
  display: block;
}

.nav-menu {
  display: grid;
  gap: 6px;
}

.nav-menu a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.88);
  font-weight: 500;
}

.nav-menu a:hover {
  background: rgba(255,255,255,.12);
  color: #fff;
}

.nav-menu .iconify { font-size: 21px; flex: 0 0 21px; }
.main-shell {
  min-width: 0;
  margin-left: 270px;
}

.topbar {
  min-height: 82px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar > div:not(.topbar-actions) {
  min-width: 0;
}

.topbar h1 {
  font-size: 22px;
  line-height: 1.15;
  margin: 0;
  overflow-wrap: anywhere;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.content {
  padding: 24px;
  display: grid;
  gap: 18px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

[data-sidebar-toggle] {
  display: none;
  flex: 0 0 40px;
}

.icon-button .iconify { font-size: 22px; }

.user-pill, .badge {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #e7eef2;
  color: var(--brand);
  font-weight: 800;
  font-size: 12px;
}

.user-pill {
  min-width: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.kpi-card, .panel, .empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card {
  padding: 18px;
  border-left: 5px solid var(--brand);
  min-width: 0;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.accent-gray { border-left-color: var(--gray); }
.accent-green { border-left-color: var(--green); }
.accent-warn { border-left-color: var(--warn); }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  min-width: 0;
}

.panel-grid.single {
  grid-template-columns: 1fr;
}

.panel, .empty-state { padding: 18px; }
.panel, .empty-state, .panel-grid > *, .content > * { min-width: 0; }

.table-wrap table td.no-padding {
  padding: 0;
  vertical-align: top;
}

.inner-row {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.inner-row:last-child {
  border-bottom: none;
}
.panel h2, .empty-state h2 { margin: 0 0 10px; font-size: 18px; }
.panel p, .empty-state p { color: var(--muted); margin: 0; }
.panel canvas { max-width: 100%; }
.panel-note {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.field {
  grid-column: span 4;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field.span-6 { grid-column: span 6; }
.field.span-12 { grid-column: 1 / -1; }
.field.compact { grid-column: span 2; }

.field label {
  color: var(--gray);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c7d2da;
  border-radius: 8px;
  background: #fff;
  padding: 9px 11px;
  outline: none;
}

.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31,72,92,.14);
}

.field span, .field .field-validation-error {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.field.invalid input, .field.invalid select, .field.invalid textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .12);
}

.form-alert {
  display: none;
  margin-top: 14px;
  border-radius: 8px;
  padding: 11px 12px;
  font-weight: 800;
}

.form-alert.ok {
  display: block;
  background: #dcfce7;
  color: #166534;
}

.form-alert.err {
  display: block;
  background: #fee2e2;
  color: #991b1b;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.section-heading > div { min-width: 0; }
.section-heading h2 { margin: 0 0 4px; }
.section-heading p { margin: 0; color: var(--muted); }

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button, .secondary-button {
  max-width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 500;
  font-size: 14px;
  white-space: normal;
  cursor: pointer;
}

.primary-button { background: var(--brand); color: #fff; }
.secondary-button { background: #e7eef2; color: var(--brand); }
.compact-button { min-height: 32px; padding: 6px 10px; font-size: 12px; }

.table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th, td {
  text-align: left;
  padding: 11px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  background: var(--soft);
  color: var(--gray);
  font-size: 12px;
  text-transform: uppercase;
}

.group-row td {
  background: #eef6fa;
  color: var(--brand);
  font-weight: 900;
}

.total-row td {
  background: #ecfdf5;
  color: #064e3b;
  font-weight: 900;
}

.selection-table tr.is-selected td {
  background: #eef6fa;
  color: var(--brand);
  font-weight: 800;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at top left, rgba(31,72,92,.16), transparent 32%), #eef3f6;
}

.login-card {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card img {
  width: 150px;
  display: block;
  margin-bottom: 20px;
}

.login-card h1 {
  margin: 0;
  font-size: 26px;
}

.login-card p {
  color: var(--muted);
  margin: 8px 0 22px;
}

.login-card form {
  display: grid;
  gap: 14px;
}

.login-card .field {
  grid-column: 1 / -1;
}

.validation-summary {
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .46);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-box {
  width: min(540px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, .32);
  padding: 20px;
}

.modal-box h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.modal-box form {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.trace-result {
  margin-top: 14px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.trace-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  min-width: 0;
}

.trace-group h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--brand);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.tab-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
  font-size: 14px;
  padding: 0 12px;
  cursor: pointer;
}

.tab-button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.status-ativo {
  background: #dcfce7;
  color: #166534;
}

.status-inativo {
  background: #fee2e2;
  color: #991b1b;
}

@media (max-width: 980px) {
  body { background: #eef3f6; }
  .app-shell { display: block; }
  .main-shell { margin-left: 0; }
  [data-sidebar-toggle] { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    transform: translateX(-100%);
    transition: transform .18s ease;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .kpi-grid, .panel-grid { grid-template-columns: 1fr; }
  .field, .field.compact { grid-column: span 6; }
}

@media (max-width: 680px) {
  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    padding: 14px;
  }
  .topbar-actions {
    min-width: 0;
    justify-content: flex-end;
  }
  .topbar .user-pill { max-width: 92px; }
  .content { padding: 14px; }
  .field, .field.compact, .field.span-6 { grid-column: 1 / -1; }
  .section-heading { flex-direction: column; }
  table { min-width: 620px; }
}
