/* Shared layout + component design layer. Linked LAST in every template's <head> (after the
   page's own inline <style>), so these rules win over the per-page defaults at equal
   specificity - which means anything touched here must also carry its own mobile override
   below, since a page's inline @media rule no longer wins by coming later. Colors come from
   the theme variables in static/theme.css. */

:root {
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-soft: #f0f1f4;
  --surface: #ffffff;
  --radius: 12px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 18px rgba(16, 24, 40, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Page shell ---------- */
html, body { height: auto; min-height: 100%; }
body {
  margin: 0; padding: 0 0 48px;
  font-family: var(--font); color: var(--ink-2);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}
.page {
  width: min(1300px, calc(100% - 48px)); box-sizing: border-box;
  margin: 24px auto 0; padding: 28px 32px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
/* The topbar replaced whatever used to sit above a page's first block, so drop that block's
   top margin instead of leaving an empty band at the top of the card. */
.page > :first-child { margin-top: 0; }
h1 { color: var(--ink); font-size: 1.45rem; font-weight: 650; letter-spacing: -0.015em; }
h2 { color: var(--ink); font-weight: 620; letter-spacing: -0.01em; }

/* Page title row (student/family detail pages, public student/family pages). */
.page-header { display: flex; align-items: center; gap: 12px; margin: 0 0 1.25rem; padding: 0; background: none; }
.page-header h1 { margin: 0; color: var(--ink); text-shadow: none; }

/* ---------- Top bar (templates/admin/topbar.html) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(100deg, var(--c900), var(--c800));
  color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08), 0 6px 20px rgba(16, 24, 40, 0.12);
}
.topbar-inner {
  width: min(1300px, calc(100% - 48px)); margin: 0 auto;
  display: flex; align-items: center; gap: 24px; min-height: 60px;
}
.topbar a { color: inherit; text-decoration: none; }
.topbar a:hover { text-decoration: none; }
.topbar-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; font-weight: 650; font-size: 0.98rem; letter-spacing: -0.01em; }
.topbar-logo {
  width: 32px; height: 32px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.14); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.topbar-nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.topbar-nav::-webkit-scrollbar { display: none; }
.topbar-link {
  /* Reset browser/page button defaults - a page (e.g. templates/student/view.html) may put
     .topbar-link on a <button> rather than an <a>, and its own generic `button { ... }` rule
     would otherwise show through as a solid pill instead of a plain nav link. */
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: none; margin: 0; font-family: inherit; cursor: pointer;
  padding: 7px 12px; border-radius: 8px; font-size: 0.9rem; font-weight: 500; white-space: nowrap;
  color: rgba(255, 255, 255, 0.72) !important; transition: background 0.15s, color 0.15s;
}
.topbar-icon { flex-shrink: 0; opacity: 0.8; }
.topbar-link.active .topbar-icon, .topbar-link:hover .topbar-icon { opacity: 1; }
.topbar-link:hover { color: #fff !important; background: rgba(255, 255, 255, 0.08); }
.topbar-link.active { color: #fff !important; background: rgba(255, 255, 255, 0.16); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12); }
.topbar-user { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: auto; }
.topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.topbar-user-text { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-user-name { font-size: 0.86rem; font-weight: 600; color: #fff; }
.topbar-user-tz { font-size: 0.74rem; color: rgba(255, 255, 255, 0.65); }
.topbar-logout { margin: 0; display: block !important; }
.topbar-logout button {
  width: 34px; height: 34px; padding: 0; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: rgba(255, 255, 255, 0.75); border: 1px solid rgba(255, 255, 255, 0.2);
}
.topbar-logout button:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.topbar-alert { position: relative; }
.topbar-alert[hidden] { display: none; }
.topbar-alert-btn {
  width: 34px; height: 34px; padding: 0; margin: 0; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; cursor: pointer;
}
.topbar-alert-btn:hover, .topbar-alert-btn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.12); }
.topbar-alert-panel {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 60;
  width: min(300px, calc(100vw - 24px)); box-sizing: border-box; padding: 14px 16px;
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.18);
}
.topbar-alert-title { margin: 0 0 4px; font-size: 0.9rem; font-weight: 650; color: var(--ink); }
.topbar-alert-body { margin: 0 0 10px; font-size: 0.83rem; line-height: 1.45; color: var(--muted); }
.topbar-alert-days { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }
.topbar .topbar-alert-days a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 2px; border-bottom: 1px solid var(--line-soft);
  font-size: 0.86rem; font-weight: 550; color: var(--accent);
}
.topbar .topbar-alert-days li:last-child a { border-bottom: none; padding-bottom: 0; }
.topbar .topbar-alert-days a::after { content: "→"; color: var(--muted); }
.topbar .topbar-alert-days a:hover { color: var(--accent-dark); }

/* ---------- Components ---------- */
a { color: var(--accent); }
table { border-collapse: separate; border-spacing: 0; }
th {
  background: #f9fafb; color: var(--muted);
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line);
}
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
td { border-bottom: 1px solid var(--line-soft); }
tbody tr:hover > td { background: #fafafb; }

button { border-radius: 8px; font-weight: 500; transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; }
button.secondary { background: #fff; color: var(--ink-2); border: 1px solid #d1d5db; }
button.secondary:hover { background: #f9fafb; border-color: #c4c8cf; }
input, select, textarea { border-radius: 8px; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent-border-mid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
dialog { border-radius: 14px; box-shadow: 0 24px 60px rgba(16, 24, 40, 0.22); }
dialog::backdrop { background: rgba(17, 24, 39, 0.45); }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  body { padding: 0 0 32px; }
  .page { width: calc(100% - 20px); margin-top: 12px; padding: 18px 14px; border-radius: 10px; }
  h1 { font-size: 1.25rem; }

  .topbar-inner { width: 100%; box-sizing: border-box; padding: 0 12px; flex-wrap: wrap; gap: 0 10px; min-height: 0; }
  .topbar-brand { order: 1; padding: 10px 0; }
  .topbar-user { order: 2; }
  .topbar-user-text { display: none; }
  .topbar-nav { order: 3; flex-basis: 100%; margin: 0 -12px; padding: 0 8px 8px; -webkit-mask-image: linear-gradient(to right, #000 88%, transparent); mask-image: linear-gradient(to right, #000 88%, transparent); }
  .topbar-link { padding: 6px 10px; font-size: 0.85rem; gap: 6px; }
  .topbar-icon { width: 15px; height: 15px; }

  /* Pages stretch dialog inputs to full width on mobile (`dialog form input { width: 100% }`);
     a checkbox/radio caught by that fills its label and squeezes the label text to nothing. */
  dialog form input[type="checkbox"], dialog form input[type="radio"] { width: auto; flex: none; }

  /* Tables collapse into stacked cards on mobile (see each page's inline styles). */
  th:first-child, th:last-child { border-radius: 0; }
  tbody tr:hover > td { background: transparent; }
}

/* Online-lesson join chip (templates/shared/meeting_link.html): the provider's icon plus its name,
   or just a text label for an unknown provider. A known provider collapses to its icon on phones
   and in .join-compact spots. */
.join-link { flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px; vertical-align: middle; font-size: 0.75rem; font-weight: 600; line-height: 1.2; padding: 3px 9px 3px 5px; border-radius: 999px; background: #fff; color: #1f2937; border: 1px solid #d1d5db; text-decoration: none; white-space: nowrap; }
.join-link:hover { border-color: var(--accent); text-decoration: none; }
.join-link.join-other { padding-left: 9px; }
.join-link .meeting-icon { flex-shrink: 0; display: block; }
.join-link.join-compact:not(.join-other) { padding: 2px; border: 0; background: transparent; }
.join-link.join-compact:not(.join-other) .join-label { display: none; }
.join-link.join-compact.join-other { font-size: 0.7rem; padding: 0 6px; }
@media (max-width: 640px) {
  .join-link:not(.join-other) { padding: 5px; }
  .join-link:not(.join-other) .join-label { display: none; }
}

/* Homework review (templates/admin/homework_thread.html, templates/student/view.html):
   status badges and the reply/comment thread under a homework note. */
.hw-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.hw-badge-awaiting { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.hw-badge-reviewed { background: #dcfce7; color: #166534; border-color: #86efac; }
.hw-badge-none { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.hw-badge-row { margin-bottom: 6px; }
.hw-entry { background: #f8f9fb; border: 1px solid var(--line-soft, #f0f1f4); border-radius: 8px; padding: 8px 14px 10px; margin-top: 8px; text-align: left; }
.hw-entry-teacher { background: var(--accent-bg); border-color: var(--accent-border); margin-left: 18px; }
.hw-entry-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.75rem; color: #6b7280; margin-bottom: 2px; }
.hw-entry-author { display: inline-flex; align-items: center; gap: 5px; }
.hw-entry-teacher .hw-entry-author { color: var(--accent-dark); font-weight: 600; }
.hw-entry-body { white-space: pre-wrap; word-break: break-word; }
.hw-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.hw-inline-form { display: inline; margin: 0; }
.hw-btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; font-size: 0.85rem; width: auto; }
.hw-link-btn { background: none; border: none; padding: 0 2px; cursor: pointer; font-size: 0.85rem; width: auto; }
.hw-link-btn:hover { background: none; }
.hw-attach-row { display: flex; gap: 8px; }
.hw-check { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: #374151; }
.hw-check input { width: auto; }
.hw-dialog { max-width: 520px; width: 90%; }
.hw-dialog form { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.hw-dialog textarea { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; font-family: inherit; resize: vertical; }
/* Planned homework (docs/homework-templates-plan.md): the record dialogs' prefill hint and the
   Заплановані subtab's cards. */
.hw-prefill-hint { font-size: 0.85rem; color: var(--accent-dark); background: var(--accent-bg); border-radius: 6px; padding: 6px 10px; margin: 4px 0 8px; }
.hw-prefill-hint[hidden] { display: none; }
.hw-subtabs { display: flex; gap: 4px; margin-bottom: 1rem; border-bottom: 1px solid var(--accent-border); }
.hw-subtab { padding: 8px 16px; color: var(--accent-darker); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.hw-subtab:hover { color: var(--accent); text-decoration: none; }
.hw-subtab.active { border-bottom-color: var(--accent); color: var(--accent); }
.hw-tpl-intro { color: #6b7280; font-size: 0.9rem; margin: 0 0 1rem; max-width: 70ch; }
.hw-tpl-toolbar { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
.hw-tpl-group-badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-bg); color: var(--accent-dark); margin-left: 6px; vertical-align: middle; }
.hw-dialog select { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; background: #fff; }
/* Image attachments render as thumbnails (renderNote in handlers/admin.go); in a homework thread a
   reviewer also gets a ✏️ button opening the markup editor (docs/homework-annotation-plan.md). */
.att-img-wrap { position: relative; display: inline-block; vertical-align: top; margin: 6px 8px 2px 0; white-space: normal; }
.att-img { display: block; line-height: 0; }
.att-img img { display: block; max-width: 220px; max-height: 170px; min-width: 60px; min-height: 40px; border-radius: 8px; border: 1px solid #e5e7eb; background: #f3f4f6; object-fit: contain; }
.att-img:hover img { border-color: var(--accent-border); }
button.att-annotate { position: absolute; top: 6px; right: 6px; width: auto; display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; margin: 0; font-size: 0.85rem; line-height: 1.2; border-radius: 999px; border: 1px solid rgba(0, 0, 0, 0.08); background: rgba(255, 255, 255, 0.94); color: #111827; box-shadow: 0 2px 6px rgba(16, 24, 40, 0.18); cursor: pointer; }
button.att-annotate:hover { background: #fff; transform: scale(1.06); }

/* The markup editor dialog: full screen, a toolbar on top, the canvas, the comment row below. */
html.ann-open { overflow: hidden; }
/* position: fixed + inset: 0 pins it to the viewport in every browser, rather than trusting
   100vh/100dvh (which some mobile browsers measure past their own toolbars). */
dialog.ann-dialog { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; overflow: hidden; padding: 0; border: none; border-radius: 0; background: #1f2128; color: #f3f4f6; box-shadow: none; }
dialog.ann-dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.ann-shell { display: flex; flex-direction: column; height: 100%; }
.ann-toolbar { display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; padding: 8px 12px; background: #2a2d36; border-bottom: 1px solid #3a3e4a; }
.ann-group { display: flex; align-items: center; gap: 4px; }
.ann-dialog .ann-toolbar button { width: 38px; height: 38px; margin: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid transparent; background: transparent; color: #e5e7eb; cursor: pointer; box-shadow: none; }
.ann-dialog .ann-toolbar button:hover { background: #3a3e4a; }
.ann-dialog .ann-toolbar button.active { background: var(--accent); color: #fff; }
.ann-tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ann-dialog .ann-toolbar .ann-color::after { content: ""; width: 20px; height: 20px; border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 2px #2a2d36, 0 0 0 3px #6b7280; }
.ann-dialog .ann-toolbar .ann-color.active { background: transparent; }
.ann-dialog .ann-toolbar .ann-color.active::after { box-shadow: 0 0 0 2px #2a2d36, 0 0 0 4px #fff; }
.ann-width span { display: block; width: 20px; background: currentColor; border-radius: 3px; }
.ann-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.ann-dialog .ann-toolbar .ann-close { font-size: 1.1rem; }
.ann-dialog .ann-toolbar button.ann-save { width: auto; height: 38px; padding: 0 16px; background: var(--accent); color: #fff; font-weight: 600; white-space: nowrap; }
.ann-dialog .ann-toolbar button.ann-save:hover { background: var(--accent-dark); }
.ann-dialog .ann-toolbar button.ann-save:disabled { opacity: 0.5; cursor: default; }
.ann-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #16181d; }
.ann-canvas { display: block; touch-action: none; cursor: crosshair; }
.ann-canvas[data-tool="pan"], .ann-canvas.panning { cursor: grab; }
.ann-canvas[data-tool="text"] { cursor: text; }
.ann-canvas[data-tool="select"] { cursor: default; }
.ann-canvas[data-tool="sticker"] { cursor: copy; }
.ann-canvas[data-tool="eraser"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Ccircle cx='12' cy='12' r='9' fill='rgba(255,255,255,0.35)' stroke='%23111' stroke-width='1.5'/%3E%3C/svg%3E") 12 12, crosshair; }
.ann-stickers { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; width: max-content; max-width: min(calc(100% - 20px), 440px); padding: 4px; border-radius: 12px; background: rgba(243, 244, 246, 0.97); border: 1px solid #d1d5db; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); z-index: 1; }
.ann-stickers[hidden] { display: none; }
.ann-dialog .ann-stickers button.ann-sticker { width: 46px; height: 46px; margin: 0; padding: 0; border: 1px solid transparent; border-radius: 8px; background: transparent; font-size: 30px; line-height: 1; cursor: pointer; box-shadow: none; }
.ann-dialog .ann-stickers button.ann-sticker:hover { background: #e5e7eb; }
.ann-dialog .ann-stickers button.ann-sticker.active { background: #fff; border-color: var(--accent); }
.ann-tool .ann-tool-emoji { font-size: 22px; line-height: 1; }
.ann-canvas[data-tool="select"].over-mark { cursor: move; }
.ann-canvas.over-handle { cursor: nwse-resize; }
.ann-dialog .ann-toolbar button[hidden] { display: none; }
.ann-dialog .ann-toolbar button.ann-delete:disabled { opacity: 0.4; cursor: default; background: transparent; }
.ann-dialog .ann-text-input { position: absolute; min-width: 160px; width: auto; margin: 0; padding: 2px 4px; border: 1px dashed currentColor; border-radius: 4px; background: rgba(255, 255, 255, 0.9); font-weight: 600; line-height: 1.2; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; outline: none; }
.ann-status { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); padding: 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 0.9rem; pointer-events: none; }
.ann-status[hidden] { display: none; }
dialog.ann-dialog form.ann-footer { display: flex; flex-direction: row; align-items: center; margin: 0; gap: 10px 16px; flex-wrap: wrap; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #2a2d36; border-top: 1px solid #3a3e4a; }
.ann-dialog .ann-footer textarea { flex: 1 1 280px; min-width: 0; margin: 0; padding: 8px 10px; border: 1px solid #4b5060; border-radius: 8px; background: #1f2128; color: #f3f4f6; font: inherit; font-size: 16px; resize: none; }
.ann-dialog .ann-footer .hw-check { color: #e5e7eb; margin: 0; }

@media (max-width: 640px) {
  .hw-entry-teacher { margin-left: 8px; }
  .hw-actions .hw-btn, .hw-actions form { width: 100%; }
  .hw-actions form .hw-btn { width: 100%; justify-content: center; }
  .hw-actions > .hw-btn { justify-content: center; }
  .hw-subtab { padding: 8px 10px; font-size: 0.9rem; }
  .hw-tpl-toolbar button { width: 100%; }
  .att-img img { max-width: 100%; max-height: 220px; }
  .ann-toolbar { gap: 4px 8px; padding: 6px 8px; }
  .ann-dialog .ann-toolbar button { width: 34px; height: 34px; }
  .ann-dialog .ann-toolbar button.ann-save { height: 34px; padding: 0 12px; }
}
