:root {
  color-scheme: dark;
  --bg: #08120e;
  --bg-grad: radial-gradient(circle at 12% 0%, #0d2b1d 0%, #08120e 55%);
  --surface: #0e1e18;
  --surface-2: #142a21;
  --surface-3: #1b362b;
  --border: #1e3b2e;
  --border-strong: #2c5543;
  --text: #f3f7f2;
  --text-muted: #9eb3a6;
  --brand-green: #074D2B;
  --brand-lime: #8FD929;
  --brand-pale: #E8FBB7;
  --brand-orange: #FF8A00;
  --danger: #ff5c5c;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Oswald', 'Arial Narrow', sans-serif;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  background-image: var(--bg-grad);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  accent-color: var(--brand-lime);
}

[hidden] {
  display: none !important;
}

h1, h2, h3, .font-display {
  font-family: var(--font-display);
  letter-spacing: 0.015em;
  margin: 0;
  font-weight: 600;
}

.mono, .money {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.84rem;
}

.text-center {
  text-align: center;
}

.positive { color: var(--brand-lime); }
.negative { color: var(--danger); }
.warning-text { color: var(--brand-orange); }

/* Focus visível acessível */
:focus-visible {
  outline: 2px solid var(--brand-lime);
  outline-offset: 2px;
}

/* Toasts */
.toast-region {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--brand-lime);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 0.9rem;
  pointer-events: auto;
}

.toast.toast-error {
  border-left-color: var(--danger);
}

.toast.toast-warn {
  border-left-color: var(--brand-orange);
}

/* Login / Convite */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 1.75rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.auth-logo-heading {
  margin: 0;
  display: flex;
  justify-content: center;
}

.auth-logo {
  width: min(260px, 100%);
  height: auto;
  border-radius: 12px;
  background: var(--brand-green);
  border: 1px solid rgba(143, 217, 41, 0.28);
  padding: 12px 18px;
  flex-shrink: 0;
}

.auth-brand h1 {
  font-size: 1.65rem;
  color: var(--brand-pale);
  margin-top: 0.2rem;
}

.pill-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(143, 217, 41, 0.14);
  color: var(--brand-lime);
  border: 1px solid rgba(143, 217, 41, 0.35);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: #0a1813;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.85rem;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.35rem 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.sidebar-logo {
  width: 64px;
  height: auto;
  border-radius: 8px;
  background: var(--brand-green);
  border: 1px solid rgba(143, 217, 41, 0.25);
  padding: 5px 7px;
}

.sidebar-brand-text strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--brand-pale);
}

.phase-pill {
  display: inline-block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--brand-green);
  color: var(--brand-pale);
  border: 1px solid rgba(143, 217, 41, 0.3);
}

.phase-pill.phase-2 {
  background: rgba(143, 217, 41, 0.2);
  color: var(--brand-lime);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.62rem 0.75rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item[aria-current="page"] {
  background: linear-gradient(90deg, rgba(143, 217, 41, 0.18), rgba(7, 77, 43, 0.35));
  color: var(--brand-pale);
  border-color: rgba(143, 217, 41, 0.4);
  font-weight: 600;
}

.nav-badge {
  background: var(--brand-orange);
  color: #111;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.user-chip strong {
  display: block;
  font-size: 0.92rem;
}

.main-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 18, 14, 0.88);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title-group h1 {
  font-size: 1.55rem;
  color: var(--brand-pale);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.warning-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 1.5rem 0;
  padding: 0.75rem 1rem;
  background: rgba(255, 138, 0, 0.12);
  border: 1px solid rgba(255, 138, 0, 0.45);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.info-banner {
  padding: 0.75rem 0.9rem;
  background: rgba(143, 217, 41, 0.09);
  border: 1px solid rgba(143, 217, 41, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.view-root {
  padding: 1.35rem 1.5rem 2.5rem;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
}

/* Grids & Cards */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}

.card + .card, .section-gap {
  margin-top: 1.1rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}

.card-head h2, .card-head h3 {
  font-size: 1.2rem;
  color: var(--brand-pale);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.stat-label {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  margin: 0.2rem 0;
  font-variant-numeric: tabular-nums;
}

/* Payback progress bar */
.payback-hero {
  background: linear-gradient(135deg, #0b291c 0%, #11241b 100%);
  border: 1px solid rgba(143, 217, 41, 0.35);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.1rem;
}

.progress-track {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #07110d;
  border: 1px solid var(--border-strong);
  overflow: hidden;
  margin: 0.65rem 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-green), var(--brand-lime));
  transition: width 0.35s ease;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s, background 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand-lime);
  color: #07190f;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-warn {
  background: var(--brand-orange);
  color: #140b00;
}

.btn-danger {
  background: rgba(255, 92, 92, 0.16);
  color: #ff9c9c;
  border-color: rgba(255, 92, 92, 0.45);
}

.btn-sm {
  min-height: 34px;
  padding: 0.3rem 0.7rem;
  font-size: 0.82rem;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
}

/* Forms */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--brand-pale);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  font: inherit;
  font-size: max(1rem, 1em);
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  background: #091510;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.field textarea {
  min-height: 82px;
  resize: vertical;
}

