:root {
  --bg: #f5f7f8;
  --ink: #182026;
  --muted: #687782;
  --line: #d9e0e4;
  --panel: #ffffff;
  --panel-2: #eef3f5;
  --green: #177245;
  --red: #b42318;
  --amber: #a75d00;
  --blue: #1b5f8f;
  --violet: #6d4aa5;
  --shadow: 0 12px 28px rgba(31, 45, 61, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px 1fr;
}
.hidden { display: none !important; }

/* ── Auth ── */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at top left, rgba(24, 95, 143, 0.16), transparent 30%),
    radial-gradient(circle at bottom right, rgba(23, 114, 69, 0.18), transparent 28%),
    linear-gradient(135deg, #f3f7f6, #e8eef2);
}
.auth-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(217,224,228,.9);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(20, 38, 51, .12);
  padding: 26px;
}
.auth-brand { color: var(--ink); border-bottom: 0; padding-bottom: 0; }
.auth-copy { margin: 18px 0; }
.auth-copy h1 { font-size: 28px; margin-bottom: 6px; }
.auth-form { display: grid; gap: 12px; }
.login-error { min-height: 18px; color: var(--red); margin: 0; font-size: 13px; }

/* ── Session chip ── */
.topbar-actions { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.session-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff;
  color: var(--muted); font-size: 12px;
}

