:root {
  --bg: #FAFCFB;
  --surface: #FFFFFF;
  --ink: #021B1A;
  --ink-soft: #5A6B68;
  --line: #E4ECEA;
  --green: #00DF81;
  --green-ink: #03624C;
  --green-soft: #E6FBF2;
  --danger: #D14343;
  --danger-soft: #FBEAEA;
  --warn: #B7791F;
  --warn-soft: #FBF3E4;
  --dark: #021B1A;
  --font: 'Plus Jakarta Sans', -apple-system, sans-serif;
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px; --s6: 48px; --s8: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(2,27,26,0.06), 0 4px 16px rgba(2,27,26,0.04);
}

[data-theme="dark"] {
  --bg: #0A1413;
  --surface: #0F1D1B;
  --ink: #F1F7F6;
  --ink-soft: #8FA3A0;
  --line: #1E312E;
  --green-ink: #2CC295;
  --green-soft: rgba(0, 223, 129, 0.12);
  --danger: #E06C6C;
  --danger-soft: rgba(224, 108, 108, 0.14);
  --warn: #D9A03F;
  --warn-soft: rgba(217, 160, 63, 0.14);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.2);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; color: inherit; font-size: inherit; }
input, select, textarea { font-family: var(--font); font-size: 15px; color: var(--ink); }
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── Login ── */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--dark); padding: var(--s3); }
.login-card { background: var(--surface); border-radius: 16px; padding: var(--s6) var(--s4); width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--s2); }
.login-logo { height: 40px; width: auto; align-self: center; filter: invert(1) brightness(0.1); margin: var(--s1) 0 var(--s3); }
.login-card label { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); display: flex; flex-direction: column; gap: 6px; }
.login-card input { padding: 12px 14px; border: 1.5px solid #D5E0DD; border-radius: 10px; background: #F3F7F6; transition: border-color 150ms ease-out; }
.login-card input:focus { outline: none; border-color: var(--green-ink); }
.login-error { color: var(--danger); font-size: 13px; text-align: center; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 14px; transition: opacity 150ms ease-out, transform 150ms ease-out; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--green); color: #021B1A; }
.btn-primary:hover { opacity: 0.88; }
.btn-ghost { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink-soft); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-icon { padding: 8px; border-radius: 8px; color: var(--ink-soft); }
.btn-icon:hover { background: var(--bg); color: var(--ink); }

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--dark); color: rgba(255,255,255,0.7); display: flex; flex-direction: column; padding: var(--s3) var(--s2); gap: 4px; position: fixed; top: 0; bottom: 0; left: 0; z-index: 10; }
.sidebar-logo { height: 20px; width: auto; align-self: flex-start; margin: var(--s1) var(--s2) var(--s4); }
.sidebar a { display: flex; align-items: center; gap: 12px; padding: 11px var(--s2); border-radius: 10px; font-weight: 500; font-size: 14px; position: relative; transition: color 150ms ease-out, background 150ms ease-out; }
.sidebar a:hover { color: #fff; background: rgba(255,255,255,0.05); }
.sidebar a.active { color: #fff; background: rgba(255,255,255,0.07); }
.sidebar a.active::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--green); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: var(--s1); padding: var(--s2); border-top: 1px solid rgba(255,255,255,0.08); font-size: 12px; }
.sidebar-footer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer button { color: rgba(255,255,255,0.5); padding: 6px; border-radius: 8px; }
.sidebar-footer button:hover { color: #fff; }

.view { flex: 1; margin-left: 240px; padding: var(--s6) var(--s6) var(--s8); max-width: 1200px; }

/* ── Page header ── */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s4); flex-wrap: wrap; }
.page-head h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; }
.page-head .actions { display: flex; gap: var(--s1); align-items: center; flex-wrap: wrap; }

