@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  --bg: #12151b;
  --surface: #1a1e26;
  --surface-2: #232833;
  --border: #2c323e;
  --text: #eef0f4;
  --text-dim: #98a1b3;
  --text-faint: #626b7c;

  --accent: #f2a341;       /* กำลังใกล้ถึง - อำพัน */
  --accent-dim: #7a5a2c;
  --danger: #ef5b5b;        /* เกินกำหนด */
  --danger-dim: #5c2f2f;
  --success: #33d69f;       /* ส่งแล้ว */
  --lab: #7c9bff;           /* งานแลป */
  --lecture: #c793f5;       /* งานบรรยาย */

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius: 10px;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
}

a { color: inherit; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

/* ---------- Layout shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  transition: transform 0.25s ease;
  z-index: 40;
}

.sidebar-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  margin: 4px 4px 26px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.sidebar-brand .dot { color: var(--accent); }

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 18px 12px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  padding: 26px 34px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
  gap: 16px;
}

.page-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  margin: 0;
}
.page-sub {
  color: var(--text-dim);
  font-size: 13.5px;
  margin-top: 4px;
}

.menu-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
}
.btn:hover { border-color: var(--text-faint); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1300;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .label { color: var(--text-dim); font-size: 12.5px; margin-bottom: 8px; }
.stat-card .value { font-family: var(--font-mono); font-size: 28px; font-weight: 600; }
.stat-card.warn .value { color: var(--accent); }
.stat-card.danger .value { color: var(--danger); }
.stat-card.success .value { color: var(--success); }

.section-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  margin: 0 0 14px;
}

.two-col {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  align-items: start;
}

/* ---------- Task rows ---------- */
.task-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 6px;
  border-bottom: 1px solid var(--border);
}
.task-row:last-child { border-bottom: none; }

.urgency-bar {
  width: 4px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--text-faint);
  flex-shrink: 0;
}
.urgency-bar.overdue { background: var(--danger); }
.urgency-bar.soon { background: var(--accent); }
.urgency-bar.ok { background: var(--success); }

.task-info { flex: 1; min-width: 0; }
.task-title { font-weight: 500; font-size: 14px; }
.task-meta { color: var(--text-dim); font-size: 12.5px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.type-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.type-chip.lab { background: rgba(124,155,255,0.15); color: var(--lab); }
.type-chip.lecture { background: rgba(199,147,245,0.15); color: var(--lecture); }

.countdown {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.countdown.overdue { color: var(--danger); background: rgba(239,91,91,0.12); }
.countdown.soon { color: var(--accent); background: rgba(242,163,65,0.12); }
.countdown.ok { color: var(--text-dim); background: var(--surface-2); }

.course-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Forms / modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8,10,14,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.hidden { display: none !important; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  padding: 22px 24px 24px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { font-family: var(--font-display); margin: 0 0 18px; font-size: 18px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }
.field input[type=text], .field input[type=datetime-local], .field textarea, .field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: var(--font-body);
}
.field textarea { resize: vertical; min-height: 70px; }
.radio-row { display: flex; gap: 10px; }
.radio-opt {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-dim);
}
.radio-opt.selected.lab { border-color: var(--lab); color: var(--lab); background: rgba(124,155,255,0.08); }
.radio-opt.selected.lecture { border-color: var(--lecture); color: var(--lecture); background: rgba(199,147,245,0.08); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Course grid ---------- */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.course-card { border-left: 3px solid var(--accent); }
.course-card .cname { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.course-card .cmeta { color: var(--text-dim); font-size: 12.5px; margin-bottom: 12px; }
.course-card .cprog { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.bar-track { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--success); }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filter-bar select { background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty-state .big { font-size: 34px; margin-bottom: 10px; }

.banner {
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--accent-dim);
  color: #ffe6bf;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13.5px;
  margin-bottom: 18px;
}
.banner.show { display: flex; }

@media (max-width: 880px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 20px 16px 50px; }
  .menu-toggle { display: flex; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
