/* =============================================================================
 * app.css — the editor UI around the sheet.
 * Deliberately always-light: the sheet preview must render exactly as it
 * prints, and a dark app frame around a light page reads badly.
 * ========================================================================== */


:root {
  --font-ui:      'Nunito Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Poppins', 'Nunito Sans', system-ui, sans-serif;

  --bg:        #f4f6f2;
  --surface:   #ffffff;
  --surface-2: #fafbf8;
  --line:      #e2e7dd;
  --line-2:    #cfd8c8;

  --ink:       #1d2419;
  --ink-2:     #56604f;
  --ink-3:     #86917f;

  --accent:      #3f7a31;
  --accent-ink:  #2c5822;
  --accent-soft: #eaf3e4;
  --accent-line: #b9d6a8;

  --gold:      #c98a10;
  --gold-soft: #fdf3dd;
  --danger:      #b3402e;
  --danger-soft: #fceeeb;
  --info-soft:   #eaf0fa;
  --info-ink:    #2f558f;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(20,35,15,.05), 0 2px 8px rgba(20,35,15,.05);
  --shadow-lg: 0 8px 32px rgba(20,35,15,.14);

  --topbar-h: 58px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.25; }
a { color: var(--accent-ink); }

.ic { width: 17px; height: 17px; flex: 0 0 auto; fill: none; stroke: currentColor;
      stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.ic-fill { fill: currentColor; stroke: none; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: 0 0 auto; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center;
              border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--font-display); font-size: 15px; font-weight: 700; }
.brand-text small { font-size: 11.5px; color: var(--ink-3); }

.topbar-nav { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

.crumb { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crumb-sep { color: var(--ink-3); }
.crumb-title { font-family: var(--font-display); font-weight: 600; font-size: 14px;
               white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
          background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 800;
          font-family: var(--font-display); flex: 0 0 auto; }

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-family: var(--font-ui); font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--ink-3); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); }
.btn-ghost.is-active { background: var(--accent-soft); color: var(--accent-ink); }

.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: transparent; }

.btn-sm { padding: 5px 10px; font-size: 13px; gap: 5px; }
.btn-icon { padding: 7px; }
.btn-block { width: 100%; justify-content: center; }
.who .avatar { margin-right: 1px; }

/* -------------------------------------------------------------- app layout */