/* ── Cards & grids ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: var(--s3); }
.grid-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); margin-bottom: var(--s3); }
.stat { padding: var(--s3); }
.stat .label { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .value.pos { color: var(--green-ink); }
.stat .value.neg { color: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--s2); margin-bottom: var(--s3); }
.section-title { font-size: 18px; font-weight: 600; margin-bottom: var(--s2); }
.card .section-title { padding: var(--s3) var(--s3) 0; }

/* ── Tables ── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); padding: 12px var(--s2); border-bottom: 1px solid var(--line); }
.table td { padding: 14px var(--s2); border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; transition: background 150ms ease-out; }
.table tbody tr.clickable:hover { background: var(--bg); }
.table .num { text-align: right; font-weight: 600; }
.table .actions-cell { text-align: right; white-space: nowrap; }

/* ── Badges & pills ── */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge + .badge { margin-left: 4px; }
.badge-service { background: var(--bg); border: 1px solid var(--line); color: var(--ink-soft); }
.badge-green { background: var(--green-soft); color: var(--green-ink); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-amber { background: var(--warn-soft); color: var(--warn); }
.badge-gray { background: var(--bg); border: 1px solid var(--line); color: var(--ink-soft); }

/* ── Segmented control ── */
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--ink-soft); transition: background 150ms ease-out, color 150ms ease-out; }
.segmented button.active { background: var(--dark); color: #fff; }

/* ── Search ── */
.search { padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 220px; }
.search:focus { outline: none; border-color: var(--green-ink); }

/* ── Empty state ── */
.empty { text-align: center; padding: var(--s6) var(--s3); color: var(--ink-soft); }
.empty .ok { color: var(--green-ink); font-weight: 600; }
.empty .btn { margin-top: var(--s2); }

/* ── Bar chart ── */
.chart { display: flex; align-items: flex-end; gap: var(--s2); height: 160px; padding: var(--s3); }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 48px; border-radius: 6px 6px 0 0; background: var(--green-ink); min-height: 2px; transition: opacity 150ms ease-out; }
.chart .bar.current { background: var(--green); }
.chart .bar-label { font-size: 11px; color: var(--ink-soft); font-weight: 500; }
.chart .bar-value { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* ── Client detail ── */
.client-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s3); flex-wrap: wrap; }
.client-head .info h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 6px; }
.client-head .meta { display: flex; align-items: center; gap: var(--s1); flex-wrap: wrap; }
.client-head .mv { font-size: 15px; font-weight: 600; color: var(--green-ink); }
.links-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s1); }
.link-card { display: flex; align-items: center; gap: 10px; padding: var(--s2); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-weight: 500; font-size: 14px; transition: border-color 150ms ease-out; }
.link-card:hover { border-color: var(--green-ink); }
.link-card svg { color: var(--green-ink); flex-shrink: 0; }
.link-card.add { color: var(--ink-soft); border-style: dashed; justify-content: center; cursor: pointer; }
.contact-list { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.contact-list .row { display: flex; gap: 8px; }
.contact-list .row .k { color: var(--ink-soft); min-width: 60px; }
.notes-area { width: 100%; min-height: 120px; border: 1px solid var(--line); border-radius: 10px; padding: var(--s2); resize: vertical; background: var(--surface); }
.notes-area:focus { outline: none; border-color: var(--green-ink); }
.save-hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; min-height: 16px; }
.save-hint.saved { color: var(--green-ink); }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(2,27,26,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: var(--s3); }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: var(--s4); }
.modal h2 { font-size: 18px; font-weight: 600; margin-bottom: var(--s3); }
.modal form { display: flex; flex-direction: column; gap: var(--s2); }
.modal label { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); display: flex; flex-direction: column; gap: 6px; }
.modal input, .modal select, .modal textarea { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.modal input:focus, .modal select:focus, .modal textarea:focus { outline: none; border-color: var(--green-ink); }
.modal .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.modal .checks { display: flex; gap: var(--s2); flex-direction: row; }
.modal .checks label { flex-direction: row; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; }
.modal .checks input { width: 16px; height: 16px; accent-color: var(--green-ink); }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: var(--s1); margin-top: var(--s1); }

/* ── Toast ── */
#toast-root { position: fixed; bottom: var(--s3); right: var(--s3); z-index: 200; display: flex; flex-direction: column; gap: var(--s1); }
.toast { background: var(--dark); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); animation: toast-in 200ms ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Tabs (financeiro) ── */
.month-nav { display: inline-flex; align-items: center; gap: var(--s1); font-weight: 600; }
.month-nav button { padding: 6px 10px; border-radius: 8px; color: var(--ink-soft); }
.month-nav button:hover { background: var(--surface); color: var(--ink); }
.month-nav .label { min-width: 130px; text-align: center; text-transform: capitalize; }

/* ── Action list (home) ── */
.action-list { display: flex; flex-direction: column; }
.action-item { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 14px var(--s3); border-bottom: 1px solid var(--line); }
.action-item:last-child { border-bottom: none; }
.action-item .who { font-weight: 600; }
.action-item .sub { font-size: 13px; color: var(--ink-soft); }
.summary-list { display: flex; flex-direction: column; gap: 10px; padding: var(--s3); font-size: 14px; }
.summary-list .row { display: flex; justify-content: space-between; }
.summary-list .row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.summary-list .total { border-top: 1px solid var(--line); padding-top: 10px; font-weight: 600; }

/* ── Materials ── */
.mat-group { margin-bottom: var(--s3); }
.mat-group h3 { font-size: 14px; font-weight: 600; color: var(--ink-soft); margin-bottom: var(--s1); text-transform: uppercase; letter-spacing: 0.06em; }
.mat-item { display: flex; align-items: center; gap: 12px; padding: 12px var(--s2); border-bottom: 1px solid var(--line); }
.mat-item:last-child { border-bottom: none; }
.mat-item svg { color: var(--green-ink); flex-shrink: 0; }
.mat-item .t { font-weight: 500; }
.mat-item .d { font-size: 12px; color: var(--ink-soft); }
.mat-item .spacer { flex: 1; }

