/* Course manager admin UI. Neutral, light, keyboard friendly. */
:root {
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #1f2933;
  --color-muted: #5f6b7a;
  --color-border: #d9dee5;
  --color-primary: #1f5fa8;
  --color-primary-dark: #174a84;
  --color-danger: #b42318;
  --color-warn: #b7791f;
  --color-ok: #1e7f4f;
  --color-focus: #ffbf47;
  --radius: 6px;
  --sidenav-width: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 16px; color: var(--color-text); background: var(--color-bg); }
body { margin: 0; line-height: 1.45; }
a { color: var(--color-primary); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--color-focus); outline-offset: 2px;
}
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
code { font-size: .9em; background: #eef1f4; padding: .1em .3em; border-radius: 3px; }
.muted { color: var(--color-muted); }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--color-surface); padding: .5rem; }
.skip-link:focus { left: .5rem; z-index: 100; }

/* layout */
.layout { display: grid; grid-template-columns: var(--sidenav-width) 1fr; grid-template-rows: 52px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; padding: 0 1rem; background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.brand { font-weight: 600; text-decoration: none; color: var(--color-text); }
.brand--center { text-align: center; display: block; margin: 0 0 1rem; color: var(--color-muted); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.user-name { font-weight: 500; }
.nav-toggle { display: none; }
.sidenav { background: var(--color-surface); border-right: 1px solid var(--color-border); padding: 1rem 0; }
.sidenav ul { list-style: none; margin: 0; padding: 0; }
.sidenav a { display: block; padding: .5rem 1.25rem; color: var(--color-text); text-decoration: none; }
.sidenav a:hover { background: #eef2f7; }
.sidenav a[aria-current="page"] { background: #e3ecf7; border-right: 3px solid var(--color-primary); font-weight: 600; }
.nav-group { margin: 1.25rem 1.25rem .25rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); }
.nav-version { margin: 1.5rem 1.25rem 0; font-size: .75rem; color: var(--color-muted); }
.main { padding: 1.25rem 1.5rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 0 0 1rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .9rem; color: var(--color-muted); margin-bottom: .5rem; }

.minimal { display: flex; align-items: flex-start; justify-content: center; padding: 3rem 1rem; }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; }
.card--center { width: 100%; max-width: 520px; }
.card--inner { margin: 0 0 1rem; }
fieldset.card--inner { border: 1px solid var(--color-border); }
legend { font-weight: 600; padding: 0 .4rem; }
.grid { display: grid; gap: 1rem; }
.grid--two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

/* forms */
.field { margin: 0 0 1rem; }
.field label { display: block; font-weight: 500; margin-bottom: .3rem; }
.field--checkbox label, .field--radio label { display: inline-flex; align-items: center; gap: .4rem; font-weight: 400; margin-right: 1rem; }
.field--radio { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid #9aa5b1; border-radius: var(--radius); font: inherit; background: #fff; color: var(--color-text);
}
textarea { min-height: 6rem; resize: vertical; }
.input--short { width: 6rem; }
.inline-fields { display: inline-flex; gap: .4rem; align-items: center; }
.inline-fields select { width: auto; }
.req { color: var(--color-danger); }
.field--error input, .field--error select, .field--error textarea { border-color: var(--color-danger); }
.field-error { color: var(--color-danger); margin: .3rem 0 0; font-size: .9rem; }
.field-help { color: var(--color-muted); margin: .3rem 0 0; font-size: .85rem; }
.password-wrap { display: flex; gap: .4rem; }
.readonly { margin: 0; padding: .5rem 0; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }
.form-actions .btn:first-child:not(.btn--primary) { margin-right: auto; }
form.inline { display: inline; }

.btn { display: inline-block; padding: .5rem .9rem; border: 1px solid #9aa5b1; border-radius: var(--radius); background: #fff; color: var(--color-text); font: inherit; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f0f3f6; }
.btn--primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn--primary:hover { background: var(--color-primary-dark); }
.btn--danger { background: #fff; border-color: var(--color-danger); color: var(--color-danger); }
.btn--danger:hover { background: #fdf2f1; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--small { padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }
.linklike { background: none; border: 0; padding: 0; color: var(--color-primary); font: inherit; cursor: pointer; text-decoration: underline; }

.menu summary { cursor: pointer; list-style: none; padding: .3rem .6rem; border: 1px solid var(--color-border); border-radius: var(--radius); }
.menu summary::-webkit-details-marker { display: none; }
.menu { position: relative; }
.menu-items { position: absolute; right: 0; top: 2.2rem; background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius); min-width: 180px; padding: .4rem 0; z-index: 20; box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.menu-items a, .menu-items button { display: block; width: 100%; text-align: left; padding: .45rem .9rem; color: var(--color-text); text-decoration: none; }
.menu-items a:hover, .menu-items button:hover { background: #eef2f7; }

/* feedback */
.flashes { margin: 0 0 1rem; }
.flash { padding: .6rem .9rem; border-radius: var(--radius); border: 1px solid; margin-bottom: .5rem; }
.flash--success { background: #e8f5ee; border-color: #9ad2b3; color: #155b3a; }
.flash--error { background: #fdecea; border-color: #f0a9a2; color: #7a1c15; }
.flash--warning { background: #fff5e5; border-color: #f2cf8a; color: #6b4300; }
.flash--info { background: #e8f0fa; border-color: #a9c4e8; color: #1c3d66; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; background: #e6e9ee; color: var(--color-text); }
.badge--ok { background: #d9f1e3; color: #155b3a; }
.badge--warn { background: #fdebc8; color: #6b4300; }
.badge--error { background: #fde0dc; color: #7a1c15; }
.badge--role { background: #e3ecf7; color: var(--color-primary-dark); }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--color-muted); background: var(--color-surface); border: 1px dashed var(--color-border); border-radius: var(--radius); }
.status-list { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.25rem; margin: 0 0 1rem; }
.status-list dt { color: var(--color-muted); }
.status-list dd { margin: 0; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: .3rem 0; }
.plain-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.plain-list li { padding: .35rem 0; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.step-indicator { color: var(--color-muted); margin: .25rem 0 1.25rem; font-size: .9rem; }

/* tables */
.filterbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: 0 0 1rem; }
.filterbar input, .filterbar select { width: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
.table th, .table td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.table th { background: #f0f3f6; font-weight: 600; font-size: .9rem; }
.table tbody tr:hover { background: #f7f9fb; }
.col-actions { text-align: right; white-space: nowrap; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--color-border); margin: 0 0 1rem; }
.tabs a { padding: .5rem .8rem; text-decoration: none; color: var(--color-text); border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { border-bottom-color: var(--color-primary); font-weight: 600; }

.toast-region { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: #1f2933; color: #fff; padding: .6rem .9rem; border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast--error { background: var(--color-danger); }

dialog { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 0; max-width: min(720px, 95vw); width: 100%; }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); font-weight: 600; }
.dialog-body { padding: 1rem 1.25rem; max-height: 70vh; overflow: auto; }
.dialog-foot { padding: .75rem 1.25rem; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: .5rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-block; }
  .sidenav { display: none; grid-column: 1; border-right: 0; border-bottom: 1px solid var(--color-border); }
  .sidenav.is-open { display: block; }
  .main { padding: 1rem; }
  .user-name { display: none; }
  dialog { max-width: 100vw; height: 100vh; max-height: 100vh; }
}
@media print {
  .topbar, .sidenav, .page-actions, .filterbar, .form-actions, .toast-region { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
}
.preview { white-space: pre-wrap; background: #f7f9fb; border: 1px solid var(--color-border); border-radius: var(--radius); padding: .75rem; font: inherit; font-size: .95rem; }

/* --- P04: calendar, course editor, occurrence page --- */
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 0 0 .75rem; }
.cal-nav { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.cal-nav input[type="date"] { width: auto; padding: .3rem .4rem; }
.cal-title { margin-left: .5rem; }
.segmented { display: inline-flex; border: 1px solid #9aa5b1; border-radius: var(--radius); overflow: hidden; }
.segmented a { padding: .35rem .8rem; text-decoration: none; color: var(--color-text); border-right: 1px solid #d9dee5; }
.segmented a:last-child { border-right: 0; }
.segmented a[aria-current="page"] { background: var(--color-primary); color: #fff; }
.checkbox-inline { display: inline-flex; align-items: center; gap: .35rem; }
.filterbar select[multiple] { min-width: 10rem; height: auto; }
.timegrid { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow-x: auto; }
.timegrid-head, .timegrid-body { display: grid; grid-template-columns: 56px repeat(var(--cols, 7), minmax(110px, 1fr)); }
.timegrid--day .timegrid-head, .timegrid--day .timegrid-body { grid-template-columns: 56px 1fr; }
.timegrid-head { border-bottom: 1px solid var(--color-border); position: sticky; top: 0; background: var(--color-surface); z-index: 2; }
.timegrid-daylabel { padding: .4rem; text-align: center; font-weight: 600; font-size: .9rem; border-left: 1px solid var(--color-border); }
.timegrid-daylabel a { color: inherit; text-decoration: none; }
.timegrid-daylabel.is-today { background: #e3ecf7; }
.timegrid-gutter { font-size: .75rem; color: var(--color-muted); }
.timegrid-hour { height: 60px; padding: 0 .3rem; text-align: right; transform: translateY(-.5em); }
.timegrid-col { position: relative; border-left: 1px solid var(--color-border); }
.timegrid-col.is-today { background: #f7f9fc; }
.timegrid-line { position: absolute; left: 0; right: 0; border-top: 1px solid #eef1f4; }
.cal-entry { position: absolute; display: flex; flex-direction: column; gap: .05rem; padding: .2rem .35rem; margin: 1px; border-radius: 4px; font-size: .78rem; line-height: 1.2; text-decoration: none; color: #1c3d66; background: #e3ecf7; border-left: 3px solid var(--color-primary); overflow: hidden; }
.cal-entry:hover, .cal-entry:focus { z-index: 3; outline: 2px solid var(--color-primary); }
.cal-entry--completed { background: #eef1f4; border-left-color: #8a96a3; color: #4b5563; }
.cal-entry--cancelled { background: #f7f7f7; border-left-color: #c0c7cf; color: #6b7280; text-decoration: line-through; }
.cal-entry--overbooked { border-left-color: var(--color-warn); }
.cal-entry-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-entry-meta { color: inherit; opacity: .85; }
.monthgrid { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
.monthgrid-head, .monthgrid-week { display: grid; grid-template-columns: repeat(7, 1fr); }
.monthgrid-head div { padding: .4rem; text-align: center; font-weight: 600; font-size: .85rem; border-bottom: 1px solid var(--color-border); }
.monthgrid-day { min-height: 110px; padding: .3rem; border-right: 1px solid #eef1f4; border-bottom: 1px solid #eef1f4; display: flex; flex-direction: column; gap: .15rem; }
.monthgrid-day.is-outside { background: #fafbfc; color: var(--color-muted); }
.monthgrid-day.is-today { background: #f3f7fc; }
.monthgrid-daynum { align-self: flex-end; font-size: .8rem; text-decoration: none; color: inherit; padding: .1rem .3rem; }
.month-entry { display: block; font-size: .72rem; padding: .1rem .3rem; border-radius: 3px; background: #e3ecf7; color: #1c3d66; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--color-primary); }
.month-more { font-size: .72rem; color: var(--color-muted); }
.table-group td { background: #f0f3f6; font-weight: 600; }
tr.is-cancelled td { color: var(--color-muted); text-decoration: line-through; }
tr.is-cancelled td a, tr.is-cancelled td .btn { text-decoration: none; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin: 0 0 1rem; }
.kpi { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: .75rem 1rem; }
.kpi-value { display: block; font-size: 1.6rem; font-weight: 600; }
.kpi-label { color: var(--color-muted); font-size: .85rem; }
.grid--two-wide { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin: 0 0 .75rem; }
.section-head h2 { margin: 0; }
.rule-cards { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.rule-card { border: 1px solid var(--color-border); border-radius: var(--radius); padding: .75rem; display: flex; flex-direction: column; gap: .3rem; }
.rule-card.is-disabled { opacity: .7; }
.rule-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .6rem; border: 1px solid var(--color-border); border-radius: 999px; font-size: .85rem; background: #fff; }
.chip--link { text-decoration: none; color: var(--color-primary); }
.chip--muted { color: var(--color-muted); background: #f3f4f6; }
.label-like { display: block; font-weight: 500; margin-bottom: .3rem; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
.form-actions--top { margin: 0 0 1rem; }
.menu-note { display: block; padding: .45rem .9rem; font-size: .85rem; }
.table--compact th, .table--compact td { padding: .3rem .5rem; font-size: .85rem; }
.table-scroll { max-height: 40vh; overflow: auto; }
.occ-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 0 0 1rem; }
.occ-date { font-size: 1.05rem; margin: 0 0 .4rem; }
.occ-occupancy { min-width: 220px; text-align: right; }
.occ-number { font-size: 1.4rem; font-weight: 600; }
.bar { height: 10px; background: #e6e9ee; border-radius: 999px; overflow: hidden; margin: .4rem 0; }
.bar-fill { height: 100%; background: var(--color-primary); }
.bar-fill--over { background: var(--color-warn); }
.pagination { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; }
.row-link { cursor: pointer; }
@media (max-width: 900px) { .grid--two-wide { grid-template-columns: 1fr; } .occ-occupancy { text-align: left; } }
