:root {
  --bg: #fbfbfa;
  --sidebar-bg: #f7f6f4;
  --panel: #ffffff;
  --border: #e8e7e4;
  --border-strong: #dcdad6;
  --text: #37352f;
  --text-dim: #8b897f;
  --text-faint: #b3b1a8;
  --accent: #5e6ad2;
  --accent-bg: #eef0fc;
  --danger: #e5484d;
  --danger-bg: #fdeceb;
  --success: #29a383;
  --success-bg: #e8f5f0;
  --warn: #d9730d;
  --warn-bg: #faf0e3;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191919;
    --sidebar-bg: #161616;
    --panel: #1f1f1f;
    --border: #2c2c2c;
    --border-strong: #383838;
    --text: #e9e9e7;
    --text-dim: #9a9a97;
    --text-faint: #6a6a68;
    --accent: #7b87e8;
    --accent-bg: #262a45;
    --danger: #f2555a;
    --danger-bg: #3a2323;
    --success: #4cc38a;
    --success-bg: #1f3129;
    --warn: #e0973a;
    --warn-bg: #3a2e1c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #191919;
  --sidebar-bg: #161616;
  --panel: #1f1f1f;
  --border: #2c2c2c;
  --border-strong: #383838;
  --text: #e9e9e7;
  --text-dim: #9a9a97;
  --text-faint: #6a6a68;
  --accent: #7b87e8;
  --accent-bg: #262a45;
  --danger: #f2555a;
  --danger-bg: #3a2323;
  --success: #4cc38a;
  --success-bg: #1f3129;
  --warn: #e0973a;
  --warn-bg: #3a2e1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-top { padding: 6px 8px 12px; }

.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { color: var(--accent); font-size: 20px; }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn .material-symbols-outlined { font-size: 16px; }

.btn-block { width: 100%; justify-content: center; margin-bottom: 10px; }

.key-hint {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 4px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover { opacity: 0.9; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover { color: var(--text); background: var(--border); }

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 6px 8px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  position: relative;
}

.nav-item .material-symbols-outlined { font-size: 17px; color: var(--text-faint); flex-shrink: 0; }

.nav-item span:nth-child(2) {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item:hover { background: var(--border); color: var(--text); }

.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
}

.nav-item.active .material-symbols-outlined { color: var(--accent); }

.nav-count {
  font-size: 11.5px;
  color: var(--text-faint);
  background: transparent;
  min-width: 16px;
  text-align: right;
}

.nav-count.danger { color: var(--danger); }

.nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 14px 8px 6px;
}

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

.sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.progress-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px auto 10px;
  width: 96px;
  height: 96px;
}

.progress-card canvas { width: 96px; height: 96px; }

.progress-card-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.progress-card-label span:first-child { font-size: 18px; font-weight: 700; }
.progress-sub { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  margin-left: auto;
}

.status-dot.on { background: var(--success); }
.status-dot.off { background: var(--danger); }

/* ---------- Main ---------- */

.main {
  padding: 28px 40px 60px;
  max-width: 900px;
  width: 100%;
}

@media (max-width: 820px) {
  .main { padding: 20px; }
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.main-header-title { display: flex; align-items: baseline; gap: 10px; }
.main-header-title h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.015em; }
.main-header-count { color: var(--text-faint); font-size: 13px; }

.main-header-actions { display: flex; align-items: center; gap: 8px; }

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  height: 34px;
  padding: 0 10px;
  min-width: 220px;
  box-sizing: border-box;
}

.search-box .material-symbols-outlined { font-size: 16px; color: var(--text-faint); }

.search-box input {
  border: none;
  background: transparent;
  font-size: 13px;
  width: 100%;
  color: var(--text);
}

.search-box input:focus { outline: none; }

select, input, textarea {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
}

select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); }

textarea { resize: vertical; }

.groups { display: flex; flex-direction: column; gap: 22px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 8px;
  padding-left: 2px;
}