/* ── Status pills ── */
.status-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 76px; min-height: 28px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: #fff;
}
.status-pill.present { color: var(--green); border-color: #b9dfca; background: #eefaf3; }
.status-pill.absent  { color: var(--red);   border-color: #efc5bf; background: #fff1ef; }
.status-pill.halfday { color: var(--amber); border-color: #f1dbb4; background: #fff7ea; }
.status-pill.pending { color: var(--muted); }

.section-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.section-tabs button.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.doc-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #fff; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.subtext { color: var(--muted); font-size: 12px; margin-top: 4px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.inline-form > * { flex: 1 1 160px; }
.photo-thumb { width: 68px; height: 68px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

/* ── Buttons & Inputs ── */
button, input, select, textarea { font: inherit; }
button, .import-label {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 6px; min-height: 36px; padding: 8px 12px; cursor: pointer;
}
button:hover, .import-label:hover { border-color: #aab7c0; }
button.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
button.danger  { color: var(--red); border-color: #efc5bf; }
button.ghost   { background: transparent; }

/* ── Sidebar ── */
.sidebar {
  height: 100vh; position: sticky; top: 0; padding: 18px;
  background: #172129; color: #f7fbfd;
  display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,.12); }
.mark { width: 46px; height: 46px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; background: #e8f4f0; color: #123b2b; }
.brand small { display: block; color: #b8c6cd; margin-top: 2px; }
nav { display: grid; gap: 6px; }
nav a {
  border: 0; color: #d7e2e7; background: transparent;
  display: flex; justify-content: space-between; align-items: center;
  text-align: left; padding: 8px 12px; border-radius: 6px;
  text-decoration: none; font-size: 14px;
}
nav a.active, nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.storage-card {
  margin-top: auto; border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px; padding: 12px; display: grid; gap: 8px; color: #d7e2e7;
}
.storage-card button { width: 100%; text-align: center; }

/* ── Main / Topbar ── */
main { min-width: 0; }
.topbar {
  min-height: 92px; padding: 20px 28px;
  background: rgba(245, 247, 248, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2;
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
}
h1 { margin: 0; font-size: 25px; }
h2 { margin: 0 0 12px; font-size: 19px; }
h3 { margin: 0 0 8px; font-size: 15px; }
p  { margin: 4px 0 0; color: var(--muted); }
.month-picker { display: grid; gap: 4px; min-width: 190px; }
.month-picker label, .field label { color: var(--muted); font-size: 12px; display: block; margin-bottom: 4px; }
.field { display: grid; gap: 4px; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff;
  border-radius: 6px; min-height: 36px; padding: 8px 10px;
}
input[type="checkbox"] { width: auto; min-height: auto; padding: 0; }
textarea { min-height: 86px; resize: vertical; }

/* ── View / Grid / Panel ── */
#view { padding: 24px 28px 42px; display: grid; gap: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kpi { display: grid; gap: 6px; min-height: 112px; }
.kpi span  { color: var(--muted); }
.kpi strong { font-size: clamp(20px, 2.4vw, 32px); }
.kpi small  { color: var(--muted); }
.positive { color: var(--green); }
.negative { color: var(--red); }
.warning  { color: var(--amber); }
.blue     { color: var(--blue); }

/* ── Tables ── */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--panel-2); color: #34434d; font-size: 12px; position: sticky; top: 0; z-index: 1; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
.tag { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 2px 9px; background: var(--panel-2); color: #33434c; font-size: 12px; white-space: nowrap; }
.tag.ok   { color: var(--green); background: #e7f5ee; }
.tag.bad  { color: var(--red);   background: #fff0ee; }
.tag.warn { color: var(--amber); background: #fff5e6; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field.full { grid-column: 1 / -1; }
.empty { border: 1px dashed #b9c5cc; background: #fff; border-radius: 8px; padding: 18px; color: var(--muted); text-align: center; }

/* ── Charts ── */
.chart { height: 240px; display: flex; align-items: end; gap: 10px; padding: 14px 6px 4px; border-bottom: 1px solid var(--line); }
.bar-group { flex: 1; min-width: 42px; display: grid; gap: 6px; align-items: end; grid-template-columns: repeat(3, 1fr); height: 100%; }
.bar { border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.rev    { background: var(--green); }
.bar.exp    { background: var(--amber); }
.bar.profit { background: var(--blue); }
.chart-labels { display: flex; justify-content: space-around; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 8px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

/* ── Cash Flow ── */
.cf-bar-wrap { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.cf-label    { width: 72px; color: var(--muted); font-size: 12px; flex-shrink: 0; text-align: right; }
.cf-track    { flex: 1; background: var(--panel-2); border-radius: 6px; height: 34px; overflow: hidden; }
.cf-bar      { height: 34px; border-radius: 6px; display: flex; align-items: center; padding: 0 12px; transition: width .4s ease; min-width: 4px; }
.cf-bar.cf-in  { background: var(--green); color: #fff; }
.cf-bar.cf-out { background: var(--amber); color: #fff; }
.cf-bar span   { font-size: 12px; white-space: nowrap; font-weight: 600; }

/* ── Payment summary ── */
.payment-summary { display: flex; gap: 24px; padding: 12px 16px; background: var(--panel-2); border-radius: 6px; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.payment-summary strong { font-size: 15px; }

/* ── Mini bar ── */
.mini-bar-wrap { display: flex; align-items: center; gap: 8px; }
.mini-bar      { height: 8px; background: var(--amber); border-radius: 4px; min-width: 2px; max-width: 120px; }
.mini-bar-wrap span { font-size: 12px; color: var(--muted); }

/* ── Attention items ── */
.attention-item { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.attention-item .ai-title { font-weight: 600; font-size: 13px; }
.attention-item .ai-desc  { font-size: 12px; color: var(--muted); }
.attention-item.ok   { border-color: #b9dfca; background: #eefaf3; }
.attention-item.warn { border-color: #f1dbb4; background: #fff7ea; }
.attention-item.bad  { border-color: #efc5bf; background: #fff1ef; }

/* ── Dialog / Modal ── */
dialog { width: min(760px, calc(100vw - 28px)); border: 0; border-radius: 10px; box-shadow: 0 26px 70px rgba(0,0,0,.26); padding: 0; }
dialog::backdrop { background: rgba(15, 23, 30, .44); }
dialog header, dialog footer { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
dialog footer { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
#modalBody { padding: 16px; max-height: 70vh; overflow: auto; }
dialog header h2 { margin: 0; font-size: 16px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--muted); padding: 4px 8px; }

/* ── Flash messages ── */
.flash-ok  { background: #eefaf3; border: 1px solid #b9dfca; color: #1a5c38; padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.flash-err { background: #fff1ef; border: 1px solid #efc5bf; color: #8b1a0f; padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

/* ── Inline form panels ── */
.form-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-top: 16px; }
.form-panel h3 { margin: 0 0 16px; font-size: 14px; font-weight: 600; color: var(--text); }
.hidden { display: none !important; }
.input-small { width: 110px; padding: 4px 8px; }
.photo-thumb { max-width: 120px; max-height: 80px; border-radius: 4px; border: 1px solid var(--line); }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.inline-form .field { margin-bottom: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.doc-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.doc-card h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.doc-card p  { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

/* ── Responsive ── */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { position: relative; flex-direction: column; align-items: stretch; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .form-grid, .two-col { grid-template-columns: 1fr; }
}