.app { max-width: 1240px; margin: 0 auto; padding: 26px 18px 80px; }
.app.app-wide { max-width: 1560px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head-text { flex: 1; min-width: 260px; }
.page-head h1 { font-size: 25px; font-weight: 700; letter-spacing: -.02em; }
.page-head p { margin: 5px 0 0; color: var(--ink-2); font-size: 14.5px; max-width: 66ch; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.section-title { font-family: var(--font-display); font-size: 12px; font-weight: 700;
                 text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 10px; }

.card-surface { background: var(--surface); border: 1px solid var(--line);
                border-radius: var(--radius); box-shadow: var(--shadow); }

/* ------------------------------------------------------------------- tabs */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line);
        margin-bottom: 22px; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 14px; border: 0; background: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 14px; font-weight: 600; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tab .pill { margin-left: 2px; }

/* ------------------------------------------------------------------ pills */

.pill { display: inline-flex; align-items: center; gap: 4px;
        padding: 2px 8px; border-radius: 999px;
        font-size: 11.5px; font-weight: 700; font-family: var(--font-display);
        background: var(--accent-soft); color: var(--accent-ink); }
.pill-warn   { background: var(--gold-soft);   color: var(--gold); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-mute   { background: #eef0ec;            color: var(--ink-2); }
.pill-info   { background: var(--info-soft);   color: var(--info-ink); }

/* --------------------------------------------------------- sheets (home) */

.sheet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px; }

.sheet-card { display: flex; flex-direction: column; padding: 18px; gap: 14px; text-align: left; }
.sheet-card-top { display: flex; align-items: flex-start; gap: 14px; }
.sheet-card-title { flex: 1; min-width: 0; }
.sheet-card-title h3 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.sheet-card-title .sub { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.sheet-card-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet-card-actions { display: flex; gap: 6px; flex-wrap: wrap;
                      border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; }

.ring { --pct: 0; width: 46px; height: 46px; flex: 0 0 auto; position: relative;
        border-radius: 50%;
        background: conic-gradient(var(--accent) calc(var(--pct) * 1%), var(--line) 0); }
.ring::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--surface); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1;
             font-family: var(--font-display); font-size: 11.5px; font-weight: 700; color: var(--accent-ink); }
.ring.is-done { --pct: 100; }

/* ------------------------------------------------------------- write view */

.write-layout { display: grid; grid-template-columns: 268px 1fr; gap: 22px; align-items: start; }
.write-side { position: sticky; top: calc(var(--topbar-h) + 18px); display: flex; flex-direction: column; gap: 14px; }

.subject-pick { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.subject-list { display: flex; flex-direction: column; gap: 3px; }
.subject-btn {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 10px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: none; cursor: pointer; text-align: left;
  font-family: var(--font-ui); font-size: 14px; color: var(--ink);
}
.subject-btn:hover { background: var(--surface-2); }
.subject-btn.is-active { background: var(--accent-soft); border-color: var(--accent-line); font-weight: 700; color: var(--accent-ink); }
.subject-btn-body { flex: 1; min-width: 0; }
.subject-btn-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject-btn-sub { display: block; font-size: 11.5px; color: var(--ink-3); font-weight: 400; }

.student-rows { display: flex; flex-direction: column; gap: 12px; }

.student-row { padding: 0; overflow: hidden; }
.student-row-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.student-row-head h3 { font-size: 15px; font-weight: 700; flex: 1; min-width: 0; }
.student-row-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }

.field { display: flex; flex-direction: column; padding: 13px 16px 11px; }
.field + .field { border-left: 1px solid var(--line); }
.field-head { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.field-label { font-family: var(--font-display); font-size: 12.5px; font-weight: 700;
               text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.field-count { margin-left: auto; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.field-count.is-over { color: var(--gold); font-weight: 700; }

textarea.gg-input, input.gg-input, select.gg-input {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-family: var(--font-ui); font-size: 14px; line-height: 1.45;
  resize: vertical;
}
textarea.gg-input { min-height: 96px; }
.gg-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.gg-input::placeholder { color: var(--ink-3); }

label.lbl { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 5px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 180px; }
.field-hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }

.lint-note { display: flex; align-items: flex-start; gap: 7px; margin-top: 7px;
             padding: 7px 9px; border-radius: var(--radius-sm);
             background: var(--gold-soft); color: #7a5405; font-size: 12.5px; }
.lint-note .ic { width: 15px; height: 15px; margin-top: 1px; }

/* ---------------------------------------------------------- overview grid */

.matrix-wrap { overflow-x: auto; border-radius: var(--radius); }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; background: var(--surface); }
table.matrix th, table.matrix td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.matrix thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2);
                        font-family: var(--font-display); font-size: 12px; font-weight: 700;
                        text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); white-space: nowrap; }
table.matrix tbody th { font-weight: 600; white-space: nowrap; position: sticky; left: 0;
                        background: var(--surface); z-index: 1; }
table.matrix tbody tr:hover th, table.matrix tbody tr:hover td { background: var(--surface-2); }
table.matrix td.cell { text-align: center; width: 92px; }

