:root {
  --bg: #f4f7f5;
  --bg-accent: #e7efe9;
  --ink: #1c2b24;
  --muted: #5b6b63;
  --brand: #1f6b4a;
  --brand-dark: #154c34;
  --danger: #9b1c1c;
  --warning: #8a5a00;
  --success: #146c43;
  --card: #ffffff;
  --border: #d5e0d9;
  --shadow: 0 10px 30px rgba(28, 43, 36, 0.08);
  --radius: 14px;
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #d9ebe1 0, transparent 40%),
    linear-gradient(180deg, #f7faf8 0%, var(--bg) 100%);
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.container { width: min(1100px, 92%); margin: 0 auto; }

/* Auth */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(ellipse at 20% 0%, #cfe6d8 0, transparent 45%),
    linear-gradient(165deg, #f7faf8 0%, #eef5f0 100%);
}
.auth-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 2rem 1.75rem;
}
.auth-card .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
}
.brand {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--brand-dark);
  margin: 0 0 0.25rem;
}
.subtitle { color: var(--muted); margin: 0 0 1.5rem; font-size: 0.95rem; line-height: 1.45; }

label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
input[type="date"],
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  margin-bottom: 1rem;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 107, 74, 0.25);
  border-color: var(--brand);
}

.toolbar {
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.45rem;
}
.page-header .lede {
  margin: 0;
  color: var(--muted);
  max-width: 40rem;
  line-height: 1.45;
}
.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: collapse; min-width: 520px; }
.table th, .table td {
  text-align: left;
  padding: 0.85rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th { font-size: 0.8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; }
.table tbody tr:hover { background: #f7fbf8; }
.actions { white-space: nowrap; }
.actions a { margin-right: 0.75rem; }
.actions .link-btn,
button.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin-right: 0.75rem;
  color: var(--brand);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.actions .link-btn.danger { color: var(--danger); }

.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; margin-bottom: 0.75rem; }
.check input { width: auto; margin: 0; }
.mode-set {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem 0.35rem;
  margin-bottom: 1rem;
  background: #f9fcfa;
}
.mode-set legend { padding: 0 0.35rem; font-weight: 700; color: var(--brand-dark); }
.mode-set .check { margin-bottom: 0.65rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.25rem;
}
.form-grid .full { grid-column: 1 / -1; }
.form-section-title {
  grid-column: 1 / -1;
  margin: 0.25rem 0 0.75rem;
  font-size: 0.95rem;
  color: var(--brand-dark);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.inline-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.inline-edit select,
.inline-edit input[type="text"],
.inline-edit input[type="number"] {
  width: auto;
  margin: 0;
  padding: 0.45rem 0.55rem;
}
.inline-edit .check { margin: 0; }

.mapping-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.85rem;
  background: #fafcfb;
}
.mapping-card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.mapping-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

[hidden] { display: none !important; }
button.link-btn.danger { color: var(--danger); }

.suggest-hint {
  margin: -0.55rem 0 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.suggest-hint .link-btn { margin-left: 0.25rem; font-size: 0.8rem; }

.section-label {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.outcome-list { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.outcome-list li { margin-bottom: 0.25rem; }

.module-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.module-summary h2 { margin: 0; }
.module-seq {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.6rem;
  margin-right: 0.5rem;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}
.module-text { margin: 0 0 0.75rem; }
.module-card details summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.module-edit { margin-top: 0.75rem; }
.module-edit label { font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn-block { width: 100%; }
.btn-light {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-light:hover { background: var(--bg-accent); color: var(--ink); }
.btn-sm { padding: 0.45rem 0.75rem; font-size: 0.9rem; }

.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  line-height: 1.4;
}
.alert-error { background: #fdecec; color: var(--danger); border-color: #f3c1c1; }
.alert-success { background: #e8f8ef; color: var(--success); border-color: #b7e4c7; }
.alert-warning { background: #fff6e5; color: var(--warning); border-color: #f0d7a0; }

.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #163a2b 0%, #1f6b4a 100%);
  color: #fff;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}
.sidebar .brand { color: #fff; font-size: 1.15rem; }
.sidebar .role-label { color: rgba(255,255,255,.75); font-size: .85rem; margin-bottom: 0.25rem; }
.sidebar nav { margin-top: 1.75rem; display: grid; gap: 0.35rem; flex: 1; align-content: start; }
.sidebar .nav-group {
  color: rgba(255,255,255,0.6);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.9rem 0.8rem 0.2rem;
}
.sidebar .nav-group:first-child { padding-top: 0; }
.sidebar a {
  color: rgba(255,255,255,0.9);
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
}
.sidebar a:hover { background: rgba(255,255,255,0.1); text-decoration: none; }
.sidebar a.active {
  background: rgba(255,255,255,0.18);
  font-weight: 700;
  text-decoration: none;
}
.sidebar .logout-form { margin-top: auto; padding-top: 1.5rem; }
.main { padding: 1.5rem 1.75rem 2rem; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.1rem;
}
.panel h2 { margin-top: 0; font-size: 1.1rem; }
.muted { color: var(--muted); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-accent);
  color: var(--brand-dark);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
}
.badge-success { background: #e3f6eb; color: var(--success); }
.badge-danger { background: #fdecec; color: var(--danger); }
.badge-warning { background: #fff3d6; color: var(--warning); }
.badge-neutral { background: #eef1ef; color: var(--muted); }
.badge-info { background: #e7f0fb; color: #1a4f8a; }
.badge-stack { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}
.empty-state strong { display: block; color: var(--ink); margin-bottom: 0.35rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 750;
  color: var(--brand-dark);
  line-height: 1.1;
}
.stat-card .stat-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.detail-list { margin: 0; padding: 0; list-style: none; }
.detail-list li {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.detail-list li:last-child { border-bottom: none; }
.detail-list .label { color: var(--muted); font-weight: 600; font-size: 0.9rem; }

.credentials-slip {
  border: 2px dashed var(--brand);
  border-radius: 14px;
  padding: 1.5rem;
  background: #f8fcf9;
  max-width: 28rem;
}
.credentials-slip .otp-value {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  word-break: break-all;
  margin: 0.35rem 0 0;
  color: var(--brand-dark);
}

.quick-links { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* Learning calendars */
.cal-timeline { margin: 0.35rem 0 0.75rem; }
.cal-track {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-flow: row dense;
  grid-auto-rows: minmax(2.6rem, auto);
  gap: 3px;
  background: #f1f5f2;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}
.cal-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 0.3rem 0.45rem;
  border-radius: 7px;
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.2;
  overflow: hidden;
}
.cal-block-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-tag {
  align-self: flex-start;
  margin-top: 0.15rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}
.cal-color-0 { background: #1f6b4a; }
.cal-color-1 { background: #2f6f9f; }
.cal-color-2 { background: #8a5a00; }
.cal-color-3 { background: #6b4a9b; }
.cal-color-4 { background: #1d7c7c; }
.cal-color-5 { background: #9b4a4a; }
.cal-block.cal-overlap {
  background: #fdecec;
  color: var(--danger);
  outline: 2px solid var(--danger);
  outline-offset: -2px;
}
.cal-block.cal-overlap .cal-tag { background: #f3c1c1; }
.cal-break {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #b9c9bf;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-style: italic;
  background: repeating-linear-gradient(135deg, #f7faf8, #f7faf8 6px, #eef3ef 6px, #eef3ef 12px);
}
.cal-months {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 3px;
  padding: 0.25rem 3px 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
}
.cal-timeline-compact .cal-track { grid-auto-rows: minmax(1.5rem, auto); }
.cal-timeline-compact .cal-block { padding: 0.15rem 0.35rem; font-size: 0.7rem; }
.cal-timeline-compact .cal-tag { display: none; }
.cal-timeline-compact .cal-break { font-size: 0.65rem; }
.cal-timeline-compact .cal-months { font-size: 0.62rem; }
.cal-warning { margin-top: 0.25rem; }
.cal-summary { margin: 0.25rem 0 0; font-size: 0.9rem; }

.cal-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
  gap: 1rem;
}
.cal-card { margin-bottom: 0; display: flex; flex-direction: column; }
.cal-card h2 { margin-bottom: 0.4rem; }
.cal-card-inactive { opacity: 0.75; }
.cal-card-head { margin-bottom: 0.65rem; }
.cal-card-summary { font-size: 0.85rem; margin: 0 0 0.5rem; }
.cal-card-desc { font-size: 0.9rem; margin: 0 0 0.5rem; }
.cal-card-foot {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
.cal-card-foot .actions form { margin: 0; }

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.1rem;
}
.choice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fafcfb;
  cursor: pointer;
  font-weight: 400;
  margin: 0;
}
.choice-card:hover { border-color: #9fc3ae; }
.choice-card input { position: absolute; opacity: 0; pointer-events: none; }
.choice-card:has(input:checked) { border-color: var(--brand); background: #eef7f1; box-shadow: 0 0 0 3px rgba(31, 107, 74, 0.12); }
.choice-card:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.choice-title { font-weight: 700; color: var(--brand-dark); }
.choice-meta { font-size: 0.82rem; font-weight: 600; color: var(--ink); }
.choice-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.35; }

.stepper { display: flex; align-items: stretch; gap: 0.35rem; margin-bottom: 1rem; }
.stepper input { width: 5rem; text-align: center; margin: 0; }
.stepper .btn { padding: 0.45rem 0.9rem; font-size: 1.1rem; }

.preset-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; margin-bottom: 0.85rem; }
.preset-bar .section-label { margin: 0 0.35rem 0 0; }
.period-rows { display: grid; gap: 0.55rem; margin-bottom: 0.85rem; }
.period-row {
  display: grid;
  grid-template-columns: auto minmax(9rem, 2fr) minmax(7rem, 1fr) minmax(7rem, 1fr) minmax(10rem, 1.4fr);
  gap: 0.6rem;
  align-items: end;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafcfb;
}
.period-row .module-seq { margin: 0 0 0.55rem; }
.period-field { display: flex; flex-direction: column; gap: 0.2rem; margin: 0; font-weight: 400; }
.period-field > span { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.period-field input, .period-field select { margin: 0; }
.term-row-form { display: contents; }

@media (max-width: 800px) {
  .period-row { grid-template-columns: auto 1fr; }
  .period-row .period-field { grid-column: 2; }
  .cal-card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { padding-bottom: 0.75rem; }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 1rem; }
  .sidebar .nav-group { grid-column: 1 / -1; padding-top: 0.5rem; }
  .sidebar .logout-form { margin-top: 1rem; padding-top: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-list li { grid-template-columns: 1fr; gap: 0.15rem; }
  .main { padding: 1rem; }
}

.print-body { background: var(--bg-accent, #eef3ef); }
.print-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  max-width: 52rem;
  margin: 1.25rem auto 0;
  padding: 0 1rem;
}
.print-sheet {
  max-width: 52rem;
  margin: 1rem auto 2rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 2.25rem;
}
.statement-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  border-bottom: 2px solid var(--brand);
  padding-bottom: 0.9rem;
  margin-bottom: 1.1rem;
}
.statement-meta { text-align: right; font-size: 0.85rem; }
.statement-section { margin-bottom: 1.4rem; break-inside: avoid; }
.statement-section h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.statement-section tfoot td { border-top: 2px solid var(--border); }
.statement-summary { padding: 0.75rem 1rem; background: #f8fcf9; border: 1px solid var(--border); border-radius: 10px; }
.statement-footer { border-top: 1px solid var(--border); padding-top: 0.75rem; font-size: 0.8rem; }

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .toolbar, .page-header-actions, .alert, .no-print { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .panel, .credentials-slip {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  .credentials-slip { max-width: none; }
  .print-body { background: #fff; }
  .print-sheet { max-width: none; margin: 0; padding: 0; border: none; box-shadow: none; }
  .statement-section table { font-size: 0.85rem; }
  @page { margin: 15mm; }
}
