/* ===== Base ===== */
:root {
  --brand: #0e4d3a;
  --brand-2: #1f7a5c;
  --brand-3: #3fa283;
  --brand-ink: #0a3327;
  --brand-soft: #e8f3ee;
  --brand-line: #cfe5da;

  --bg: #f4f7f5;
  --card: #ffffff;
  --text: #1d2a25;
  --muted: #6b7a74;
  --line: #e3e9e6;

  --amber-bg: #fff4e0;
  --amber-ink: #9a5b00;
  --violet-bg: #efe9ff;
  --violet-ink: #5b35b5;
  --green-bg: #e3f6ec;
  --green-ink: #13693f;
  --red: #c2413b;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

.theme-secondary {
  --brand: #0b3a6e;
  --brand-2: #2563a8;
  --brand-3: #4f8fd6;
  --brand-ink: #082a50;
  --brand-soft: #e9f0f9;
  --brand-line: #cadcf1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; color: var(--brand-ink); }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 18px; font-weight: 700; }
p { margin: 0; }

.container { max-width: 1480px; margin: 0 auto; padding: 0 24px 64px; }

/* ===== Header ===== */
.topbar {
  background: linear-gradient(120deg, var(--brand-ink) 0%, var(--brand) 55%, var(--brand-2) 100%);
  color: #fff;
  box-shadow: 0 4px 18px rgba(10, 51, 39, .18);
}
.topbar-inner {
  max-width: 1480px; margin: 0 auto; padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; font-weight: 800; font-size: 18px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .25); font-size: 18px;
}
.brand small { display: block; font-size: 12px; font-weight: 500; opacity: .8; }
.nav { display: flex; align-items: center; gap: 6px; }
.nav a, .nav button {
  color: rgba(255, 255, 255, .9); padding: 8px 12px; border-radius: 10px;
  background: transparent; border: 0; font: inherit; cursor: pointer;
}
.nav a:hover, .nav button:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }

/* ===== Flash ===== */
.flash {
  margin: 20px 0 0; padding: 12px 16px; border-radius: 12px;
  background: var(--green-bg); color: var(--green-ink); border: 1px solid #bfe8d2;
  font-weight: 500;
}
.flash.error { background: #fdecea; color: #9c2b25; border-color: #f5c6c2; }

/* ===== Page head ===== */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin: 28px 0 18px;
}
.eyebrow { font-size: 13px; color: var(--brand-2); font-weight: 600; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }

/* ===== Cards ===== */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 20px 22px;
}
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-7 { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.stat { position: relative; overflow: hidden; }
.stat::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--brand-3);
}
.stat .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 800; color: var(--brand-ink); margin-top: 4px; letter-spacing: -0.02em; }
.stat .unit { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.stat-hero {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff; border: 0;
}
.stat.stat-hero::before { display: none; }
.stat.stat-hero .label, .stat.stat-hero .value, .stat.stat-hero .unit, .stat.stat-hero .sub { color: #fff; }
.stat.stat-hero .sub { opacity: .8; }

/* ===== Level tabs ===== */
.tabs { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.tabs a {
  padding: 9px 18px; border-radius: 10px; color: var(--muted); font-weight: 600; text-decoration: none;
}
.tabs a.active { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(14, 77, 58, .25); }
.theme-secondary .tabs a.active { box-shadow: 0 6px 16px rgba(11, 58, 110, .25); }
.tabs a:hover:not(.active) { background: var(--brand-soft); color: var(--brand-ink); text-decoration: none; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 10px 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(14, 77, 58, .22); }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: #fff; color: var(--brand-ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--brand-soft); border-color: var(--brand-line); }
.btn-danger { background: #fff; color: var(--red); border-color: #f2c7c4; }
.btn-danger:hover { background: #fdecea; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }

/* ===== Forms ===== */
.form-section { margin-top: 18px; }
.form-section > h2 {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px dashed var(--brand-line);
}
.form-section > h2 .num {
  width: 26px; height: 26px; border-radius: 8px; background: var(--brand); color: #fff;
  display: inline-grid; place-items: center; font-size: 13px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label-text { font-size: 13px; font-weight: 600; color: #3b4a44; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; font: inherit; color: var(--text); background: #fff;
  border: 1px solid #d7e0dc; border-radius: 11px; padding: 10px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand-3); box-shadow: 0 0 0 4px rgba(63, 162, 131, .18);
}
.theme-secondary .input:focus, .theme-secondary .select:focus, .theme-secondary .textarea:focus {
  border-color: var(--brand-3); box-shadow: 0 0 0 4px rgba(79, 143, 214, .2);
}
.input-group { display: flex; align-items: center; gap: 8px; }
.input-group .suffix { color: var(--muted); font-size: 13px; white-space: nowrap; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.error-text { color: var(--red); font-size: 13px; margin-top: 4px; }
.preview {
  margin-top: 16px; padding: 14px 16px; border-radius: 14px; background: var(--brand-soft);
  border: 1px solid var(--brand-line); display: flex; gap: 22px; flex-wrap: wrap; align-items: center;
}
.preview .k { font-size: 12px; color: var(--muted); }
.preview .v { font-size: 17px; font-weight: 800; color: var(--brand-ink); }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap; line-height: 1.3;
}
.badge-all { background: var(--green-bg); color: var(--green-ink); }
.badge-lottery { background: var(--violet-bg); color: var(--violet-ink); }
.badge-pending { background: var(--amber-bg); color: var(--amber-ink); }
.badge-muted { background: #eef2f0; color: var(--muted); }
.badge-alt { background: var(--brand-soft); color: var(--brand-ink); border: 1px solid var(--brand-line); }

/* ===== Table ===== */
.table-wrap {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow-x: hidden; overflow-y: auto; max-height: 74vh;
}
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; table-layout: auto; }
.tbl th, .tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: left; }
.tbl th {
  position: sticky; top: 0; z-index: 2; background: var(--brand-soft); color: var(--brand-ink);
  font-size: 12.5px; font-weight: 700; white-space: nowrap; box-shadow: inset 0 -1px 0 var(--brand-line);
}
.tbl tbody tr:hover td { background: #f7fbf9; }
.tbl tbody tr.is-pending td { background: #fffdf7; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td.center, .tbl th.center { text-align: center; }
.tbl .strong { font-weight: 700; color: var(--brand-ink); }
.tbl .sub { font-size: 11.5px; color: var(--muted); }
.tbl .course-no {
  display: inline-block; min-width: 36px; text-align: center; padding: 2px 8px; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 12px; margin-right: 6px;
}
.tbl .row-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.tbl form { margin: 0; display: inline; }
.order-cell { display: flex; align-items: center; gap: 4px; justify-content: center; }
.drag-handle { cursor: grab; color: var(--muted); padding: 2px 4px; user-select: none; font-size: 16px; line-height: 1; }
.drag-handle:active { cursor: grabbing; }
.order-btn {
  width: 24px; height: 24px; padding: 0; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--brand-ink); cursor: pointer; font-size: 10px; line-height: 1;
}
.order-btn:hover { background: var(--brand-soft); border-color: var(--brand-line); }
.tbl tbody tr.dragging { opacity: .45; }
.tbl tbody tr.drag-over td { box-shadow: inset 0 2px 0 var(--brand); }
.empty { padding: 48px; text-align: center; color: var(--muted); }

.pill-note {
  display: inline-block; padding: 3px 8px; border-radius: 8px; background: #f2f5f4; color: var(--muted);
  font-size: 12px; font-weight: 500;
}

/* ===== Auth ===== */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 500px at 10% -10%, #cfe9dd 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #cfe0f5 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; padding: 36px 32px; }
.auth-card .brand-mark { background: var(--brand); border-color: transparent; color: #fff; width: 44px; height: 44px; }
.auth-card h1 { font-size: 22px; margin: 16px 0 4px; }

/* ===== Misc ===== */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 22px 0 12px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); align-items: center; }
.semester-list { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.semester-item { display: flex; flex-direction: column; gap: 12px; text-decoration: none; color: inherit; transition: transform .12s, box-shadow .12s; }
.semester-item:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 12px 30px rgba(16, 24, 40, .1); }
.semester-item .title { font-size: 20px; font-weight: 800; color: var(--brand-ink); }
.semester-item .meta { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-ink); }
.chip.secondary { background: #e9f0f9; color: #0b3a6e; }
.details summary { cursor: pointer; font-weight: 600; color: var(--brand-2); }
.details[open] summary { margin-bottom: 8px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .select { width: auto; min-width: 200px; }

/* ===== Confirm Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: none; place-items: center; padding: 20px;
  background: rgba(10, 26, 20, .52); backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: grid; }
.modal-box {
  width: 100%; max-width: 420px; background: #fff; border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25); border: 1px solid var(--line); padding: 24px;
}
.modal-box h3 { font-size: 18px; font-weight: 800; color: var(--brand-ink); margin-bottom: 8px; }
.modal-box p { font-size: 14px; color: var(--muted); white-space: pre-line; line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn-danger-solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger-solid:hover { background: #a8322d; }

@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-7 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .form-grid, .grid-3, .grid-4, .grid-7 { grid-template-columns: 1fr; }
  .span-2, .span-3, .span-4 { grid-column: auto; }
  .topbar-inner { flex-direction: column; align-items: flex-start; }
}
