:root {
  --bg: #eef2f0;
  --bg-accent: #d7e3dd;
  --ink: #1f2a2e;
  --muted: #5c6b70;
  --line: #c2d0c9;
  --card: #f7faf8;
  --brand: #1f5c4d;
  --brand-soft: #d7ebe3;
  --warn: #9a5b12;
  --warn-soft: #f5e6d2;
  --danger: #8f2f2f;
  --danger-soft: #f3d9d9;
  --ok: #1f6b45;
  --ok-soft: #d8efe2;
  --course: #355f7a;
  --supervised: #1f5c4d;
  --independent: #6b5a3e;
  --life: #7a7f7c;
  --shadow: 0 1px 0 rgba(31, 42, 46, 0.04);
  --radius: 14px;
  --font: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Segoe UI", sans-serif;
  --display: "Fraunces", "Noto Serif SC", "Songti SC", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9ebe3 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #dce6ea 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

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

.shell {
  width: min(1100px, calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1rem 0 5.5rem;
}

.week-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.85rem;
}
.week-actions form { margin: 0; }
.week-more {
  position: relative;
}
.week-more > summary {
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
}
.week-more > summary::-webkit-details-marker { display: none; }
.week-more > summary:hover { background: var(--brand-soft); color: var(--brand); }
.week-more[open] > summary { color: var(--brand); }
.week-more form {
  margin-top: 0.35rem;
}

.day-jump {
  display: grid;
  grid-template-columns: 1.15fr repeat(7, minmax(0, 1fr));
  gap: 0.4rem;
  margin: 0 0 1rem;
  padding: 0.45rem;
  position: sticky;
  top: 0.35rem;
  z-index: 12;
  background: rgba(247, 250, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.day-jump-item {
  display: grid;
  gap: 0.1rem;
  justify-items: center;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  padding: 0.45rem 0.2rem;
  border-radius: 10px;
  min-width: 0;
  border: 1px solid transparent;
}
.day-jump-item:hover {
  background: var(--brand-soft);
  text-decoration: none;
  color: var(--brand);
}
.day-jump-item.is-today:not(.is-active) {
  border-color: var(--brand);
  color: var(--brand);
}
.day-jump-item.is-active {
  background: var(--brand);
  color: #fff;
}
.day-jump-item.is-active:hover { color: #fff; }
.day-jump-name {
  font-weight: 600;
  font-size: 0.88rem;
}
.day-jump-date {
  font-size: 0.75rem;
  opacity: 0.85;
}
.day-jump-count {
  font-size: 0.72rem;
  opacity: 0.8;
}
.day {
  scroll-margin-top: 5.5rem;
}
.empty-day {
  margin: 0.35rem 0 0.2rem;
  padding: 0.65rem 0.2rem;
}

@media (max-width: 900px) {
  .day-jump {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .day-jump-all {
    grid-column: 1 / -1;
  }
}
@media (max-width: 720px) {
  .day-jump-count { display: none; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0 1.25rem;
}
.brand {
  font-family: var(--display);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--brand);
}
.brand span { color: var(--ink); font-weight: 500; font-size: 0.95rem; margin-left: 0.55rem; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 0.45rem 0.75rem calc(0.45rem + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav a {
  text-align: center;
  padding: 0.55rem 0.25rem;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.nav a.active, .nav a:hover {
  background: var(--brand-soft);
  color: var(--brand);
  text-decoration: none;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card h2, .card h3 { margin: 0 0 0.75rem; font-family: var(--display); font-weight: 600; }
.muted { color: var(--muted); }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

.btn {
  appearance: none;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 10px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  cursor: pointer;
}
.btn.secondary {
  background: transparent;
  color: var(--brand);
}
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn.warn {
  background: var(--warn);
  border-color: var(--warn);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.flash {
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
}
.flash.success { background: var(--ok-soft); border-color: #b7dcc8; color: var(--ok); }
.flash.warning { background: var(--warn-soft); border-color: #e5c79a; color: var(--warn); }
.flash.error { background: var(--danger-soft); border-color: #e0b3b3; color: var(--danger); }
.flash.info { background: var(--brand-soft); color: var(--brand); }

.week-nav { margin-bottom: 1rem; }
.day {
  margin-bottom: 1.1rem;
}
.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.45rem;
}
.day-head h3 { margin: 0; font-size: 1.05rem; }
.day.today .day-head h3 { color: var(--brand); }
.timeline { display: grid; gap: 0.4rem; }
.item {
  display: grid;
  grid-template-columns: 5.2rem 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}
.item .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.86rem; }
.item .title { font-weight: 500; }
.item .meta { font-size: 0.8rem; color: var(--muted); }
.item.course {
  border-left: 4px solid var(--course);
  background: linear-gradient(90deg, rgba(53, 95, 122, 0.08), #fff 42%);
}
.item.supervised,
.item.independent {
  border-left: 4px solid var(--supervised);
  background: #fff;
}
.item.independent { border-left-color: var(--independent); }
.item.life { border-left: 4px solid var(--life); opacity: 0.92; background: #f5f6f5; }
.item.done { background: #f3faf6; }
.item.course.done { background: linear-gradient(90deg, rgba(53, 95, 122, 0.1), #f3faf6 42%); }
.item.skipped { opacity: 0.65; text-decoration: line-through; text-decoration-thickness: 1px; }
.item.rescheduled { opacity: 0.55; }
.pill {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--bg-accent);
  color: var(--muted);
}
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.partial { background: var(--warn-soft); color: var(--warn); }
.pill.skipped { background: #eee; }
.pill.planned { background: var(--brand-soft); color: var(--brand); }
.pill.kind-course { background: rgba(53, 95, 122, 0.14); color: var(--course); }
.pill.kind-hw { background: var(--brand-soft); color: var(--brand); }

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}
.quick-actions form { margin: 0; }
.quick-actions .btn { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.quick-pop { position: relative; }
.quick-pop > summary {
  list-style: none;
  display: inline-block;
  cursor: pointer;
}
.quick-pop > summary::-webkit-details-marker { display: none; }
.quick-pop-panel {
  display: grid;
  gap: 0.4rem;
  margin-top: 0.4rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  min-width: 11rem;
  position: absolute;
  right: 0;
  z-index: 5;
  box-shadow: var(--shadow);
}
.quick-pop-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  align-items: center;
}
.quick-done-form label {
  font-size: 0.8rem;
  color: var(--muted);
}
.quick-done-form select {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}

.unfinished-days { display: grid; gap: 0.55rem; }
.unfinished-day {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.35rem 0.65rem 0.55rem;
}
.unfinished-day > summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.15rem;
  font-weight: 500;
}
.unfinished-day[open] > summary { border-bottom: 1px solid var(--line); margin-bottom: 0.35rem; }

.form-grid {
  display: grid;
  gap: 0.85rem;
}
label { display: grid; gap: 0.3rem; font-size: 0.92rem; }
input, select, textarea {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
}
textarea { min-height: 5rem; resize: vertical; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
}
.stat .value { font-family: var(--display); font-size: 1.6rem; font-weight: 600; }
.stat .label { color: var(--muted); font-size: 0.85rem; }

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th { color: var(--muted); font-weight: 500; }
/* admin-table overrides applied via .admin-table */
table.data.admin-table th,
table.data.admin-table td {
  vertical-align: middle;
  padding: 0.7rem 0.65rem;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.6rem 1.4rem 1.4rem;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-family: var(--display);
  margin: 0 0 0.35rem;
  color: var(--brand);
  font-size: 2rem;
}
.suggestions { display: grid; gap: 0.5rem; }
.suggestion {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}

.save-bar {
  position: sticky;
  bottom: 4.5rem;
  z-index: 15;
  background: rgba(247, 250, 248, 0.96);
  backdrop-filter: blur(8px);
}

.tpl-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 1rem 1rem;
  margin: 0.85rem 0;
  background: #fff;
}
.tpl-panel > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  align-items: baseline;
}
.tpl-panel > summary::-webkit-details-marker { display: none; }
.tpl-panel > summary::before {
  content: "▸";
  color: var(--brand);
  font-weight: 600;
  margin-right: 0.15rem;
}
.tpl-panel[open] > summary::before { content: "▾"; }

.settings-layout {
  display: grid;
  gap: 1rem;
  align-items: start;
}
.settings-side {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 0.85rem;
  box-shadow: var(--shadow);
}
.settings-side-title {
  margin: 0 0 0.65rem;
  font-family: var(--display);
  font-weight: 600;
  color: var(--brand);
}
.settings-side-nav {
  display: grid;
  gap: 0.25rem;
}
.settings-side-nav a {
  padding: 0.5rem 0.7rem;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}
.settings-side-nav a:hover,
.settings-side-nav a.active {
  background: var(--brand-soft);
  color: var(--brand);
  text-decoration: none;
}
.settings-side-note {
  margin: 0.85rem 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
}
.settings-main { min-width: 0; }

/* Page header: title + primary action on one row; description below */
.page-header {
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}
.page-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header-top h2 {
  margin: 0;
  line-height: 1.25;
  flex: 1 1 auto;
  min-width: 8rem;
}
.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}
.page-header-actions .btn {
  white-space: nowrap;
}
.page-header-desc {
  margin: 0.45rem 0 0;
  max-width: 52rem;
  line-height: 1.5;
}

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.hub-card {
  display: grid;
  gap: 0.35rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}
.hub-card:hover {
  border-color: var(--brand);
  text-decoration: none;
}
.hub-card strong { font-family: var(--display); color: var(--brand); }

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.filter-row .pill {
  text-decoration: none;
  border: 1px solid transparent;
}
.filter-row .pill:hover { border-color: var(--line); }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.7rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  line-height: 1.4;
}
.admin-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
  white-space: nowrap;
  background: rgba(215, 227, 221, 0.35);
}
.admin-table tbody tr:hover {
  background: rgba(247, 250, 248, 0.9);
}
.admin-table th.col-actions,
.admin-table td.actions-cell {
  text-align: right;
  width: 7.5rem;
  min-width: 7.5rem;
  white-space: nowrap;
}
.admin-table th.col-notes,
.admin-table td.col-notes {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.actions-cell {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
}
.actions-cell a {
  margin: 0;
  text-decoration: none;
  flex: 0 0 auto;
}
.actions-cell a:hover { text-decoration: underline; }
.row-inactive { opacity: 0.65; }

.admin-form {
  max-width: 640px;
  display: grid;
  gap: 0.9rem;
}
.admin-form.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}
@media (min-width: 720px) {
  .admin-form.form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .admin-form.form-grid > label:has(input[type="checkbox"]),
  .admin-form.form-grid > .check-inline,
  .admin-form.form-grid > .form-actions,
  .admin-form.form-grid > .span-2 {
    grid-column: 1 / -1;
  }
}
.form-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 0.25rem;
}
.subpanel {
  border-top: 1px solid var(--line);
  margin-top: 1.25rem;
  padding-top: 1rem;
}
.subpanel h3, .subpanel h4 {
  margin: 0 0 0.75rem;
  font-family: var(--display);
  font-size: 1.15rem;
}
.confirm-box {
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin: 0;
}
.confirm-box h2 { margin-top: 0; }
.check-inline {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  grid-auto-flow: column;
}
.check-inline input { width: auto; margin: 0; }

@media (min-width: 900px) {
  .settings-layout {
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 1.25rem;
  }
  .settings-side {
    position: sticky;
    top: 0.75rem;
  }
  .shell { width: min(1180px, calc(100% - 1.5rem)); }
}

@media (min-width: 860px) {
  .shell { padding-bottom: 2rem; }
  .save-bar { bottom: 1rem; }
  .nav {
    position: sticky;
    top: 0;
    bottom: auto;
    grid-template-columns: repeat(3, max-content);
    justify-content: start;
    gap: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    margin-bottom: 1rem;
    padding: 0.4rem;
    background: rgba(255, 253, 248, 0.9);
  }
  .nav a { padding: 0.55rem 0.9rem; }
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .item { grid-template-columns: 6rem 1fr auto; }
}

@media (max-width: 640px) {
  .brand span { display: none; }
  .item { grid-template-columns: 4.6rem 1fr; }
  .item .actions { grid-column: 1 / -1; }
}