.group-title .material-symbols-outlined { font-size: 15px; }
.group-title.overdue { color: var(--danger); }

.assignment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.assignment-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s ease;
}

.assignment-card:last-child { border-bottom: none; }
.assignment-card:hover { background: var(--sidebar-bg); }
.assignment-card:hover .assignment-actions { opacity: 1; }

.check-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: transparent;
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.12s ease;
}

.check-btn .material-symbols-outlined { font-size: 14px; }

.check-btn:hover { border-color: var(--success); }

.check-btn.checked {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.check-btn.in-progress {
  border-color: var(--accent);
  background: linear-gradient(90deg, var(--accent) 50%, transparent 50%);
}

.check-btn.in-progress:hover { border-color: var(--accent); }

.assignment-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.assignment-title {
  font-weight: 500;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  width: fit-content;
  max-width: 100%;
}

.assignment-card.is-done .assignment-title {
  color: var(--text-faint);
  text-decoration: line-through;
}

.assignment-title:hover { text-decoration: underline; }

.assignment-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.course-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 500;
}

.due-text { display: flex; align-items: center; gap: 4px; }
.due-text .material-symbols-outlined { font-size: 13px; }
.due-text.overdue { color: var(--danger); font-weight: 500; }

.priority-flag { font-size: 15px !important; }
.priority-flag.high { color: var(--danger); }
.priority-flag.medium { color: var(--warn); }
.priority-flag.low { color: var(--text-faint); }

.assignment-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { color: var(--text); background: var(--border); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }

.empty-state[hidden] { display: none; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  text-align: center;
  padding: 60px 0;
  font-size: 13.5px;
}

.empty-state .material-symbols-outlined { font-size: 32px; }

