/* Tuition Manager — mobile-first styles */
:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #4338ca;
  --primary-ink: #ffffff;
  --primary-soft: #eef2ff;
  --green: #047857;
  --green-soft: #ecfdf5;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 1px 8px rgba(17, 24, 39, .04);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.bare { padding-bottom: 0; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--primary); color: var(--primary-ink);
}
.topbar .brand { color: inherit; font-weight: 700; font-size: 1.05rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { color: inherit; display: inline-flex; padding: 6px; border-radius: 10px; }
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.container { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* Bottom tab bar (mobile) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 500;
}
.tabbar a.active { color: var(--primary); }
.tabbar a.collect-tab .bubble {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; margin-top: -22px; border-radius: 50%;
  background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(67, 56, 202, .4);
}

/* Desktop: tab bar becomes a left sidebar */
@media (min-width: 900px) {
  body { padding-bottom: 24px; padding-left: 210px; }
  body.bare { padding-left: 0; }
  .topbar { padding-left: 226px; margin-left: -210px; }
  .tabbar {
    top: 0; bottom: 0; right: auto; width: 210px; height: auto;
    flex-direction: column; justify-content: flex-start; gap: 4px; padding: 72px 12px 12px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tabbar a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: .92rem; }
  .tabbar a.active { background: var(--primary-soft); }
  .tabbar a.collect-tab .bubble { width: auto; height: auto; margin: 0; background: none; color: inherit; box-shadow: none; }
  .container { padding: 24px; }
}

/* Cards and layout */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3-1 { grid-template-columns: 2fr 1fr; }
}
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat .label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.accent { background: var(--primary); color: #fff; }
.stat.accent .label, .stat.accent .sub { color: rgba(255, 255, 255, .8); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover { border-color: #cbd5e1; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #3730a3; border-color: #3730a3; }
.btn-danger { color: var(--red); border-color: #fecaca; background: var(--red-soft); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn-lg { min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { display: flex; width: 100%; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; min-height: 0; font-weight: 600; cursor: pointer; font: inherit; }

/* Collect-fee hero button on dashboard */
.collect-hero { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 58px; margin-bottom: 16px; font-size: 1.1rem; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  font: inherit; font-size: 16px; /* prevents iOS zoom */
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.form-grid { display: grid; gap: 0 14px; }
.form-grid > * { min-width: 0; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.amount-input { font-size: 1.8rem; font-weight: 700; min-height: 62px; text-align: center; font-variant-numeric: tabular-nums; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checkbox input { width: 20px; min-height: 20px; height: 20px; }

/* Segmented radio (payment mode) and chips */
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  margin: 0; display: flex; align-items: center; justify-content: center; min-height: 44px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-weight: 600; color: var(--ink-2);
}
.segmented input:checked + label { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.segmented input:focus-visible + label { outline: 2px solid var(--primary); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: 36px; padding: 6px 14px;
  border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.active, .chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover .title { color: var(--primary); }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { font-size: .82rem; color: var(--muted); }
.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .9rem;
}

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-gray { background: #f3f4f6; color: var(--muted); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }

/* Progress */
.progress { height: 8px; background: #eef0f4; border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress.done > span { background: var(--green); }

/* Flash */
.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.flash-success { background: var(--green-soft); color: var(--green); border: 1px solid #a7f3d0; }
.flash-error { background: var(--red-soft); color: var(--red); border: 1px solid #fecaca; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; white-space: nowrap; }
tfoot td { font-weight: 700; border-bottom: 0; }

/* Tabs */
.tabs { display: flex; gap: 4px; background: #e9ebf1; padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tabs a { flex: 1; text-align: center; padding: 9px 8px; border-radius: 9px; color: var(--ink-2); font-weight: 600; font-size: .9rem; }
.tabs a.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* Student profile */
.profile-head { display: flex; gap: 14px; align-items: center; }
.profile-head .avatar { width: 56px; height: 56px; font-size: 1.2rem; }
.due-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border-radius: var(--radius); flex-wrap: wrap; }
.due-box.has-dues { background: var(--red-soft); }
.due-box.clear { background: var(--green-soft); }
.due-box .amount { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.due-box.has-dues .amount { color: var(--red); }
.due-box.clear .amount { color: var(--green); }
.months { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; }
.month { padding: 8px; border-radius: 10px; text-align: center; font-size: .78rem; font-weight: 600; }
.month .m { display: block; font-size: .85rem; }
.month.paid { background: var(--green-soft); color: var(--green); }
.month.partial { background: var(--amber-soft); color: var(--amber); }
.month.due { background: var(--red-soft); color: var(--red); }
dl.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: .92rem; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; font-weight: 500; }

/* Attendance */
.class-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.class-btn {
  position: relative; display: flex; align-items: center; justify-content: center; min-height: 52px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 700;
}
.class-btn.current { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.class-btn.done::after { content: "✓"; position: absolute; top: 3px; right: 7px; font-size: .75rem; color: var(--green); }
.att-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.att-row:last-child { border-bottom: 0; }
.att-row .main { flex: 1; min-width: 0; }
.att-toggle { position: relative; }
.att-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.att-toggle label {
  margin: 0; display: flex; align-items: center; justify-content: center; width: 96px; min-height: 42px;
  border-radius: 12px; font-weight: 700; cursor: pointer; user-select: none;
  background: var(--green-soft); color: var(--green); border: 1px solid #a7f3d0;
}
.att-toggle label::before { content: "Present"; }
.att-toggle input:checked + label { background: var(--red-soft); color: var(--red); border-color: #fecaca; }
.att-toggle input:checked + label::before { content: "Absent"; }
.att-toggle input:focus-visible + label { outline: 2px solid var(--primary); }
.sticky-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 10;
  display: flex; align-items: center; gap: 12px; padding: 12px; margin-top: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: 0 4px 20px rgba(17, 24, 39, .12);
}
@media (min-width: 900px) { .sticky-bar { bottom: 16px; } }

/* Auth pages */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; padding: 24px; }
.auth h1 { margin-bottom: 4px; }

/* Receipt preview */
.receipt-ok { text-align: center; padding: 8px 0 4px; }
.receipt-ok .tick {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center; background: var(--green-soft); color: var(--green);
}
.receipt-ok .tick svg.i { width: 30px; height: 30px; }
.big-amount { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Search */
.search { position: relative; }
.search svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.search input { padding-left: 40px; }

.chart-box { position: relative; height: 230px; }

/* Export dropdown */
.export-menu { position: relative; }
.export-menu > summary { list-style: none; }
.export-menu > summary::-webkit-details-marker { display: none; }
.export-menu > summary::after { content: "▾"; font-size: .75rem; color: var(--muted); }
.export-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 210px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(17, 24, 39, .14); padding: 6px;
}
.export-list a { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; color: var(--ink); font-weight: 500; }
.export-list a:hover, .export-list a:focus-visible { background: var(--primary-soft); }
.export-list .badge { min-width: 44px; justify-content: center; }
details summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
