:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --income: #22c55e;
  --expense: #ef4444;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.loading { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* ---------- Auth ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.muted { color: var(--text-muted); font-size: 0.9rem; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; color: var(--text-muted); }
.field input, .field select {
  background: #0b1220;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px;
  border-radius: 10px;
  font-size: 1rem;
}
.field.checkbox { flex-direction: row; align-items: center; }
.field.checkbox label { display: flex; align-items: center; gap: 8px; color: var(--text); }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: #334155; color: var(--text); }
.error { color: var(--expense); min-height: 1.2em; font-size: 0.9rem; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.topnav { display: none; gap: 18px; }
.topnav a { color: var(--text-muted); text-decoration: none; font-size: 0.95rem; padding: 6px 2px; }
.topnav a.active { color: var(--text); border-bottom: 2px solid var(--primary); }
.btn-logout { background: transparent; border: 1px solid var(--border); color: var(--text-muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; }

main#screen { flex: 1; padding: 16px; padding-bottom: calc(84px + var(--safe-bottom)); max-width: 900px; width: 100%; margin: 0 auto; }

.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 8px 4px calc(8px + var(--safe-bottom));
  z-index: 20;
}
.bottomnav a { color: var(--text-muted); text-decoration: none; font-size: 0.7rem; display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; }
.bottomnav a span { font-size: 1.3rem; }
.bottomnav a.active { color: var(--primary); }

@media (min-width: 820px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  main#screen { padding-bottom: 32px; }
}

/* ---------- Dashboard ---------- */
.dash-header { margin-bottom: 14px; }
.dash-header input[type=month] {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 10px; border-radius: 10px; font-size: 1rem;
}

.banner {
  background: #78350f; border: 1px solid #b45309; color: #fde68a;
  padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; cursor: pointer; font-size: 0.9rem;
}
.hidden { display: none !important; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.cards.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 600px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .cards.two { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; min-width: 0;
}
.card-label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px; }
.card-value { font-size: 1.35rem; font-weight: 700; }
.card.income .card-value { color: var(--income); }
.card.expense .card-value { color: var(--expense); }
.mini-row { display: flex; justify-content: space-between; font-size: 0.88rem; padding: 4px 0; }
.mini-row.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; font-weight: 700; }

.panel {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.panel h3 { margin-top: 0; font-size: 1rem; }

/* ---------- Registar ---------- */
.quick-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0; }
.quick-btn {
  border: none; border-radius: var(--radius); padding: 26px 12px; font-size: 1rem; font-weight: 700;
  cursor: pointer; color: white; line-height: 1.6;
}
.quick-btn.expense { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.quick-btn.income { background: linear-gradient(135deg, #22c55e, #15803d); }

.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-actions .btn-secondary, .form-actions .btn-primary { width: auto; flex: 1; }

/* ---------- Transações ---------- */
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input, .filters select {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text);
  padding: 10px; border-radius: 10px;
}

.tx-item {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px;
}
.tx-item.review { border-color: #b45309; }
.tx-main { flex: 1; min-width: 0; }
.tx-desc { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.tx-amount { font-weight: 700; white-space: nowrap; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }
.tx-cat-select { background: #0b1220; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px; font-size: 0.8rem; max-width: 140px; }
.tag { display: inline-block; font-size: 0.68rem; padding: 2px 6px; border-radius: 6px; margin-right: 4px; background: #334155; color: var(--text-muted); }
.tag.review { background: #78350f; color: #fde68a; }
.tx-del { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }

/* ---------- Importar ---------- */
.preview-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.78rem; display: block; overflow-x: auto; white-space: nowrap; }
.preview-table th, .preview-table td { border: 1px solid var(--border); padding: 6px 8px; }
.preview-table th { background: var(--bg-elevated); }

#import-file {
  display: block; width: 100%; padding: 30px 14px; border: 2px dashed var(--border); border-radius: var(--radius);
  color: var(--text-muted); background: var(--bg-elevated); text-align: center;
}

code { background: #0b1220; padding: 6px 10px; border-radius: 8px; display: inline-block; font-size: 0.82rem; word-break: break-all; }

/* ---------- Definições ---------- */
.inline-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; background: #0b1220; border: 1px solid var(--border); color: var(--text); padding: 10px; border-radius: 8px; }
.inline-form button { flex: none; width: auto; }

.list-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.list-row:last-child { border-bottom: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.btn-connect { background: #2563eb; color: white; border: none; padding: 10px 16px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.status-ok { color: var(--income); }
.status-off { color: var(--text-muted); }
