/* ============================================================
   Planilha – CSS principal
   Mobile-first, sem framework, modo escuro automático
   ============================================================ */

:root {
  --bg:          #f5f7fa;
  --surface:     #ffffff;
  --surface2:    #f0f2f5;
  --border:      #e2e6ea;
  --text:        #1a1d23;
  --text-muted:  #6b7280;
  --primary:     #4f6ef7;
  --primary-h:   #3a57e8;
  --danger:      #ef4444;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --me-color:    #4f6ef7;
  --spouse-color:#a855f7;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         #0f1117;
    --surface:    #1a1d27;
    --surface2:   #252832;
    --border:     #2d3141;
    --text:       #e8ecf0;
    --text-muted: #8892a4;
    --shadow:     0 1px 4px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
  }
}
:root[data-theme="dark"] {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #252832;
  --border:     #2d3141;
  --text:       #e8ecf0;
  --text-muted: #8892a4;
  --shadow:     0 1px 4px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- Layout ---- */
.app-wrap    { max-width: 680px; margin: 0 auto; padding: 0 16px 120px; }
.page-header { padding: 20px 0 8px; display: flex; align-items: center; gap: 12px; }
.page-header h1 { font-size: 1.25rem; font-weight: 700; flex: 1; }

/* ---- Nav bottom ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.bottom-nav a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  padding: 10px 0 12px;
  font-size: .68rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color .15s;
}
.bottom-nav a.active, .bottom-nav a:hover { color: var(--primary); }
.bottom-nav a svg { width: 22px; height: 22px; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 12px;
}
.card-sm { padding: 14px 16px; }

.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.person-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.person-card .label { font-size: .78rem; color: var(--text-muted); margin-bottom: 4px; }
.person-card .value { font-size: 1.5rem; font-weight: 700; }
.person-card.me .value    { color: var(--me-color); }
.person-card.spouse .value { color: var(--spouse-color); }
.person-card .badge {
  display: inline-block; margin-top: 6px;
  font-size: .68rem; padding: 2px 8px;
  border-radius: 20px; font-weight: 600;
}
.person-card.me .badge    { background: rgba(79,110,247,.12); color: var(--me-color); }
.person-card.spouse .badge { background: rgba(168,85,247,.12); color: var(--spouse-color); }

/* ---- Limit bar ---- */
.limit-bar-wrap { margin-bottom: 4px; }
.limit-bar-labels { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-muted); margin-bottom: 6px; }
.limit-bar {
  height: 10px; border-radius: 10px;
  background: var(--surface2);
  overflow: hidden;
}
.limit-bar-fill {
  height: 100%; border-radius: 10px;
  background: linear-gradient(90deg, var(--primary), var(--spouse-color));
  transition: width .4s ease;
}
.limit-bar-fill.danger { background: linear-gradient(90deg, var(--warning), var(--danger)); }

/* ---- Month nav ---- */
.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.month-nav .month-label { font-size: 1rem; font-weight: 600; }
.month-nav a {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
  transition: background .15s;
}
.month-nav a:hover { background: var(--surface2); }