.dot { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 7px;
       background: #eef0ec; color: var(--ink-3); }
.dot .ic { width: 13px; height: 13px; stroke-width: 2.6; }
.dot-full { background: var(--accent-soft); color: var(--accent); }
.dot-half { background: var(--gold-soft);  color: var(--gold); }
.dot-conflict { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------------ roster view */

.list-rows { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row.is-muted { opacity: .55; }
.list-row-main { flex: 1; min-width: 0; }
.list-row-main strong { font-weight: 600; }
.list-row-sub { font-size: 12.5px; color: var(--ink-3); }
.list-row-actions { display: flex; gap: 4px; }
.drag-handle { color: var(--ink-3); cursor: grab; }
.list-row.is-dragging { opacity: .4; }
.list-row.is-drop-target { box-shadow: inset 0 2px 0 var(--accent); }

/* --------------------------------------------------------- preview layout */

.preview-layout { display: grid; grid-template-columns: 276px 1fr; gap: 22px; align-items: start; }
.preview-side { position: sticky; top: calc(var(--topbar-h) + 18px); display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - var(--topbar-h) - 40px); }
.preview-side-scroll { overflow-y: auto; }
.preview-docs { display: flex; flex-direction: column; gap: 22px; align-items: center; }
.preview-item { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.preview-caption { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }

.check-row { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.check-row:hover { background: var(--surface-2); }
.check-row input { accent-color: var(--accent); width: 15px; height: 15px; flex: 0 0 auto; }
.check-row span { flex: 1; min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.print-tips { padding: 14px; background: var(--info-soft); border: 1px solid #ccd9ee; border-radius: var(--radius); }
.print-tips h4 { font-size: 13px; color: var(--info-ink); margin-bottom: 7px; }
.print-tips dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; }
.print-tips dt { color: var(--ink-2); }
.print-tips dd { margin: 0; font-weight: 700; color: var(--info-ink); }

/* ------------------------------------------------------- empty / callouts */

.empty { text-align: center; padding: 56px 24px; }
.empty-icon { width: 46px; height: 46px; margin: 0 auto 14px; display: grid; place-items: center;
              border-radius: 14px; background: var(--accent-soft); color: var(--accent); }
.empty-icon .ic { width: 24px; height: 24px; }
.empty h3 { font-size: 18px; margin-bottom: 6px; }
.empty p { color: var(--ink-2); max-width: 46ch; margin: 0 auto 18px; }

.callout { display: flex; gap: 11px; padding: 13px 15px; border-radius: var(--radius); font-size: 13.5px; }
.callout .ic { margin-top: 1px; }
.callout-warn   { background: var(--gold-soft);   color: #7a5405; }
.callout-danger { background: var(--danger-soft); color: var(--danger); }
.callout-info   { background: var(--info-soft);   color: var(--info-ink); }
.callout-ok     { background: var(--accent-soft); color: var(--accent-ink); }
.callout strong { font-weight: 800; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 9px; }
.row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.row-end { margin-left: auto; }
.pad { padding: 18px; }
.muted { color: var(--ink-3); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ------------------------------------------------------------------ modal */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(24,33,20,.42);
  display: grid; place-items: center; padding: 24px;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(620px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
}
.modal-wide { width: min(880px, 100%); }
.modal-head { padding: 20px 22px 0; }
.modal-head h2 { font-size: 19px; font-weight: 700; }
.modal-head p { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; }
.modal-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 15px; }
.modal-foot { padding: 14px 22px 20px; display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot .row-start { margin-right: auto; }

/* ------------------------------------------------------------------ toast */

.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 200;
              display: flex; flex-direction: column; gap: 9px; align-items: flex-end; }
.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 15px; border-radius: var(--radius);
  background: #24301f; color: #f2f6ef; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg); max-width: 400px;
  animation: toast-in .18s ease-out;
}
.toast-err { background: var(--danger); }
.toast-ok  { background: var(--accent-ink); }
.toast .ic { margin-top: 1px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.save-state { font-size: 12.5px; color: var(--ink-3); display: flex; align-items: center; gap: 5px; }
.save-state.is-saving { color: var(--accent); }
.save-state.is-error  { color: var(--danger); font-weight: 700; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .write-layout, .preview-layout { grid-template-columns: 1fr; }
  .write-side, .preview-side { position: static; max-height: none; }
}
@media (max-width: 720px) {
  .student-row-body { grid-template-columns: 1fr; }
  .field + .field { border-left: 0; border-top: 1px solid var(--line); }
  .app { padding: 18px 13px 60px; }
  .brand-text small { display: none; }
  .btn span.btn-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
