:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e4e1d9;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --bad: #b03a2e;
  --bad-soft: #fbeae8;
  --ok: #2f8f4e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(31, 41, 51, .05), 0 2px 8px rgba(31, 41, 51, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.pre { white-space: pre-line; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.brand:hover { text-decoration: none; }
.brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 700; flex: none; }
.brand-mark.big { width: 52px; height: 52px; font-size: 24px; border-radius: 14px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 7px; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; font-size: 14px; }
.nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav a.on { color: var(--accent); background: var(--accent-soft); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-cta { order: 0; }
.logout { margin-left: auto; }
.linklike { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; }
.linklike:hover { color: var(--ink); }

.main { max-width: 1120px; margin: 0 auto; padding: 24px; }
.main.bare { padding: 0; max-width: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.back { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.empty { text-align: center; padding: 32px 16px; }
.empty p { margin: 0 0 8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid2.top { align-items: start; gap: 16px; }
.grid2.top > .card { margin-bottom: 0; }
.grid2.top + * { margin-top: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: 40px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: #cfcabf; background: #fbfaf7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #285f51; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 5px 11px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.danger-outline { color: var(--bad); border-color: #ecc8c3; background: transparent; }
.btn.danger-outline:hover { background: var(--bad-soft); }
.icon-btn { width: 36px; height: 40px; border: 1px solid var(--line); background: var(--card); border-radius: 9px; font-size: 20px; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { color: var(--bad); border-color: #ecc8c3; }

/* forms */
.form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 14px; }
.form label > input, .form label > select, .form label > textarea, .form .money-input { margin-top: 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink);
  padding: 9px 11px; border: 1px solid #d6d2c8; border-radius: 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 94, .15); }
input[type=file] { padding: 7px; background: #fbfaf7; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
.form label.check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; margin: 10px 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1 1 260px; }
.filters input[type=month], .filters select { flex: 0 1 180px; width: auto; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.danger-zone { margin-top: 8px; display: flex; justify-content: flex-end; }

.student-select { padding: 4px; }
.student-select option { padding: 8px 10px; border-radius: 6px; }
.filter-input { margin-bottom: 8px; }

.item-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.item-row > input { flex: 1; }
.money-input { display: flex; align-items: center; border: 1px solid #d6d2c8; border-radius: 9px; background: #fff; flex: 0 0 170px; margin-top: 0 !important; }
.money-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 94, .15); }
.money-input span { padding-left: 11px; color: var(--muted); font-size: 14px; }
.money-input input { min-width: 0; border: 0; box-shadow: none !important; text-align: right; font-variant-numeric: tabular-nums; }
.total-line { display: flex; justify-content: flex-end; align-items: baseline; gap: 12px; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; color: var(--muted); }
.total-line strong { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* lists */
.list { margin: 0 -20px -20px; }
.list-group { padding: 8px 20px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; background: #faf9f6; border-top: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line); color: var(--ink); }
a.row:hover { background: #faf9f6; text-decoration: none; }
.row-main { display: flex; flex-direction: column; min-width: 0; color: var(--ink); }
.row-main:hover { text-decoration: none; }
.row-main strong { font-weight: 600; }
.row-main .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: flex; align-items: center; gap: 12px; flex: none; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; vertical-align: middle; }
.badge-sent { background: #e5f4ea; color: var(--ok); }
.badge-draft { background: var(--warn-soft); color: var(--warn); }
.badge-void { background: #eceae5; color: var(--muted); }
h1 .badge { font-size: 13px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 2px; color: var(--ink); box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; border-color: #cfcabf; }
.stat-n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 13px; color: var(--muted); }
.stat-warn .stat-n { color: var(--warn); }

/* definition lists */
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

/* invoice preview */
.preview-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.pdf-frame { padding: 0; overflow: hidden; height: 80vh; min-height: 560px; position: relative; }
.pdf-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.pdf-fallback { display: none; }
.side .card { margin-bottom: 16px; }
.checks { list-style: none; padding: 0; margin: 0 0 12px; font-size: 13.5px; }
.checks li { padding: 5px 0 5px 26px; position: relative; }
.checks li::before { position: absolute; left: 0; top: 4px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.checks li.ok::before { content: "✓"; background: #e5f4ea; color: var(--ok); }
.checks li.warn::before { content: "!"; background: var(--warn-soft); color: var(--warn); }
.checks li.bad::before { content: "✕"; background: var(--bad-soft); color: var(--bad); }
.checks li.bad { color: var(--bad); }
.log { list-style: none; padding: 0; margin: 0; }
.log li { padding: 6px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }

/* flash */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; border: 1px solid transparent; }
.flash ul { margin: 0; padding-left: 18px; }
.flash-success { background: #e5f4ea; border-color: #c4e5cf; color: #1f6b39; }
.flash-error { background: var(--bad-soft); border-color: #f0cdc8; color: #8e2c22; }
.flash-info { background: #e8f0f7; border-color: #cddcea; color: #2b4d6b; }
.banner { background: var(--warn-soft); border: 1px solid #f1dcb3; color: #7a5212; padding: 9px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13.5px; }

/* settings */
.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-row label { flex: 1; min-width: 220px; margin-bottom: 0; }
.logo-preview { width: 64px; height: 64px; object-fit: contain; border: 1px solid var(--line); border-radius: 10px; padding: 4px; background: #fff; }
.inline-form .inline { margin-top: 4px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head h1 { margin-top: 12px; font-size: 21px; }
.login-head p { margin: 0; }
.login-logo { width: 64px; height: 64px; object-fit: contain; }

/* responsive */
@media (max-width: 900px) {
  .preview-grid { grid-template-columns: 1fr; }
  .pdf-frame { height: 70vh; min-height: 420px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  body { padding-bottom: 72px; }
  .topbar { padding: 10px 16px; gap: 12px; }
  .brand { max-width: 60vw; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--line);
    justify-content: space-around; gap: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav a.on { background: none; }
  .nav-cta svg { background: var(--accent); color: #fff; border-radius: 10px; padding: 4px; width: 30px; height: 30px; }
  .nav-cta span { color: var(--accent); }
  .main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .list { margin: 0 -16px -16px; }
  .row, .list-group { padding-left: 16px; padding-right: 16px; }
  .hide-sm { display: none; }
  h1 { font-size: 21px; }
  .page-head { align-items: flex-start; }
  .page-head > .btn, .page-head .btn-row { width: 100%; }
  .page-head .btn-row .btn, .page-head > .btn { flex: 1; }
  .item-row { flex-wrap: wrap; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
  .item-row > input { flex: 1 1 100%; }
  .money-input { flex: 1 1 0; min-width: 0; }
  .sticky-actions { bottom: 64px; }
  .sticky-actions .btn { flex: 1; }
  .pdf-fallback { display: block; position: absolute; bottom: 10px; right: 10px; background: var(--card); padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; }
  .dl { grid-template-columns: 96px 1fr; }
  .filters input[type=month], .filters select { flex: 1 1 140px; }
}
