/* ===== Design system ===== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #17203a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
}
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-2: #1b2740;
  --text: #e6ebf5;
  --muted: #8b98b3;
  --border: #24304d;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  transition: background .25s, color .25s;
}
a { cursor: pointer; }
h1, h2, h3 { font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red); font-size: 13px; margin: 8px 0; }
.info { color: var(--green); font-size: 13px; margin: 8px 0; }

/* ===== Inputs / botões ===== */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  font-size: 15px; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: background .15s, transform .05s;
  background: var(--surface-2); color: var(--text); margin-top: 16px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.icon-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px; border-radius: 8px; display: inline-flex;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

/* ===== Autenticação ===== */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--bg) 0%, color-mix(in srgb, var(--primary) 12%, var(--bg)) 100%);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  padding: 36px 32px;
}
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo h1 { font-size: 26px; margin-top: 12px; }
.logo-badge {
  width: 56px; height: 56px; margin: 0 auto;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; font-weight: 800; font-size: 20px;
  border-radius: 16px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 45%, transparent);
}
.logo-badge.sm { width: 34px; height: 34px; font-size: 13px; border-radius: 10px; margin: 0; }
.auth-links { display: flex; justify-content: space-between; margin-top: 18px; font-size: 13.5px; }
.auth-links.center { justify-content: center; }
.auth-links a { color: var(--primary); font-weight: 600; text-decoration: none; }

