:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --sidebar: #1f2433;
  --sidebar-text: #c9cede;
  --sidebar-active: #2e3549;
  --text: #1c2030;
  --muted: #6b7185;
  --border: #e3e6ef;
  --primary: #036efc;
  --primary-text: #ffffff;
  --danger: #d6455d;
  --overdue: #d6455d;
  --today: #e08a1e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 2px 8px rgba(20, 24, 40, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1b1e29;
    --sidebar: #0d0f15;
    --sidebar-text: #aab0c2;
    --sidebar-active: #1f2332;
    --text: #e7e9f0;
    --muted: #8d93a7;
    --border: #2a2e3d;
    --primary: #3d8bff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

/* Phones/tablets: keep zoom fixed at 100%. iOS zooms into any field with text under 16px,
   so fields get 16px; touch-action stops double-tap zoom. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (pointer: coarse) {
  html, body { touch-action: pan-x pan-y; }
  input, select, textarea { font-size: 16px; }
}

/* ---------- layout ---------- */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  color: #fff;
  padding: 4px 10px 18px;
}
.brand-logo { width: 26px; height: auto; display: block; }

nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item.add { color: var(--muted); margin-top: 4px; }
.nav-item.add:hover { color: #fff; }

.nav-icon { width: 18px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.nav-item .dot { margin: 0 4px; }

.count {
  font-size: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 0 8px;
  min-width: 22px;
  text-align: center;
}
.count:empty { display: none; }

.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 18px 10px 6px;
}

.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
}
.link-btn:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 24px 32px 48px; max-width: 900px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.title-wrap { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.title-wrap h1 { margin: 0; font-size: 26px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.title-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.menu-btn {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 18px;
}

.scrim { display: none; }

/* ---------- controls ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
label .muted { font-weight: 400; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; font-size: 14px; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------- cards & lists ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}


.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.toggle { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.toggle input { width: auto; }

.group { margin-bottom: 22px; }
.group h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 8px 2px;
}
.group.overdue h3 { color: var(--overdue); }
.group.today h3 { color: var(--today); }

.list { list-style: none; margin: 0; padding: 0; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: 0; }
.item .check { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; cursor: pointer; accent-color: var(--primary); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; word-break: break-word; }
.item.done .title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin-top: 2px; align-items: center; }
.item .notes { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.item .due.overdue { color: var(--overdue); font-weight: 600; }
.item .due.today { color: var(--today); font-weight: 600; }
.item .actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.item:hover .actions, .item:focus-within .actions { opacity: 1; }

.icon-btn {
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.chip:hover { text-decoration: underline; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.kind-tag { font-size: 12px; color: var(--muted); }

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(10, 12, 20, 0.45); }
.dialog-form { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.dialog-form h2 { margin: 0 0 4px; font-size: 19px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -8px; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.selected { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }

/* Eyedropper circle: rainbow ring around a plain center, or filled with the custom color once chosen. */
.swatch-custom {
  display: grid;
  place-items: center;
  background: conic-gradient(#f43f5e, #f5a524, #eab308, #2fa36b, #0ea5b7, #4f6bed, #a855f7, #f43f5e);
}
.swatch-custom span {
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.swatch-custom svg { width: 9px; height: 9px; }
.swatch-custom:hover span { color: var(--text); }
.swatch-custom.has-color span { background: var(--custom); color: var(--custom-ink); }
.swatch-custom[aria-expanded="true"]:not(.selected) { border-color: var(--border); }

/* Hex box revealed by the eyedropper: color preview (doubles as a native picker) inside the input. */
.custom-color { margin-top: -4px; animation: reveal 0.15s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } }
.hex-field { position: relative; width: 160px; }
.hex-field input[name="hex"] {
  padding-left: 40px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hex-field input[name="hex"].invalid { border-color: var(--danger); outline-color: var(--danger); }
.hex-field input[type="color"] {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; padding: 0; border: 1px solid var(--border); border-radius: 6px;
  background: none; cursor: pointer; overflow: hidden;
}
.hex-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.hex-field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.hex-field input[type="color"]::-moz-color-swatch { border: 0; border-radius: 5px; }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; margin-bottom: 6px; }
.login-logo { width: 72px; height: auto; margin-bottom: 10px; filter: drop-shadow(0 4px 10px rgba(20, 24, 40, 0.12)); }
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.login-brand p { margin: 0; font-size: 14px; }
.empty-logo { width: 64px; height: auto; margin-bottom: 8px; }

.tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 3px; }
.tab { flex: 1; border: 0; background: none; padding: 7px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.hint { font-size: 13px; margin: -4px 0 0; }

.account { display: flex; align-items: center; justify-content: space-between; gap: 4px; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 12px; margin-top: 12px; }
.account-link { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; padding: 6px 8px; border-radius: 8px; color: inherit; text-decoration: none; }
.account-link:hover, .account-link.active { background: var(--sidebar-active); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.account-name { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.gear { color: var(--muted); font-size: 14px; }
.account-link:hover .gear { color: #fff; }

/* profile form (first-time prompt + settings) */
.profile-form { display: flex; flex-direction: column; gap: 14px; }
.profile-form fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.profile-form legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
.choices { display: flex; gap: 8px; }
.choice { flex: 1; flex-direction: row; justify-content: center; position: relative; border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; cursor: pointer; color: var(--text); font-size: 15px; font-weight: 500; background: var(--surface); }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); color: var(--primary); font-weight: 600; }
.choice:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.profile-intro { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; margin-bottom: 4px; }
.profile-intro img { width: 48px; height: auto; margin-bottom: 6px; }
.profile-intro p { margin: 0; font-size: 14px; }
.profile-dialog { width: min(480px, calc(100vw - 32px)); }

.settings-card { padding: 20px; margin-bottom: 16px; max-width: 560px; }
.settings-card h2 { margin: 0 0 14px; font-size: 17px; }
.kv { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    left: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 10; }
  .menu-btn { display: block; }
  .main { padding: 16px 16px 40px; }
  .title-wrap h1 { font-size: 21px; }
  .topbar { flex-wrap: wrap; }
  .title-actions { width: 100%; justify-content: flex-start; }
  .title-actions:empty { display: none; }
  #add-assignment { flex: 1; }
        .item .actions { opacity: 1; }
  .row { flex-direction: column; }
}