/* ---- Transaction list ---- */
.tx-list { list-style: none; }
.tx-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 5px;
}
.tx-dot.me     { background: var(--me-color); }
.tx-dot.spouse { background: var(--spouse-color); }
.tx-dot.split  { background: linear-gradient(135deg, var(--me-color) 50%, var(--spouse-color) 50%); }
.tx-info { flex: 1; min-width: 0; }
.tx-desc { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.tx-meta-split { display: block; font-size: .72rem; margin-top: 1px; }
.tx-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.tx-amount {
  font-size: .95rem; font-weight: 600; white-space: nowrap;
  color: var(--text);
}
.tx-amount.negative { color: var(--success); }
.tx-actions { display: flex; gap: 2px; align-items: center; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  min-width: 32px; min-height: 32px;
  transition: color .15s, background .15s;
}
.btn-icon:hover { color: var(--text); background: var(--surface2); }
.btn-icon.danger:hover { color: var(--danger); }

/* ---- Recurring bills in list ---- */
.tx-item.recurring { opacity: .85; }
.recurring-badge {
  font-size: .68rem; padding: 1px 6px; border-radius: 20px;
  background: var(--surface2); color: var(--text-muted); margin-left: 6px;
}

/* ---- Section header ---- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 0 10px;
}
.section-header h2 { font-size: .9rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600; cursor: pointer;
  border: none; text-decoration: none; transition: background .15s, opacity .15s;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-success   { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---- FAB ---- */
.fab {
  position: fixed; bottom: 76px; right: 20px;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(79,110,247,.4);
  text-decoration: none; font-size: 1.5rem;
  transition: transform .15s, background .15s;
  z-index: 90;
}
.fab:hover { transform: scale(1.08); background: var(--primary-h); }

/* ---- Forms ---- */
.form-group  { margin-bottom: 16px; }
.form-label  { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 11px 14px;
  background: var(--surface2); color: var(--text);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; font-family: var(--font);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.form-control.error { border-color: var(--danger); }
.form-hint   { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }
.form-error  { font-size: .78rem; color: var(--danger); margin-top: 4px; }

.radio-group { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-btn input { display: none; }
.radio-btn label {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2); cursor: pointer;
  font-size: .88rem; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.radio-btn input:checked + label { border-color: var(--primary); background: rgba(79,110,247,.1); color: var(--primary); }

/* ---- Alert ---- */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: .88rem;
}
.alert-success { background: rgba(34,197,94,.12); color: #15803d; border: 1px solid rgba(34,197,94,.2); }
.alert-error   { background: rgba(239,68,68,.1);  color: #dc2626; border: 1px solid rgba(239,68,68,.2); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .alert-success { color: #4ade80; }
  :root:not([data-theme="light"]) .alert-error   { color: #f87171; }
}

/* ---- Invoice paid banner ---- */
.paid-banner {
  background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.2);
  border-radius: var(--radius-sm); padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  font-size: .88rem; color: var(--success); margin-bottom: 12px;
}

/* ---- Totals ---- */
.total-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.total-row .label { font-size: .9rem; color: var(--text-muted); }
.total-row .value { font-size: .9rem; font-weight: 600; }
.total-row.grand  { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 12px; }
.total-row.grand .value { font-size: 1.1rem; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; padding: 10px 8px; color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ---- Badge ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .72rem; font-weight: 600;
}
.badge-me     { background: rgba(79,110,247,.12); color: var(--me-color); }
.badge-spouse { background: rgba(168,85,247,.12); color: var(--spouse-color); }
.badge-split  { background: rgba(245,158,11,.12); color: var(--warning); }
.badge-active   { background: rgba(34,197,94,.12); color: var(--success); }
.badge-inactive { background: var(--surface2); color: var(--text-muted); }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.login-card { width: 100%; max-width: 380px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.login-logo p  { font-size: .88rem; color: var(--text-muted); margin-top: 4px; }

/* ---- Empty state ---- */
.empty { text-align: center; padding: 32px 16px; color: var(--text-muted); }
.empty svg { width: 48px; height: 48px; opacity: .3; margin-bottom: 12px; }
.empty p { font-size: .9rem; }

/* ---- Utilities ---- */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: .82rem; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.w-full { width: 100%; }

@media (min-width: 480px) {
  .cards-row { gap: 16px; }
  .person-card .value { font-size: 1.75rem; }
}

/* ---- Mobile tweaks ---- */
@media (max-width: 479px) {
  /* Prevent iOS from auto-zooming inputs (requires font-size >= 16px) */
  .form-control, select, textarea { font-size: 16px; }

  /* Tighten person-card values on very small screens */
  .person-card .value { font-size: 1.3rem; }

  /* Limit bar labels: stack on small screens */
  .limit-bar-labels { flex-direction: column; gap: 2px; }

  /* Page header title: prevent overflow */
  .page-header h1 { font-size: 1.1rem; }

  /* Transaction list: stack amount + actions vertically on mobile */
  .tx-right { flex-direction: column; align-items: flex-end; gap: 0; }
  .tx-amount { font-size: .85rem; }
  .btn-icon { padding: 4px; min-width: 26px; min-height: 26px; }
  .btn-icon svg { width: 13px; height: 13px; }

  /* Evolution table: sticky month column */
  .table-wrap table { font-size: .82rem; }
  .table-wrap table th:first-child,
  .table-wrap table td:first-child {
    position: sticky; left: 0;
    background: var(--surface);
    z-index: 1;
    box-shadow: 2px 0 4px rgba(0,0,0,.06);
  }
}