/* ===== Layout do app ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px;
  padding: 20px 20px 14px;
}
.sidebar nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.sidebar nav a, .side-footer a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin: 2px 0;
  border-radius: 10px; color: var(--muted);
  font-weight: 550; font-size: 14.5px; text-decoration: none;
  transition: background .12s, color .12s;
}
.sidebar nav a:hover, .side-footer a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active, .side-footer a.active {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
}
.sidebar .icon svg { width: 19px; height: 19px; }
.side-footer { padding: 10px 12px 16px; border-top: 1px solid var(--border); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar h2 { font-size: 18px; flex: 1; }
.menu-toggle { display: none; }
.content { padding: 26px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ===== Cards ===== */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.card h3 { margin-bottom: 6px; font-size: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.placeholder { text-align: center; padding: 70px 24px; }
.placeholder-icon svg { width: 44px; height: 44px; color: var(--muted); margin-bottom: 14px; }

/* ===== Cores utilitárias ===== */
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ===== Toolbar / filtros ===== */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar .btn { margin-top: 0; }
.btn.income { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.btn.expense { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.btn.income:hover { background: color-mix(in srgb, var(--green) 26%, transparent); }
.btn.expense:hover { background: color-mix(in srgb, var(--red) 26%, transparent); }
.btn svg { width: 17px; height: 17px; }
.btn.sm { padding: 7px 14px; font-size: 13.5px; }
.btn.xs { padding: 4px 10px; font-size: 12.5px; margin-top: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 13px; font-size: 13.5px; font-weight: 600;
}
.chip.cat { border: none; background: var(--surface-2); font-weight: 550; padding: 4px 10px; }
.filters {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr 1fr;
  gap: 10px; padding: 14px 16px; margin-bottom: 18px;
}
.filters input, .filters select { padding: 9px 11px; font-size: 13.5px; }

/* ===== Stats (dashboard) ===== */
.month-nav { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 18px; }
.month-label { font-weight: 700; font-size: 17px; min-width: 170px; text-align: center; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 750; }
.stat-sub { font-size: 12px; color: var(--amber); }
.grid-2 + .grid-2 { margin-top: 20px; }
.chart-box { position: relative; height: 240px; margin-top: 10px; }

/* ===== Mini listas (dashboard) ===== */
.mini-list, .alert-box { margin-top: 8px; }
.mini-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.mini-row:last-child { border-bottom: none; }
.mini-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mini-desc { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-sub { font-size: 12px; }
.alert-box {
  background: color-mix(in srgb, var(--red) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--red) 25%, transparent);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;
}
.alert-box > strong { color: var(--red); font-size: 13.5px; }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cat-dot.lg { width: 14px; height: 14px; }
.empty { padding: 24px 0; text-align: center; }

/* ===== Tabela ===== */
.table-card { padding: 8px 0 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border);
}
td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.td-desc { font-weight: 600; }
.actions .icon-btn { padding: 5px; }
.actions .icon-btn svg { width: 17px; height: 17px; }
.icon-btn.danger:hover { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700;
}
.badge.paid { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.badge.pending { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.badge.overdue { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 0; gap: 10px; flex-wrap: wrap;
}
.pagination .btn { margin-top: 0; }
.check-col { width: 34px; text-align: center; padding-left: 14px; padding-right: 4px; }
.check-col input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
tr.selected { background: color-mix(in srgb, var(--primary) 8%, transparent); }
tr.selected:hover { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.btn.danger-btn { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.btn.danger-btn:hover { background: color-mix(in srgb, var(--red) 25%, transparent); }

/* ===== Contas ===== */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.acc-card { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.acc-top { display: flex; align-items: center; gap: 12px; }
.acc-badge {
  width: 42px; height: 42px; border-radius: 12px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; flex-shrink: 0;
}
.acc-name { font-weight: 700; }
.acc-balance { font-size: 22px; font-weight: 750; }
.acc-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ===== Categorias ===== */
.cat-list { margin-top: 10px; }
.cat-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--border);
}
.cat-row:last-child { border-bottom: none; }
.cat-name { font-weight: 600; flex: 1; }

/* ===== Cartões de crédito ===== */
.cards-strip {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.mini-card-cc { padding: 14px 16px; border-left: 4px solid var(--primary); }
.mini-cc-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.mini-cc-value { font-size: 19px; font-weight: 750; }
.cc-card { padding: 0; overflow: hidden; }
.cc-top { padding: 18px 20px 14px; color: #fff; }
.cc-name { font-weight: 750; font-size: 17px; }
.cc-sub { font-size: 12.5px; opacity: .85; }
.cc-body { padding: 14px 20px 16px; display: flex; flex-direction: column; gap: 8px; }
.cc-row { display: flex; justify-content: space-between; align-items: center; }
.closed-invoice {
  background: color-mix(in srgb, var(--amber) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
  border-radius: 10px; padding: 9px 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
}
.closed-invoice.late {
  background: color-mix(in srgb, var(--red) 10%, transparent);
  border-color: color-mix(in srgb, var(--red) 35%, transparent);
}
.closed-invoice:hover { filter: brightness(1.06); }
.limit-bar {
  height: 8px; border-radius: 6px; background: var(--surface-2);
  overflow: hidden; margin-bottom: 4px;
}
.limit-fill { height: 100%; border-radius: 6px; transition: width .3s; }
.cc-actions { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.cc-actions .btn { margin-top: 0; }
.cc-actions .icon-btn { margin-left: auto; }
.cc-actions .icon-btn + .icon-btn { margin-left: 0; }
tr.inactive { opacity: .55; }

/* ===== Fatura ===== */
.modal.wide { max-width: 560px; }
.invoice-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.month-nav.compact { margin-bottom: 0; }
.month-label.sm { font-size: 14.5px; min-width: 130px; }
.invoice-summary {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 12px 0 4px; padding: 10px 14px;
  background: var(--surface-2); border-radius: 10px;
}
.invoice-items { max-height: 320px; overflow-y: auto; }
.invoice-pay { border-top: 1px solid var(--border); margin-top: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 860px) { .form-row-3 { grid-template-columns: 1fr; } }

/* ===== Orçamentos e metas ===== */
.budget-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.budget-row:last-child { border-bottom: none; }
.budget-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.budget-head { display: flex; align-items: center; gap: 8px; }
.goal-card { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.goal-card.achieved { outline: 2px solid color-mix(in srgb, var(--green) 45%, transparent); }
.goal-head { display: flex; align-items: center; gap: 12px; }
.goal-values { font-size: 19px; }
.goal-meta { display: flex; justify-content: space-between; }

/* ===== Relatórios ===== */
.report-filters { grid-template-columns: 1fr auto auto auto; align-items: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  border: none; background: var(--surface-2); color: var(--muted);
  padding: 8px 14px; border-radius: 20px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.toolbar a.btn { text-decoration: none; }

/* ===== Expansão (relatório de cartões) ===== */
.expand-block { border-bottom: 1px solid var(--border); }
.expand-block:last-child { border-bottom: none; }
.expand-block .budget-row { border-bottom: none; }
.budget-row.clickable { cursor: pointer; border-radius: 10px; padding-left: 6px; padding-right: 6px; }
.budget-row.clickable:hover { background: var(--surface-2); }
.expand-chev svg { width: 17px; height: 17px; transition: transform .18s; color: var(--muted); }
.expand-chev.open svg { transform: rotate(90deg); }
.expand-body {
  margin: 0 0 10px 26px; padding: 2px 14px;
  border-left: 2px solid var(--border);
}
.expand-body.nested { margin: 0 0 6px 18px; }
.reimburse-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 10px; margin: 6px 0;
  background: var(--surface-2); border-radius: 10px;
}
.reimburse-btn { font-size: 15px; padding: 4px 6px; }
.mini-row.reimbursed .mini-desc, .mini-row.reimbursed .neg { opacity: .55; }
.mini-row.reimbursed .mini-desc { text-decoration: line-through; }
.clickable-row { cursor: pointer; border-radius: 8px; }
.clickable-row:hover { background: var(--surface-2); }
.clickable-row .expand-chev { margin-left: 4px; }

/* ===== Anexos ===== */
.att-box {
  margin-top: 14px; padding: 12px 14px;
  background: var(--surface-2); border-radius: 10px;
}
.att-box label { margin-top: 0; }
.att-box input[type="file"] { padding: 8px; font-size: 13px; margin-top: 8px; }
.att-link { color: var(--primary); text-decoration: none; }
@media (max-width: 860px) { .report-filters { grid-template-columns: 1fr 1fr; } }

/* ===== Modais ===== */
.modal-bg {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 25, .55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  padding: 26px 26px 22px;
}
.modal h3 { font-size: 17px; margin-bottom: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions .btn { margin-top: 0; }
.color-input { height: 44px; padding: 4px; cursor: pointer; }
textarea { resize: vertical; font-family: inherit; }

/* ===== Seletor de meses (recorrências) ===== */
.month-picker {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 4px;
}
.people-picker {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px;
}
.people-picker .month-chip { padding: 7px 14px; }
.month-chip {
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); border-radius: 8px; padding: 7px 0;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.month-chip.on {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: var(--primary); color: var(--primary);
}

/* ===== Importação ===== */
.import-list {
  max-height: 46vh; overflow-y: auto; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px;
}
.import-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.import-row:last-child { border-bottom: none; }
.import-row.off { opacity: .45; }
.import-row input[type="checkbox"] { width: 17px; height: 17px; flex-shrink: 0; }
.import-cat { width: 150px; padding: 6px 8px; font-size: 12.5px; flex-shrink: 0; }
.import-row .badge { margin-left: 6px; }

/* ===== Pessoas ===== */
.person-tag {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  border: 1px solid; border-radius: 12px; padding: 1px 8px;
  margin-left: 6px; vertical-align: 1px;
}
.invoice-people {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 10px 0 4px;
}

/* ===== Telegram ===== */
.tg-code {
  text-align: center; padding: 14px; margin: 12px 0;
  background: var(--surface-2); border-radius: 12px;
}
.tg-code strong { font-size: 30px; letter-spacing: 8px; color: var(--primary); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 200; background: var(--text); color: var(--bg);
  padding: 11px 22px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ===== Spinner ===== */
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Responsivo ===== */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: repeat(3, 1fr); }
  .filters input:first-child { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 40; left: -240px; transition: left .22s;
    box-shadow: var(--shadow);
  }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat-value { font-size: 19px; }
}
