/* Sparky admin — the app's look (src/constants/theme.ts): orange #FF8A00 with dark text on it,
   warm neutrals, Nunito, "clay" buttons and cards with a solid lip underneath. */
:root {
  --orange: #ff8a00;
  --orange-lip: #d46f00;
  --orange-dark: #b85a00;
  --orange-deep: #f06e00;
  --orange-soft: #ffebd1;
  --orange-tint: #fff6ea;
  --orange-border: #ffc98a;
  --dark: #15171d;
  --text: #15171d;
  --muted: #6b6559;
  --faint: #a8a396;
  --border: #ece6db;
  --lip: #e3dccf;
  --surface: #f7f3ec;
  --bg: #fbf7f0;
  --white: #fff;
  --green: #21c16b;
  --green-dark: #128048;
  --green-soft: #e4f8ec;
  --red: #ff4d4f;
  --red-lip: #d63638;
  --red-soft: #ffeded;
  --blue: #4d88ff;
  --blue-soft: #e8f0ff;
  --yellow-soft: #fff3c4;
  --card-shadow: 0 3px 0 var(--border), 0 10px 24px rgba(21, 23, 29, 0.06);
  --radius: 24px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Nunito", system-ui, sans-serif; color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--orange-dark); font-weight: 700; }
img { display: block; }
.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red-lip); font-weight: 700; font-size: 14px; }
.error:empty { display: none; }

