/* Class Mercado — styles */

:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --surface-2: #f4eee4;
  --text: #2a2420;
  --muted: #6d625a;
  --line: #e6ddd1;
  --primary: #1f6f4a;
  --primary-hover: #185a3c;
  --primary-soft: #e3f1e9;
  --warn: #b4531a;
  --warn-hover: #96430f;
  --danger: #b42318;
  --pos: #1f7a4d;
  --neg: #b42318;
  --focus: #2563eb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(42, 36, 32, .06), 0 4px 16px rgba(42, 36, 32, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }
a:hover { color: var(--primary-hover); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: .5rem; top: .5rem; }

.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand:hover { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.topbar-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { outline: none; }

.page { max-width: 760px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-wide { max-width: 960px; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.card-head h2 { margin: 0; }
.notice { background: var(--primary-soft); border-color: #c4e2d1; }
.soon { background: var(--surface-2); box-shadow: none; }
.section-title { margin-top: 1.5rem; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; margin: 0; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .6rem 1.2rem;
  border: 2px solid var(--primary); border-radius: 999px;
  background: var(--primary); color: #fff;
  font: inherit; font-weight: 700; text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary-hover); }
.btn-warn { background: var(--warn); border-color: var(--warn); }
.btn-warn:hover { background: var(--warn-hover); border-color: var(--warn-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #8f1b12; border-color: #8f1b12; }
.btn-small { min-height: 38px; padding: .35rem .9rem; font-size: .95rem; }
.btn-block { width: 100%; }
.danger-text { color: var(--danger); border-color: var(--danger); }
.danger-text:hover { background: #fdecea; color: var(--danger); }

.icon-btn {
  border: none; background: transparent; font-size: 1.1rem; cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); }

.actions { display: flex; justify-content: flex-end; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }
.actions-left { justify-content: flex-start; }

/* ---------- Forms ---------- */

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 700; margin-bottom: .3rem; }
.field input, .field select, .search {
  width: 100%; min-height: 46px; padding: .55rem .8rem;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line); border-radius: var(--radius-sm);
}
.field input:focus, .field select:focus, .search:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.field-check { display: flex; align-items: center; gap: .6rem; }
.field-check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); }
.field-check label { margin: 0; font-weight: 500; }
.hint { font-size: .9rem; color: var(--muted); margin: .3rem 0 0; }
.input-code { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; font-size: 1.2rem !important; }
.form-error {
  background: #fdecea; color: var(--danger); border-radius: var(--radius-sm);
  padding: .6rem .8rem; font-weight: 600; margin: 0 0 1rem;
}
.inline-form .field { max-width: 420px; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: -.25rem 0 1rem; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: .3rem .8rem; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip:hover { border-color: var(--primary); }

/* ---------- Welcome & login ---------- */

.auth { max-width: 720px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; text-align: center; }
.auth-card { max-width: 440px; margin: 1.5rem auto 0; text-align: left; }
.brand-lg { display: inline-block; font-size: 1.4rem; }
.brand-xl { font-weight: 800; font-size: 2.4rem; letter-spacing: -0.02em; }
.tagline { font-size: 1.2rem; color: var(--muted); margin-bottom: 2rem; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.25rem; }
.choice { display: flex; flex-direction: column; gap: .75rem; align-items: stretch; padding: 1.75rem 1.5rem; }
.choice h2 { margin-bottom: .5rem; }
.choice-icon { font-size: 3rem; line-height: 1; }
.switch { text-align: center; margin: 1.25rem 0 0; color: var(--muted); }

/* ---------- Student home ---------- */

.balance-card {
  background: linear-gradient(135deg, #1f6f4a, #2f8a5f);
  color: #fff; border-radius: var(--radius); padding: 1.75rem 1.5rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow); text-align: center;
}
.balance-card p { margin: 0; }
.balance-hello { font-size: 1.2rem; font-weight: 700; }
.balance-label { opacity: .85; margin-top: .75rem !important; }
.balance-amount { font-size: 2.75rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.balance-amount.neg { color: #ffd2cc; }
.balance-class { opacity: .8; margin-top: .5rem !important; font-size: .95rem; }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 4px; }
.seg-btn {
  border: none; background: transparent; font: inherit; font-weight: 600; color: var(--muted);
  padding: .4rem 1rem; border-radius: 999px; cursor: pointer; min-height: 36px;
}
.seg-btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* Summary tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1.25rem; }
.tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: .75rem; display: flex; flex-direction: column; }
.tile-label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Ledger */
.ledger { list-style: none; margin: 0; padding: 0; }
.ledger-day { font-size: .85rem; font-weight: 700; color: var(--muted); padding: .9rem 0 .3rem; border-bottom: 1px solid var(--line); }
.ledger-row { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.ledger-icon { font-size: 1.3rem; width: 2rem; text-align: center; flex: none; }
.ledger-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ledger-desc { font-weight: 600; overflow-wrap: anywhere; }
.ledger-meta { font-size: .85rem; color: var(--muted); }
.ledger-amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Tables ---------- */

.table { width: 100%; border-collapse: collapse; }
.table caption { text-align: left; font-weight: 700; padding-bottom: .5rem; }
.table th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 700; padding: .5rem .5rem; border-bottom: 2px solid var(--line); }
.table th.num { text-align: right; }
.table td { padding: .65rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table .check { width: 2.5rem; }
.table input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }
.students tbody tr:hover { background: var(--surface-2); }
.student-link { font-weight: 700; text-decoration: none; }
.username { display: block; font-size: .85rem; }
.weeks { margin-bottom: .5rem; }

/* ---------- Teacher ---------- */

.toolbar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .search { flex: 1 1 220px; width: auto; }
.toolbar-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.class-header { display: grid; grid-template-columns: 1fr auto; gap: .75rem 1.5rem; align-items: end; margin-bottom: 1.25rem; }
.class-title h1 { margin: .25rem 0 0; }
.class-title p { margin: 0; }
.back-link { display: inline-block; text-decoration: none; font-weight: 600; margin-bottom: .5rem; }
.code-chip {
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border: 2px dashed var(--primary); border-radius: var(--radius);
  padding: .5rem .75rem .5rem 1rem;
}
.code-label { font-size: .8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.code-value { font-size: 1.5rem; font-weight: 800; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
.code-inline { letter-spacing: .1em; }
.tabs { grid-column: 1 / -1; display: flex; gap: .25rem; border-bottom: 2px solid var(--line); }
.tab {
  padding: .6rem 1rem; text-decoration: none; font-weight: 700; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); }

.class-list { list-style: none; margin: 0; padding: 0; }
.class-link {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  margin-bottom: .6rem; text-decoration: none; color: var(--text);
}
.class-link:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.class-link-name { font-weight: 700; font-size: 1.1rem; }

.student-head { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; }
.student-head h1 { margin-bottom: .25rem; }
.student-head .actions { grid-column: 1 / -1; margin-top: 0; }
.student-balance { display: flex; flex-direction: column; text-align: right; }
.student-balance .tile-value { font-size: 1.6rem; }

.removed summary { cursor: pointer; font-weight: 700; color: var(--muted); }
.removed ul { margin: .75rem 0 0; padding-left: 1.25rem; }

/* ---------- Dialogs ---------- */

.dialog {
  border: none; border-radius: var(--radius); padding: 1.25rem 1.5rem 1.5rem;
  width: min(480px, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.25);
  color: var(--text);
}
.dialog::backdrop { background: rgba(42, 36, 32, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.dialog-head h2 { margin: 0; }

/* ---------- Toasts & loading ---------- */

.toasts { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 1000; width: min(420px, calc(100vw - 2rem)); }
.toast {
  background: var(--text); color: #fff; padding: .75rem 1rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow); font-weight: 600; transition: opacity .4s, transform .4s;
}
.toast-error { background: var(--danger); }
.toast-hide { opacity: 0; transform: translateY(8px); }

.loading { display: flex; justify-content: center; align-items: center; gap: .6rem; color: var(--muted); padding: 3rem 1rem; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.noscript { text-align: center; padding: 2rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0s !important; }
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  body { font-size: 16px; }
  .class-header { grid-template-columns: 1fr; }
  .code-chip { justify-self: start; }
  .tiles { grid-template-columns: 1fr 1fr 1fr; gap: .5rem; }
  .tile { padding: .6rem; }
  .tile-value { font-size: 1rem; }
  .balance-amount { font-size: 2.25rem; }
  .student-head { grid-template-columns: 1fr; }
  .student-balance { text-align: left; }
  .topbar-name { display: none; }
}
