:root {
  --ink: #132333;
  --muted: #5d6b78;
  --paper: #f4f6f8;
  --surface: #ffffff;
  --navy: #14283d;
  --navy-2: #213b55;
  --amber: #f0a62b;
  --amber-soft: #fff4da;
  --green: #1f7554;
  --green-soft: #e5f4ed;
  --yellow: #8b6411;
  --yellow-soft: #fff4d3;
  --red: #a53b37;
  --red-soft: #fbe9e7;
  --blue-soft: #e8f0f7;
  --line: #dce2e7;
  --shadow: 0 10px 28px rgba(20, 40, 61, .08);
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button, select, input[type="date"], input[type="search"] { min-height: 44px; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid #2b7bbc; outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.15; letter-spacing: -.025em; }
h2 { margin-bottom: .45rem; font-size: 1.35rem; }
h3 { margin-bottom: .35rem; font-size: 1.05rem; }
small, .muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 99; background: white; color: var(--ink); padding: .75rem 1rem; border-radius: 8px; }
.skip-link:focus { top: 1rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.3rem 1rem; background: var(--navy); color: white; display: flex; flex-direction: column; z-index: 5; }
.brand { display: flex; align-items: center; padding: .35rem .35rem 1.55rem; }
.brand-logo { display: block; width: 100%; max-width: 192px; height: auto; }
.brand-symbol { display: none; width: 46px; height: 46px; object-fit: contain; }
.sidebar nav { display: grid; gap: .35rem; }
.nav-item { width: 100%; padding: .7rem .75rem; border: 0; border-radius: 9px; display: grid; grid-template-columns: 32px 1fr; align-items: center; text-align: left; color: #dce6ef; background: transparent; font-weight: 650; }
.nav-item span { color: #9fb1c1; font-weight: 800; }
.nav-item:hover { background: rgba(255,255,255,.07); color: white; }
.nav-item.is-active { background: white; color: var(--navy); }
.nav-item.is-active span { color: var(--amber); }
.privacy-note { margin-top: auto; padding: .75rem; border-top: 1px solid rgba(255,255,255,.14); color: #bfccd7; font-size: .78rem; }
.privacy-note span { color: #64c293; margin-right: .3rem; }

.workspace { min-width: 0; }
.topbar { min-height: 82px; padding: .8rem clamp(1rem, 3vw, 2.2rem); display: flex; gap: .8rem; align-items: end; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 4; }
.topbar label { display: grid; gap: .25rem; color: var(--muted); font-size: .74rem; font-weight: 700; }
.topbar input, .topbar select { border: 1px solid var(--line); border-radius: 8px; background: white; padding: .55rem .7rem; color: var(--ink); }
.date-control input { width: 158px; }
.search-control { flex: 1; min-width: 180px; }
.search-control input { width: 100%; }
.context-selects { display: flex; gap: .55rem; }
.save-state { min-width: 84px; align-self: center; color: var(--green); font-size: .78rem; font-weight: 700; }
main { padding: 1.5rem clamp(1rem, 3vw, 2.2rem) 3rem; max-width: 1500px; }

.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: end; margin-bottom: 1.25rem; }
.page-head p { margin: .25rem 0 0; color: var(--muted); max-width: 760px; }
.page-actions, .inline-actions { display: flex; flex-wrap: wrap; gap: .55rem; }
.eyebrow { display: block; margin-bottom: .25rem; color: #52687b; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.button { border: 1px solid transparent; border-radius: 9px; padding: .65rem .9rem; background: var(--navy); color: white; font-weight: 750; line-height: 1; }
.button:hover { background: var(--navy-2); }
.button.secondary { color: var(--ink); background: white; border-color: var(--line); }
.button.secondary:hover { background: #edf2f6; }
.button.accent { color: #392609; background: var(--amber); }
.button.danger { background: var(--red); }
.button.small { min-height: 36px; padding: .45rem .65rem; font-size: .82rem; }
.button:disabled, .icon-button:disabled { opacity: .45; cursor: not-allowed; }
.icon-button { min-width: 42px; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--ink); font-size: 1.3rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--navy); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.kpi.attention { border-top-color: var(--amber); }
.kpi strong { display: block; margin-top: .35rem; font-size: 2rem; line-height: 1; }
.kpi span { color: var(--muted); font-size: .85rem; font-weight: 650; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .75fr); gap: 1rem; }
.stack { display: grid; gap: 1rem; align-content: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; gap: 1rem; align-items: start; justify-content: space-between; margin-bottom: .8rem; }
.card-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.timeline { display: grid; gap: .55rem; }
.timeline-item { display: grid; grid-template-columns: 82px 4px 1fr auto; gap: .75rem; align-items: center; min-height: 58px; padding: .55rem .6rem; border-radius: 9px; background: #f7f9fb; }
.timeline-rail { width: 4px; height: 38px; border-radius: 5px; background: var(--amber); }
.timeline-item strong { display: block; }
.timeline-item small { display: block; margin-top: .15rem; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.quick-grid .button { min-height: 56px; text-align: left; }

.status { display: inline-flex; align-items: center; gap: .35rem; min-height: 28px; padding: .25rem .55rem; border-radius: 999px; font-size: .77rem; font-weight: 800; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.ok { color: var(--green); background: var(--green-soft); }
.status.warn { color: var(--yellow); background: var(--yellow-soft); }
.status.bad { color: var(--red); background: var(--red-soft); }
.status.neutral { color: #49677e; background: var(--blue-soft); }

.table-tools { display: flex; flex-wrap: wrap; gap: .65rem; align-items: end; margin-bottom: .8rem; }
.field { display: grid; gap: .3rem; min-width: 150px; }
.field > span, .field > label { color: var(--muted); font-size: .78rem; font-weight: 750; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: .58rem .65rem; color: var(--ink); background: white; border: 1px solid #cbd4dc; border-radius: 8px; }
.field textarea { min-height: 80px; resize: vertical; }
.check-field { display: flex; gap: .55rem; align-items: center; min-height: 44px; }
.check-field input { width: 20px; height: 20px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.field-grid .wide { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: white; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .72rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f2f5f7; color: #465a6c; font-size: .75rem; letter-spacing: .025em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
td .subline { display: block; color: var(--muted); font-size: .77rem; margin-top: .1rem; }
.row-actions { display: flex; justify-content: flex-end; gap: .35rem; }
.text-button { border: 0; background: transparent; color: #195a86; font-weight: 750; padding: .35rem; }
.text-button.danger-text { color: var(--red); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: .3rem; }
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .9rem; }
.class-card { border-top: 5px solid var(--navy); }
.class-card .class-name { font-size: 1.5rem; font-weight: 850; }
.class-card .class-meta { margin: .6rem 0 .9rem; display: grid; gap: .35rem; color: var(--muted); font-size: .86rem; }
.class-card .stat-row { display: flex; gap: .55rem; margin: .7rem 0; }
.mini-stat { flex: 1; padding: .55rem; background: #f4f7f9; border-radius: 8px; }
.mini-stat strong, .mini-stat span { display: block; }
.mini-stat span { margin-top: .15rem; color: var(--muted); font-size: .72rem; }
.progress { height: 10px; margin: .45rem 0; overflow: hidden; background: #e6ebef; border-radius: 99px; }
.progress > span { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.calculation { max-width: 440px; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.summary-note { padding: .75rem; border-left: 4px solid var(--amber); background: var(--amber-soft); border-radius: 0 8px 8px 0; }
.list { display: grid; gap: .5rem; }
.list-item { padding: .75rem; border: 1px solid var(--line); border-radius: 9px; display: flex; gap: 1rem; justify-content: space-between; align-items: center; }
.list-item strong { display: block; }
.list-item small { display: block; margin-top: .2rem; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.info-block { padding: .85rem; background: #f5f8fa; border-radius: 9px; }
.info-block ul { margin: .5rem 0 0; padding-left: 1.2rem; }
.info-block li + li { margin-top: .35rem; }

dialog { width: min(720px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: 14px; box-shadow: 0 24px 60px rgba(7, 20, 32, .26); }
dialog::backdrop { background: rgba(7, 20, 32, .58); }
.dialog-card { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.dialog-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; padding: 1.1rem 1.2rem .85rem; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.dialog-body { overflow: auto; padding: 1.1rem 1.2rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .55rem; padding: .85rem 1.2rem 1.1rem; border-top: 1px solid var(--line); }
.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.preview-table { margin-top: 1rem; max-height: 220px; overflow: auto; }
.callout { padding: .8rem; border: 1px solid #e8d18a; border-radius: 8px; background: var(--yellow-soft); color: #62490d; }
.connection-card { border-left: 5px solid var(--navy); }
.connection-card.is-connected { border-left-color: var(--green); }
.connection-meta { display: flex; flex-wrap: wrap; gap: .45rem 1rem; margin-top: .7rem; color: var(--muted); font-size: .85rem; }
.class-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; max-height: 320px; overflow: auto; padding: .25rem; }
.class-check { display: flex; gap: .55rem; align-items: center; min-height: 44px; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; }
.class-check input { width: 20px; height: 20px; }
.lesson-list { display: grid; gap: .65rem; }
.lesson-row { display: grid; grid-template-columns: 112px minmax(100px, .55fr) minmax(180px, 1.4fr) minmax(130px, 1fr) auto; gap: .8rem; align-items: center; padding: .8rem; border: 1px solid var(--line); border-left: 4px solid var(--navy); border-radius: 9px; background: white; }
.lesson-row.is-cancelled { border-left-color: var(--red); background: var(--red-soft); }
.lesson-time { font-variant-numeric: tabular-nums; font-weight: 850; }
.lesson-main strong, .lesson-main small { display: block; }
.lesson-main small { margin-top: .2rem; color: var(--muted); }
.sync-range { display: grid; grid-template-columns: repeat(2, minmax(150px, 220px)); gap: .65rem; margin-top: 1rem; }
.toast { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 30; max-width: 360px; transform: translateY(30px); opacity: 0; pointer-events: none; padding: .8rem 1rem; color: white; background: var(--navy); border-radius: 9px; box-shadow: var(--shadow); transition: .18s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.readonly-banner { margin-bottom: 1rem; padding: .7rem .85rem; border-radius: 9px; color: #4b3a0b; background: var(--yellow-soft); border: 1px solid #ebd38d; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 92px minmax(0, 1fr); }
  .sidebar { padding-inline: .65rem; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand-logo { display: none; }
  .brand-symbol { display: block; }
  .privacy-note { display: none; }
  .nav-item { grid-template-columns: 1fr; gap: .15rem; justify-items: center; text-align: center; padding: .55rem .25rem; font-size: .72rem; }
  .nav-item span { font-size: 1rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; top: 0; width: 100%; height: auto; padding: .55rem .7rem; flex-direction: row; align-items: center; overflow-x: auto; }
  .brand { padding: 0 .35rem 0 0; }
  .brand-symbol { width: 42px; height: 42px; }
  .sidebar nav { display: flex; gap: .3rem; }
  .nav-item { min-width: 74px; }
  .topbar { position: static; flex-wrap: wrap; align-items: end; padding: .75rem 1rem; }
  .search-control { order: 4; flex-basis: 100%; }
  .save-state { display: none; }
  .context-selects { margin-left: auto; }
  .context-selects label:first-child { display: none; }
  main { padding-top: 1rem; }
  .page-head { align-items: start; flex-direction: column; }
  .card-head { align-items: flex-start; flex-direction: column; }
  .card-head > .button, .card-head > .text-button, .card-head > .status { align-self: flex-start; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi strong { font-size: 1.55rem; }
  .timeline-item { grid-template-columns: 70px 4px 1fr; }
  .timeline-item .status { grid-column: 3; justify-self: start; }
  .field-grid, .mapping-grid, .info-grid { grid-template-columns: 1fr; }
  .class-picker, .sync-range { grid-template-columns: 1fr; }
  .lesson-row { grid-template-columns: 86px 1fr auto; align-items: start; }
  .lesson-row .lesson-main { grid-column: 1 / -1; }
  .field-grid .wide { grid-column: auto; }
}

@media print {
  body { background: white; }
  .sidebar, .topbar, .page-actions, .table-tools, .row-actions, .button, .readonly-banner { display: none !important; }
  .app-shell { display: block; }
  main { max-width: none; padding: 0; }
  .card, .table-wrap { border: 0; box-shadow: none; padding: 0; }
  th, td { padding: .42rem; font-size: 10pt; }
  h1 { font-size: 18pt; }
  .page-head { margin-bottom: .5rem; }
  @page { margin: 1.2cm; size: A4 landscape; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