.field input:user-invalid,
.field select:user-invalid {
  border-color: var(--danger);
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.password-wrap {
  display: flex;
  gap: 0.45rem;
  align-items: stretch;
}

.password-wrap input {
  flex: 1;
}

.form-error {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 92, 92, 0.14);
  border: 1px solid rgba(255, 92, 92, 0.4);
  color: #ffb4b4;
  font-size: 0.88rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

@supports not (accent-color: #8FD929) {
  input[type="range"] {
    background: var(--surface-3);
  }
}

/* Search / Filter bar */
search form, .filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filter-bar .field {
  min-width: 150px;
  flex: 1;
}

/* Tabs */
[role="tablist"] {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  padding-bottom: 0.1rem;
}

[role="tab"] {
  position: relative;
  flex: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 0.95rem;
  cursor: pointer;
}

[role="tab"][aria-selected="true"] {
  color: var(--brand-lime);
}

[role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 3px solid var(--brand-lime);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.badge-ok { background: rgba(143, 217, 41, 0.16); color: var(--brand-lime); border: 1px solid rgba(143, 217, 41, 0.35); }
.badge-warn { background: rgba(255, 138, 0, 0.16); color: var(--brand-orange); border: 1px solid rgba(255, 138, 0, 0.4); }
.badge-danger { background: rgba(255, 92, 92, 0.16); color: #ff9c9c; border: 1px solid rgba(255, 92, 92, 0.4); }
.badge-neutral { background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border-strong); }

/* Responsive Tables */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 75vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
}

.data-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-2);
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: rgba(143, 217, 41, 0.04);
}

.num-col {
  text-align: right !important;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@container (width < 640px) {
  .data-table, .data-table thead, .data-table tbody, .data-table tr, .data-table th, .data-table td {
    display: block;
  }
  .data-table thead {
    display: none;
  }
  .data-table tr {
    margin: 0.65rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.07);
    text-align: right !important;
  }
  .data-table td:last-child {
    border-bottom: none;
  }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
}

/* Native Modal Dialog */
dialog.app-modal {
  width: min(680px, calc(100vw - 1.5rem));
  max-height: 90dvh;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.75);
}

dialog.app-modal:modal {
  overscroll-behavior: contain;
}

dialog.app-modal::backdrop {
  background: rgba(4, 10, 8, 0.78);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.modal-title {
  font-size: 1.25rem;
  color: var(--brand-pale);
}

.modal-body {
  padding: 1.25rem;
}

/* Cascata & Waterfall steps */
.waterfall-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.wf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.wf-row.wf-highlight {
  background: rgba(143, 217, 41, 0.11);
  border-color: rgba(143, 217, 41, 0.4);
  font-weight: 600;
}

.qr-box {
  background: #ffffff;
  display: inline-block;
  padding: 0.5rem;
  border-radius: 8px;
}

.mobile-only {
  display: none;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .mobile-only {
    display: inline-flex;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 270px;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.6);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .topbar {
    padding: 0.75rem 1rem;
  }
  .view-root {
    padding: 1rem 0.9rem 2rem;
  }
}

@media print {
  body {
    background: #ffffff !important;
    color: #111111 !important;
  }
  .sidebar, .topbar, .warning-banner, .no-print, .btn {
    display: none !important;
  }
  .app-shell {
    display: block;
  }
  .card, .stat-card {
    border: 1px solid #cccccc;
    background: #ffffff;
    color: #111111;
    break-inside: avoid;
  }
  .muted, .stat-label {
    color: #444444 !important;
  }
  .positive, .negative {
    color: #111111 !important;
  }
}