/* ── Theme toggle ── */
.theme-toggle { width: 36px; height: 36px; border-radius: 999px; display: flex; align-items: center; justify-content: center; color: var(--ink-soft); transition: color 150ms ease-out, transform 150ms ease-out; }
.theme-toggle:hover { color: var(--ink); }
.theme-toggle:active { transform: scale(0.92); }
.theme-float { position: fixed; top: 16px; right: 16px; z-index: 300; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; margin: var(--s1) var(--s2) var(--s4); }
.sidebar-top .sidebar-logo { margin: 0; }
.theme-sidebar { color: rgba(255,255,255,0.5); width: 32px; height: 32px; }
.theme-sidebar:hover { color: #fff; background: rgba(255,255,255,0.08); }

/* ── Period filter popover ── */
.period-wrap { position: relative; }
.period-btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 13px; font-weight: 500; color: var(--ink); }
.period-btn:hover { border-color: var(--ink-soft); }
.period-btn svg { width: 15px; height: 15px; color: var(--ink-soft); }
.popover { position: absolute; top: calc(100% + 6px); right: 0; z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(2,27,26,0.14); padding: 6px; min-width: 190px; }
.popover .opt { display: block; width: 100%; text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--ink); }
.popover .opt:hover { background: var(--bg); }
.popover .opt.active { background: var(--green-soft); color: var(--green-ink); }
.popover .custom { border-top: 1px solid var(--line); margin-top: 6px; padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 8px; }
.popover .custom label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); display: flex; flex-direction: column; gap: 3px; }
.popover .custom input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 13px; }

/* ── SVG chart ── */
.chart-svg { width: 100%; height: auto; display: block; padding: var(--s2) var(--s3) var(--s3); }
.chart-svg text { font-family: var(--font); font-size: 11px; fill: var(--ink-soft); }
.chart-legend { display: flex; gap: var(--s3); padding: 0 var(--s3); font-size: 13px; color: var(--ink-soft); }
.chart-legend .li { display: flex; align-items: center; gap: 6px; }
.chart-legend .dot { width: 10px; height: 10px; border-radius: 3px; }

/* ── Donut ── */
.donut-wrap { display: flex; align-items: center; gap: var(--s3); padding: var(--s3); }
.donut { width: 130px; height: 130px; border-radius: 50%; position: relative; flex-shrink: 0; }
.donut::after { content: ''; position: absolute; inset: 22px; border-radius: 50%; background: var(--surface); }
.donut .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1; }
.donut .center .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut .center .l { font-size: 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; flex: 1; }
.donut-legend .row { display: flex; align-items: center; gap: 8px; }
.donut-legend .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.donut-legend .v { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Dark mode fixes ── */
[data-theme="dark"] .login-logo { filter: none; }
[data-theme="dark"] .login-card input { background: #142523; border-color: #24403C; color: var(--ink); }
[data-theme="dark"] .login-screen { background: #071110; }
[data-theme="dark"] .segmented button.active { background: #F1F7F6; color: #021B1A; }
[data-theme="dark"] .toast { background: #F1F7F6; color: #021B1A; }
[data-theme="dark"] .sidebar { border-right: 1px solid var(--line); }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.6); }

/* ── Funnel ── */
.funnel { display: flex; flex-direction: column; gap: 14px; padding: var(--s3); }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 50px 50px; align-items: center; gap: var(--s2); }
.funnel-row .fl { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.fbar-track { height: 26px; background: var(--bg); border-radius: 8px; overflow: hidden; }
.fbar { height: 100%; border-radius: 8px; background: linear-gradient(90deg, #03624C, #00DF81); transition: width 400ms cubic-bezier(0.4, 0, 0.2, 1); }
.funnel-row .fv { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.funnel-row .fc { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; text-align: right; }

/* ── Mobile ── */
@media (max-width: 900px) {
  .sidebar { width: 100%; height: 64px; bottom: 0; top: auto; flex-direction: row; align-items: center; padding: 0 var(--s1); gap: 0; }
  .sidebar-top { margin: 0; }
  .sidebar-logo, .sidebar-footer span { display: none; }
  .donut-wrap { flex-direction: column; }
  .sidebar a { flex: 1; flex-direction: column; gap: 2px; font-size: 10px; padding: 8px 4px; justify-content: center; }
  .sidebar a.active::before { top: 0; bottom: auto; left: 20%; right: 20%; width: auto; height: 3px; }
  .sidebar-footer { margin: 0; border: none; padding: 8px; }
  .view { margin-left: 0; padding: var(--s3) var(--s2) 96px; }
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .links-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 22px; }
  .table thead { display: none; }
  .table tbody tr { display: block; border-bottom: 1px solid var(--line); padding: var(--s1) 0; }
  .table td { display: flex; justify-content: space-between; border: none; padding: 4px var(--s2); }
  .table td::before { content: attr(data-label); font-size: 12px; color: var(--ink-soft); font-weight: 500; }
  .table .num, .table .actions-cell { text-align: left; }
  .modal { max-width: none; }
}