/* ---------- buttons: clay, the face moves down onto its lip when pressed ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border: 0; border-radius: 16px;
  background: var(--orange); color: var(--dark); font-weight: 900; font-size: 15px; white-space: nowrap;
  box-shadow: 0 4px 0 var(--orange-lip); cursor: pointer; text-decoration: none;
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.04); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--orange-lip); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: var(--white); color: var(--text); box-shadow: 0 4px 0 var(--lip), inset 0 0 0 2px var(--border); }
.btn.ghost:active:not(:disabled) { box-shadow: 0 0 0 var(--lip), inset 0 0 0 2px var(--border); }
.btn.danger { background: var(--red); color: var(--white); box-shadow: 0 4px 0 var(--red-lip); }
.btn.danger:active:not(:disabled) { box-shadow: 0 0 0 var(--red-lip); }
.btn.green { background: var(--green); color: var(--white); box-shadow: 0 4px 0 #179652; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 12px; box-shadow: 0 3px 0 var(--orange-lip); }
.btn.small.ghost { box-shadow: 0 3px 0 var(--lip), inset 0 0 0 2px var(--border); }
.btn.small.danger { box-shadow: 0 3px 0 var(--red-lip); }
.btn.block { width: 100%; }

/* ---------- fields ---------- */
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 800; color: var(--muted); }
input, select, textarea {
  min-height: 48px; padding: 10px 14px; border: 2px solid var(--border); border-radius: 14px;
  background: var(--white); min-width: 0; width: 100%; font-weight: 600;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input::placeholder { color: var(--faint); font-weight: 600; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 4px var(--orange-soft); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; overflow: hidden; }
.login-card { width: 100%; max-width: 400px; background: var(--white); border-radius: 32px; padding: 28px 28px 32px; box-shadow: var(--card-shadow); display: grid; gap: 14px; }
.login-card .hero { width: 150px; height: 150px; justify-self: center; margin-top: -8px; }
.login-card h1 { margin: 0; text-align: center; font-size: 28px; font-weight: 900; }
.login-card p { margin: 0 0 4px; text-align: center; color: var(--muted); font-weight: 600; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; min-height: 100vh; padding: 16px; }
.layout > * { min-width: 0; }
.side {
  position: sticky; top: 16px; height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 4px;
  background: var(--white); border-radius: 28px; padding: 18px 14px; box-shadow: var(--card-shadow); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; }
.brand img { width: 48px; height: 48px; border-radius: 50%; background: var(--orange-soft); }
.brand b { display: block; font-size: 21px; font-weight: 900; line-height: 1.1; }
.brand small { display: block; font-size: 11px; letter-spacing: .12em; color: var(--orange-dark); font-weight: 900; }
.nav {
  display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 10px 12px; border-radius: 16px;
  background: none; border: 0; cursor: pointer; text-align: left; font-weight: 800; color: var(--muted);
  transition: background .15s ease, color .15s ease;
}
.nav .icon { width: 24px; text-align: center; font-size: 18px; }
.nav:hover { background: var(--surface); color: var(--text); }
.nav.active { background: var(--orange); color: var(--dark); box-shadow: 0 4px 0 var(--orange-lip); }
.nav .count { margin-left: auto; min-width: 24px; text-align: center; background: var(--red); color: var(--white); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 900; }
.nav.active .count { background: var(--dark); }
.side .spacer { flex: 1; min-height: 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 18px; background: var(--surface); margin-bottom: 8px; }
.me .avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 900; background: var(--orange-soft); color: var(--orange-dark); text-transform: uppercase; }
.me b { display: block; font-weight: 900; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .role { font-size: 12px; font-weight: 800; color: var(--orange-dark); }
.me div { min-width: 0; }

.main { padding: 12px 8px 64px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head h1 { margin: 0; font-size: 30px; font-weight: 900; letter-spacing: -.01em; flex: 1; min-width: 200px; }
.lead-text { margin: -8px 0 18px; color: var(--muted); font-weight: 600; max-width: 760px; }
.section-title { margin: 26px 0 14px; font-size: 20px; font-weight: 900; }

/* ---------- cards ---------- */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--white); border-radius: var(--radius); padding: 20px; box-shadow: var(--card-shadow); min-width: 0; }
.card h2 { margin: 0 0 12px; font-size: 18px; font-weight: 900; }
.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }
.card.spaced { margin-top: 16px; }
.kpi { display: grid; gap: 4px; align-content: start; }
.kpi b { font-size: 34px; font-weight: 900; line-height: 1.05; }
.kpi span { color: var(--muted); font-weight: 700; font-size: 13px; }
.kpi.accent { background: var(--orange); box-shadow: 0 4px 0 var(--orange-lip), 0 12px 24px rgba(255, 138, 0, .25); }
.kpi.accent span { color: var(--dark); }
.bar { display: grid; grid-template-columns: 130px 1fr 36px; align-items: center; gap: 10px; margin: 10px 0; font-weight: 800; font-size: 14px; }
.bar .track { height: 12px; border-radius: 6px; background: var(--surface); overflow: hidden; }
.bar .fill { height: 100%; background: var(--orange); border-radius: 6px; }
.bar b { text-align: right; }
.recent { display: grid; grid-template-columns: auto 1fr auto; gap: 10px 12px; align-items: center; font-size: 14px; font-weight: 600; }
.recent .muted { white-space: nowrap; }

