/* ====================================================================
   CassaFlow — stile dashboard. Sobrio, pulito, self-contained.
   ==================================================================== */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1a1d24;
  --muted: #6b7280;
  --line: #e6e8ec;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }

.logo { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.logo span { color: var(--accent); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #e8edff, var(--bg));
}
.login-card {
  background: var(--card); padding: 40px; border-radius: var(--radius);
  box-shadow: var(--shadow); width: 340px; text-align: center;
}
.login-card .logo { font-size: 28px; margin-bottom: 6px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 15px; margin-bottom: 12px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: #1d4ed8; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- topbar ---------- */
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.badge {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
  background: #eef2ff; color: var(--accent);
}
.badge.live { background: #dcfce7; color: var(--green); }
.btn-secondary {
  padding: 8px 14px; border: 1px solid var(--line); background: var(--card);
  border-radius: 9px; font-size: 14px; cursor: pointer; font-weight: 500;
}
.btn-secondary:hover { background: #f8fafc; }
.btn-ghost { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 14px; }

/* ---------- layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 28px; }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.kpi .label { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.kpi .value.pos { color: var(--green); }
.kpi .value.neg { color: var(--red); }
.kpi.highlight { background: linear-gradient(135deg, #2563eb, #1d4ed8); border: none; }
.kpi.highlight .label, .kpi.highlight .value { color: #fff; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 24px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-head h3 { font-size: 15px; font-weight: 600; }

/* ---------- grafico cash flow (barre SVG) ---------- */
.bars { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar-stack { flex: 1; display: flex; align-items: flex-end; gap: 4px; width: 100%; justify-content: center; }
.bar { width: 16px; border-radius: 4px 4px 0 0; transition: height .3s; }
.bar.in { background: var(--green); }
.bar.out { background: var(--red); opacity: .85; }
.bar-label { font-size: 11px; color: var(--muted); margin-top: 8px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* ---------- categorie ---------- */
.cat-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cat-name { width: 150px; font-size: 13px; }
.cat-track { flex: 1; height: 8px; background: #f1f3f5; border-radius: 6px; overflow: hidden; }
.cat-fill { height: 100%; border-radius: 6px; }
.cat-amt { width: 90px; text-align: right; font-size: 13px; font-weight: 600; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  padding: 10px 16px; border: none; background: none; cursor: pointer;
  font-size: 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.pill {
  background: var(--red); color: #fff; font-size: 11px; border-radius: 20px;
  padding: 1px 7px; margin-left: 4px;
}

/* ---------- liste ---------- */
.row {
  display: flex; align-items: center; gap: 14px; padding: 12px 8px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.row-main { flex: 1; min-width: 0; }
.row-desc { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-amt { font-weight: 600; font-size: 15px; white-space: nowrap; }
.row-amt.pos { color: var(--green); }
.row-amt.neg { color: var(--ink); }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 6px; background: #f1f3f5;
  color: var(--muted); font-weight: 500;
}
.tag.paid { background: #dcfce7; color: var(--green); }
.tag.unpaid { background: #fef3c7; color: var(--amber); }
.check { color: var(--green); font-size: 14px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 6px 14px; border: 1px solid var(--line); background: var(--card);
  border-radius: 20px; font-size: 13px; cursor: pointer; color: var(--muted);
}
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.hint { font-size: 13px; color: var(--muted); margin-bottom: 16px; }

/* ---------- riconciliazione ---------- */
.match {
  display: flex; align-items: center; gap: 16px; padding: 14px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: #fbfcfd;
}
.match-side { flex: 1; }
.match-side .t { font-size: 14px; font-weight: 600; }
.match-side .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.match-arrow { color: var(--accent); font-size: 20px; }
.match-score { font-size: 12px; font-weight: 600; color: var(--accent); background: #eef2ff; padding: 3px 8px; border-radius: 6px; }
.btn-confirm {
  padding: 8px 16px; background: var(--green); color: #fff; border: none;
  border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-confirm:hover { background: #15803d; }
.empty { text-align: center; color: var(--muted); padding: 40px; font-size: 14px; }

/* ==================== Vista Cashflow stile Sibill ==================== */
.summary-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.view-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

/* barra periodo (mese/anno + selettore anno) */
.cf-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #f1f3f5; border-radius: 9px; padding: 3px; }
.seg-btn {
  border: none; background: none; padding: 7px 14px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.year-select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; font-weight: 600; background: var(--card); cursor: pointer; color: var(--ink);
}

/* card grandi Entrate / Uscite / Netto */
.cf-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 760px) { .cf-cards { grid-template-columns: 1fr; } }
.cf-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px; background: var(--card);
}
.cf-label { font-size: 12px; font-weight: 700; letter-spacing: .5px; margin-bottom: 8px; }
.cf-val { font-size: 26px; font-weight: 700; letter-spacing: -.6px; }
.cf-card.in .cf-label { color: var(--green); }
.cf-card.out .cf-label { color: var(--red); }
.cf-card.net .cf-label { color: var(--accent); }
.cf-card.in .cf-val { color: #0f172a; }
.cf-card.out .cf-val { color: #0f172a; }
.cf-card.net .cf-val { color: var(--accent); }

/* grafico SVG */
.cf-chart { margin-bottom: 8px; }
.cf-svg { width: 100%; height: auto; display: block; }
.cf-svg .grid { stroke: #eef0f3; stroke-width: 1; }
.cf-svg .axis-y { fill: var(--muted); font-size: 12px; text-anchor: end; }
.cf-svg .axis-x { fill: var(--muted); font-size: 12px; text-anchor: middle; }
.cf-svg .bar-in { fill: #2f8f83; }
.cf-svg .bar-out { fill: #ec6a5e; }
.cf-svg .saldo-line { fill: none; stroke: #334155; stroke-width: 2; }
.cf-svg .saldo-dot { fill: #334155; }
.cf-legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.cf-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.cf-legend .sq-in { background: #2f8f83; }
.cf-legend .sq-out { background: #ec6a5e; }
.cf-legend .sq-line { background: #334155; border-radius: 2px; height: 3px; width: 14px; }

/* tabella mensile */
.cf-table-wrap { overflow-x: auto; margin-top: 18px; border-top: 1px solid var(--line); padding-top: 4px; }
.cf-table { border-collapse: collapse; width: 100%; min-width: 720px; font-size: 13px; }
.cf-table th, .cf-table td { padding: 10px 12px; text-align: right; white-space: nowrap; }
.cf-table thead th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
.cf-table tbody tr { border-bottom: 1px solid var(--line); }
.cf-table tbody tr:last-child { border-bottom: none; }
.cf-table .rowhead { text-align: left; font-weight: 600; color: var(--ink); position: sticky; left: 0; background: var(--card); }
.cf-table .totcol { font-weight: 700; border-left: 1px solid var(--line); background: #fafbfc; }
.cf-table td.pos { color: var(--green); }
.cf-table td.neg { color: var(--red); }
.cf-table .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }
.cf-table .dot.in { background: #2f8f83; }
.cf-table .dot.out { background: #ec6a5e; }
.cf-table td.muted { color: #cbd0d6; }
.cf-table tr.group { cursor: pointer; }
.cf-table tr.group:hover { background: #f8fafc; }
.cf-table tr.group .rowhead { font-weight: 700; }
.cf-table .caret { display: inline-block; width: 14px; color: var(--muted); font-size: 11px; }
.cf-table tr.sub td { font-weight: 400; color: #475569; }
.cf-table tr.sub .rowhead.sub { padding-left: 26px; font-weight: 500; }
.cf-table tr.sub { background: #fcfcfd; }

/* ==================== Vista Conti ==================== */
.conti-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; }
.conti-total-label { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.conti-total { font-size: 30px; font-weight: 700; letter-spacing: -.6px; }
.btn-dark {
  padding: 10px 16px; background: var(--ink); color: #fff; border: none;
  border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-dark:hover { background: #000; }
.btn-dark.inline { display: inline-block; text-decoration: none; margin-top: 10px; }
.account-card { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 12px; }
.account-top { display: flex; justify-content: space-between; align-items: center; }
.account-name { font-size: 15px; font-weight: 600; }
.account-bal { font-size: 17px; font-weight: 700; }
.account-status { font-size: 10.5px; font-weight: 700; letter-spacing: .5px; padding: 2px 7px; border-radius: 6px; margin-left: 8px; vertical-align: middle; }
.account-status.connected { background: #dcfce7; color: var(--green); }
.account-status.manual { background: #eef2ff; color: var(--accent); }
.account-sub { font-size: 12px; color: var(--muted); margin-top: 8px; }
.account-sub code { background: #f1f3f5; padding: 2px 6px; border-radius: 5px; font-size: 11.5px; }

/* ==================== Movimenti per giorno ==================== */
.day-group { margin-bottom: 8px; }
.day-head { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: capitalize; padding: 12px 8px 6px; border-bottom: 1px solid var(--line); }

/* ==================== Modale ==================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-card { background: var(--card); border-radius: 16px; width: 480px; max-width: 100%; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h3 { font-size: 17px; font-weight: 600; }
.modal-x { border: none; background: none; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
.opt { display: flex; align-items: center; gap: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; cursor: pointer; }
.opt:hover { border-color: var(--accent); background: #f8faff; }
.opt-ico { font-size: 22px; width: 30px; text-align: center; }
.opt-t { font-size: 15px; font-weight: 600; }
.opt-s { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.opt-arrow { margin-left: auto; color: var(--muted); font-size: 18px; }
.warn { color: var(--amber); font-weight: 600; }
.bank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bank-btn { padding: 16px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; }
.bank-btn:hover { border-color: var(--accent); background: #f8faff; }
.connect-result { margin-top: 16px; }
.info-box { background: #fef9ee; border: 1px solid #fde68a; color: #92400e; padding: 12px 14px; border-radius: 10px; font-size: 13px; line-height: 1.5; }
.form { display: flex; flex-direction: column; }
.form label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
.form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; outline: none; }
.form input:focus { border-color: var(--accent); }
.form .btn-dark { margin-top: 20px; }

.linkbar {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: 10px; font-size: 14px; font-weight: 600;
  z-index: 200; box-shadow: 0 8px 30px rgba(0,0,0,.18);
}
.linkbar.ok { background: #dcfce7; color: #15803d; }
.linkbar.err { background: #fee2e2; color: #b91c1c; }

/* selettore categoria (tag manuale) nei movimenti */
.cat-select {
  font-size: 11px; font-weight: 500; color: var(--muted);
  background: #f1f3f5; border: 1px solid transparent; border-radius: 6px;
  padding: 2px 4px 2px 16px; cursor: pointer; max-width: 200px;
  appearance: none; -webkit-appearance: none;
  background-image: radial-gradient(circle at 7px center, var(--c, #94a3b8) 3px, transparent 3.5px);
  background-repeat: no-repeat;
}
.cat-select:hover { border-color: var(--line); background-color: #e9ecef; }
.cat-select:focus { outline: none; border-color: var(--accent); }

/* ==================== Forecast / ricorrenze ==================== */
/* colonne previste: tono smorzato + tratteggio verticale */
.cf-table th.fc, .cf-table td.fc { background: repeating-linear-gradient(-45deg, #f6f8fb, #f6f8fb 6px, #eef1f6 6px, #eef1f6 12px); color: #64748b; }
.cf-table td.fc.pos { color: #4f9e7a; }
.cf-table td.fc.neg { color: #c47a72; }
.cf-table th.fc { position: relative; }
.fc-tag { display: block; font-size: 9px; font-weight: 700; letter-spacing: .5px; color: var(--accent); text-transform: uppercase; margin-top: 1px; }
.fc-legend-note { font-size: 12px; color: var(--muted); margin: 4px 0 12px; display: flex; align-items: center; gap: 8px; }
.fc-swatch { display: inline-block; width: 26px; height: 13px; border-radius: 3px; background: repeating-linear-gradient(-45deg, #f6f8fb, #f6f8fb 4px, #e2e7ee 4px, #e2e7ee 8px); border: 1px solid var(--line); flex: none; }

.btn-dark.sm { padding: 7px 12px; font-size: 12.5px; }

/* lista ricorrenze nella modale */
.rule-list { max-height: 240px; overflow-y: auto; margin-bottom: 4px; }
.rule-row { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.rule-row:last-child { border-bottom: none; }
.rule-main { flex: 1; min-width: 0; }
.rule-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rule-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.rule-amt { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.rule-amt.pos { color: var(--green); }
.rule-amt.neg { color: var(--red); }
.rule-del { border: none; background: none; color: #c0c5cd; font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
.rule-del:hover { color: var(--red); }
.rule-hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }

/* form ricorrenza a griglia */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .fg { display: flex; flex-direction: column; }
.form-grid .fg.full { grid-column: 1 / -1; }
.form-grid label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 5px; }
.form-grid input, .form-grid select { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; outline: none; background: var(--card); }
.form-grid input:focus, .form-grid select:focus { border-color: var(--accent); }
.form-grid .btn-dark { margin-top: 16px; width: 100%; }
.modal-card { width: 520px; }