.locked-group {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.locked-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.locked-group summary::-webkit-details-marker { display: none; }
.locked-group summary .material-symbols-outlined { font-size: 15px; }
.locked-group[open] summary { border-bottom: 1px solid var(--border); }

.locked-group .assignment-list { border: none; border-radius: 0; }

.assignment-card.is-locked { opacity: 0.6; }
.assignment-card.is-locked:hover .assignment-actions { opacity: 0; }
.assignment-card.is-locked .check-btn { cursor: default; border-style: dashed; }
.assignment-card.is-locked .check-btn .material-symbols-outlined { font-size: 12px; color: var(--text-faint); }

.locked-text { color: var(--text-faint) !important; }

/* ---------- Modal ---------- */

.modal-overlay[hidden] { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.modal h2 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.modal-hint { font-size: 12.5px; color: var(--text-dim); margin: 0 0 16px; }

#assignmentForm, #settingsForm { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
#assignmentForm label, #settingsForm label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--text-dim); font-weight: 500; }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }

.field-hint { font-size: 11.5px; color: var(--text-faint); margin: -6px 0 0; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- Course autocomplete ---------- */

.autocomplete-field { position: relative; }

.suggestions[hidden] { display: none; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  max-height: 220px;
  overflow-y: auto;
  z-index: 5;
}

.suggestion-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 10px;
  cursor: pointer;
}

.suggestion-item:hover, .suggestion-item.active {
  background: var(--accent-bg);
}

.suggestion-title { font-size: 13px; font-weight: 500; color: var(--text); }
.suggestion-sub { font-size: 11px; color: var(--text-faint); }

.course-info[hidden] { display: none; }

.course-info {
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12px;
  color: var(--text);
  margin-top: -4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.course-info .course-info-meta { color: var(--text-dim); font-size: 11.5px; }
.course-info .course-info-next { display: flex; align-items: center; gap: 5px; font-weight: 500; color: var(--accent); }
.course-info .course-info-next .material-symbols-outlined { font-size: 14px; }

.quick-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -6px;
}

.chip-btn {
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip-btn[hidden] { display: none; }

.chip-btn .chip-chevron { font-size: 14px; vertical-align: -2px; margin-left: 1px; }

.class-day-menu {
  position: fixed;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow-md);
  padding: 4px;
  min-width: 200px;
  max-height: 260px;
  overflow-y: auto;
}

.class-day-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.class-day-option:hover { background: var(--sidebar-bg); }
.class-day-option-main { font-size: 13px; font-weight: 500; color: var(--text); }
.class-day-option-sub { font-size: 11px; color: var(--text-faint); }

/* ---------- Checkbox complete animation ---------- */

.check-btn {
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.check-btn.pop {
  animation: checkPop 0.32s ease;
}

@keyframes checkPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.assignment-card {
  transition: opacity 0.32s ease, transform 0.32s ease, max-height 0.32s ease,
    margin 0.32s ease, padding 0.32s ease, border-color 0.32s ease;
}

.assignment-card.leaving {
  opacity: 0;
  transform: translateX(16px) scale(0.97);
  overflow: hidden;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-bottom-width: 0 !important;
}

.assignment-card.just-completed {
  background: var(--success-bg);
}

/* ---------- Custom select (replaces native <select> chrome) ---------- */

.custom-select { position: relative; }

.custom-select-trigger {
  display: grid;
  grid-template-columns: 18px 1fr 18px;
  align-items: center;
  column-gap: 7px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  height: 34px;
  padding: 0 10px;
  box-sizing: border-box;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s ease;
}

.custom-select-trigger:hover { border-color: var(--accent); }

.custom-select.open .custom-select-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.custom-select-trigger .leading-icon { font-size: 15px; color: var(--text-faint); justify-self: center; }
.custom-select-trigger .option-dot { justify-self: center; }

.custom-select-label {
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select-trigger .chevron {
  font-size: 17px;
  color: var(--text-faint);
  justify-self: center;
  transition: transform 0.15s ease;
}

.custom-select.open .chevron { transform: rotate(180deg); }

.custom-select-menu[hidden] { display: none; }

.custom-select-menu {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 100%;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow-md);
  z-index: 20;
  padding: 4px;
}

.custom-select-option {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
}

.custom-select-option:hover { background: var(--sidebar-bg); }

.custom-select-option.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
}

.custom-select-option .option-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.custom-select--header { min-width: 152px; }

.feed-url-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.feed-url-row input {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- Quick status pill + popover ---------- */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  cursor: pointer;
  background: var(--sidebar-bg);
  color: var(--text-dim);
}

.status-pill:hover { background: var(--border); color: var(--text); }

.status-menu {
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow-md);
  padding: 4px;
  min-width: 150px;
}

/* ---------- Assignment detail drawer ---------- */

.drawer-overlay {
  justify-content: flex-end;
  align-items: stretch;
  background: rgba(0, 0, 0, 0.35);
}

.drawer-panel {
  max-width: 560px;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  padding: 30px 34px;
  border-radius: 0;
  border-top: none;
  border-right: none;
  border-bottom: none;
  overflow-y: auto;
  animation: drawerSlideIn 0.2s ease;
}

.drawer-panel h2 { font-size: 18px; }

.drawer-panel #assignmentForm { gap: 16px; }
.drawer-panel #assignmentForm label { gap: 7px; font-size: 13px; }

@keyframes drawerSlideIn {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.drawer-header h2 { flex: 1; min-width: 0; }

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.drawer-header-actions .btn {
  white-space: nowrap;
  padding: 6px 10px;
}

.drawer-header-actions .btn[hidden] { display: none; }

.description-section {
  margin: 14px 0;
  padding: 12px 13px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 260px;
  overflow-y: auto;
}

.description-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.description-label .material-symbols-outlined { font-size: 14px; }

.description-content {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}

.description-content p,
.description-content ul,
.description-content ol,
.description-content blockquote,
.description-content table {
  margin: 0 0 10px;
}

.description-content ul, .description-content ol { padding-left: 20px; }
.description-content a { color: var(--accent); }
.description-content > *:last-child { margin-bottom: 0; }