.note-card { display: flex; gap: 14px; align-items: center; background: var(--orange-tint); border: 2px solid var(--orange-soft); border-radius: 20px; padding: 14px 16px; margin-bottom: 16px; font-weight: 600; }
.note-card img { width: 56px; height: 56px; flex: none; }
.note-card p { margin: 0; }
.note-card.info { background: var(--blue-soft); border-color: #d3e1ff; }

.form-card { display: grid; grid-template-columns: 2fr 1fr 1fr 2fr auto; gap: 12px; align-items: end; margin-bottom: 18px; }
.form-card.curator { grid-template-columns: 1.5fr 1.5fr 1fr auto; }
.form-card.search { grid-template-columns: minmax(0, 1fr) auto; max-width: 720px; }

/* ---------- «Спарки ученика» ---------- */
.student { display: grid; gap: 10px; margin: 18px 0 16px; }
.student h2 { margin: 0; word-break: break-word; }
.student-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; font-weight: 700; font-size: 14px; }
.kpi.held { background: var(--yellow-soft); box-shadow: 0 4px 0 #f0d77a, 0 10px 24px rgba(21, 23, 29, .06); }
.kpi.held span { color: #6b5400; }
.note-card.held { background: var(--yellow-soft); border-color: #f0d77a; align-items: flex-start; }
.note-line { display: block; margin-top: 6px; }
.op { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; font-weight: 700; }
.amount { font-weight: 900; font-size: 15px; white-space: nowrap; }
.amount.plus { color: var(--green-dark); }
.amount.minus { color: var(--red-lip); }
tr.held td, tbody tr.held:hover td { background: #fffaeb; }
.s-held { background: var(--yellow-soft); color: #8a6d00; }
.k-earn { background: var(--orange-soft); color: var(--orange-dark); }
.k-bonus { background: var(--blue-soft); color: #2f5fc4; }
.k-shop { background: #f1e7ff; color: #6c3fc4; }
.k-withdraw { background: var(--yellow-soft); color: #8a6d00; }
.k-refund { background: var(--green-soft); color: var(--green-dark); }

/* ---------- tables (become cards on phones) ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"] { flex: 1; min-width: 220px; width: auto; }
.toolbar select { width: auto; min-width: 180px; }
.table-wrap { background: var(--white); border-radius: var(--radius); box-shadow: var(--card-shadow); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 900; background: var(--surface); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fffdf9; }
td select, td input { min-height: 40px; padding: 6px 10px; border-radius: 12px; font-size: 13px; }
td select { min-width: 160px; padding-right: 32px; }
td .note { min-width: 170px; }
.comment-cell { min-width: 180px; max-width: 280px; }
.phone { font-weight: 900; white-space: nowrap; }
.links { display: flex; gap: 10px; font-size: 13px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.code { font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 13px; letter-spacing: .02em; background: var(--surface); border-radius: 8px; padding: 3px 8px; white-space: nowrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); font-weight: 700; display: grid; justify-items: center; gap: 8px; }
.empty img { width: 120px; height: 120px; }

.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 900; white-space: nowrap; }
.s-new { background: var(--red-soft); color: #c42b2d; }
.s-contacted { background: var(--blue-soft); color: #2f5fc4; }
.s-invoiced { background: var(--orange-soft); color: var(--orange-dark); }
.s-paid { background: var(--yellow-soft); color: #8a6d00; }
.s-access, .s-on { background: var(--green-soft); color: var(--green-dark); }
.s-lost, .s-off { background: var(--surface); color: var(--muted); }
.s-hot { background: var(--red-soft); color: #c42b2d; }
.plan-standard { background: var(--blue-soft); color: #2f5fc4; }
.plan-pro { background: var(--orange-soft); color: var(--orange-dark); }
.plan-max { background: #f1e7ff; color: #6c3fc4; }
.plan-promo { background: #dff4ff; color: #0b6a8c; }
.yes { color: var(--green-dark); font-weight: 800; font-size: 13px; }
.no { color: var(--faint); font-weight: 700; font-size: 13px; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 28px; padding: 0; width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 6px 0 var(--border), 0 30px 60px rgba(21, 23, 29, .25); background: var(--white); color: var(--text); }
dialog::backdrop { background: rgba(21, 23, 29, .5); }
.dialog { padding: 24px; display: grid; gap: 14px; }
.dialog h2 { margin: 0; font-size: 22px; font-weight: 900; }
.dialog p { margin: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row > * { flex: 1 1 0; min-width: 0; }
.segments { display: flex; gap: 6px; background: var(--surface); border-radius: 16px; padding: 5px; }
.segments button { flex: 1; min-height: 40px; border: 0; border-radius: 12px; background: none; font-weight: 900; color: var(--muted); cursor: pointer; }
.segments button.on { background: var(--white); color: var(--text); box-shadow: 0 3px 0 var(--lip); }
.segments.wrap { flex-wrap: wrap; }
.segments.wrap button { flex: 1 1 28%; }
.issued { background: var(--orange-tint); border: 2px solid var(--orange-border); border-radius: 20px; padding: 16px; display: grid; gap: 12px; justify-items: stretch; }
.issued .cheer { width: 96px; height: 96px; justify-self: center; }
.issued .code { font-size: 17px; text-align: center; background: var(--white); padding: 12px; white-space: normal; word-break: break-all; }
.issued .ok-title { text-align: center; font-weight: 900; font-size: 17px; }
.issued .ok-sub { text-align: center; color: var(--muted); font-weight: 700; margin-top: -8px; word-break: break-all; }
.issued .ok-sub.plain { word-break: normal; }
.issued .row > * { flex: 1 1 150px; }
.secret { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; font-weight: 700; }
.secret .code { font-size: 16px; }
.warn { color: var(--orange-dark); font-weight: 800; font-size: 13px; }

/* ---------- phones and tablets ---------- */
@media (max-width: 1100px) {
  .kpis, .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-card { grid-template-columns: 1fr 1fr; }
  .form-card .wide { grid-column: 1 / -1; }
  .form-card.curator { grid-template-columns: 1fr 1fr; }
  .form-card.curator .btn { grid-column: 1 / -1; }
  .form-card.search { grid-template-columns: minmax(0, 1fr) auto; }
  .form-card.search .wide { grid-column: auto; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .side { position: sticky; top: 0; z-index: 5; height: auto; border-radius: 0 0 24px 24px; padding: 10px 12px 12px; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; overflow: visible; }
  .brand { padding: 0 6px 0 0; flex: 1; }
  .brand img { width: 40px; height: 40px; }
  .side .spacer { display: none; }
  .me { order: 1; margin: 0; padding: 6px 10px 6px 6px; background: none; }
  .me .avatar { width: 34px; height: 34px; }
  .me b { max-width: 110px; font-size: 14px; }
  .side .logout { order: 2; min-height: 40px; padding: 6px 10px; }
  .side nav { order: 3; display: flex; gap: 6px; overflow-x: auto; flex: 1 1 100%; min-width: 0; max-width: 100%; padding-bottom: 6px; scrollbar-width: none; }
  .side nav::-webkit-scrollbar { display: none; }
  .nav { flex: none; min-height: 42px; padding: 8px 12px; background: var(--surface); }
  .main { padding: 18px 16px 48px; }
  .head h1 { font-size: 24px; }
  .two { grid-template-columns: 1fr; }
  .bar { grid-template-columns: 110px 1fr 30px; }

  /* Tables turn into cards: each cell gets its column name. */
  .table-wrap { background: none; box-shadow: none; overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr { background: var(--white); border-radius: 20px; box-shadow: var(--card-shadow); padding: 6px 4px; margin-bottom: 14px; }
  td { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 10px; border: 0; padding: 8px 12px; }
  td::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 900; padding-top: 3px; }
  td[data-label=""]::before { display: none; }
  td[data-label=""] { grid-template-columns: 1fr; }
  tbody tr:hover td, tbody tr.held:hover td { background: none; }
  tbody tr.held { background: #fffaeb; box-shadow: 0 3px 0 #f0d77a, 0 10px 24px rgba(21, 23, 29, .06); }
  tr.held td { background: none; }
  td select, td .note { min-width: 0; width: 100%; }
  .comment-cell { max-width: none; }
  .code { white-space: normal; word-break: break-all; }
}
@media (max-width: 520px) {
  .me div { display: none; }
  .me { padding: 0; }
  .kpis, .kpis.five { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi b { font-size: 26px; }
  .card { padding: 16px; border-radius: 20px; }
  .form-card, .form-card.curator, .form-card.search { grid-template-columns: 1fr; }
  .form-card .btn { width: 100%; }
  .toolbar select { width: 100%; }
  .login-card { padding: 22px 20px 26px; border-radius: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active:not(:disabled) { transform: none; }
}

/* copy() in admin.js: a field for the execCommand fallback (selectable, so not display: none) and,
   when copying is blocked completely, the text shown selected for a manual copy. */
.copy-buffer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; }
.copy-manual { width: 100%; resize: none; font-size: 14px; }
.row > .copy-manual, .issued .row > .copy-manual, .actions > .copy-manual { flex: 1 1 100%; }
