:root {
  color-scheme: light;
  --bg: #f7f7f3;
  --surface: #fff;
  --surface-soft: #f3f3ef;
  --line: #e7e7e1;
  --text: #292d3d;
  --muted: #7f8494;
  --primary: #585deb;
  --primary-soft: #eeefff;
  --danger: #dc5a55;
  --warning: #e69342;
  --success: #45a17b;
  --shadow: 0 16px 50px rgba(35, 40, 70, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
[hidden] { display: none !important; }

.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(390px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.login-card h1 { margin: 14px 0 5px; text-align: center; font-size: 26px; }
.login-card > p { margin: 0 0 26px; color: var(--muted); text-align: center; font-size: 14px; }
.brand-icon { width: 52px; height: 52px; margin: auto; display: grid; place-items: center; border: 3px solid currentColor; border-radius: 50%; color: var(--primary); font-size: 31px; font-weight: 800; line-height: 1; }
.brand-icon.small { width: 30px; height: 30px; margin: 0; border-width: 2px; font-size: 19px; }

label { display: grid; gap: 7px; margin: 0 0 15px; color: #54596b; font-size: 13px; font-weight: 600; }
input, textarea, select { width: 100%; border: 1px solid #dcdcd5; border-radius: 11px; background: #fbfbf8; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; }
input, select { min-height: 44px; padding: 0 12px; }
textarea { min-height: 112px; padding: 11px 12px; resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(88,93,235,.11); }
.form-error { min-height: 20px; margin-top: 10px; color: var(--danger); font-size: 13px; text-align: center; }

.primary, .secondary, .ghost, .danger-button { min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 650; }
.primary { color: #fff; background: var(--primary); }
.primary:hover { background: #4b50d9; }
.secondary { color: var(--primary); background: var(--primary-soft); border-color: #dfe0ff; }
.ghost { color: #5e6373; background: transparent; border-color: var(--line); }
.danger-button { color: #fff; background: var(--danger); }
.wide { width: 100%; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #646979; font-size: 20px; }
.icon-button:hover { background: #eeeef0; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; padding: 22px 14px 16px; border-right: 1px solid var(--line); background: rgba(252,252,249,.96); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 21px; font-size: 18px; font-weight: 800; }
.side-nav { display: grid; gap: 5px; }
.side-foot { margin-top: auto; display: grid; gap: 5px; }
.nav-button { width: 100%; min-height: 43px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border: 0; border-radius: 11px; background: transparent; color: #696e7e; text-align: left; }
.nav-button span:first-child { width: 24px; text-align: center; font-size: 18px; }
.nav-button:hover { background: #f0f0ed; }
.nav-button.active { color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.mobile-header, .bottom-nav { display: none; }
.main-content { min-width: 0; min-height: 100dvh; }

.page { width: min(1080px, 100%); margin: 0 auto; padding: 28px 30px 54px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0 0 4px; font-size: 25px; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; gap: 9px; }
.card { border: 1px solid var(--line); border-radius: 17px; background: var(--surface); }
.section { margin-top: 20px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 15px; }
.count { min-width: 22px; padding: 2px 7px; border-radius: 20px; background: #ececf0; color: #747989; font-size: 11px; text-align: center; }

.capture { overflow: hidden; margin-bottom: 18px; }
.capture summary { min-height: 54px; display: flex; align-items: center; gap: 10px; padding: 0 16px; list-style: none; cursor: pointer; font-weight: 750; }
.capture summary::-webkit-details-marker { display: none; }
.capture summary::after { content: "⌄"; margin-left: auto; color: var(--muted); }
.capture[open] summary::after { transform: rotate(180deg); }
.capture .capture-body { padding: 0 16px 16px; }
.capture textarea { min-height: 86px; }
.capture-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.capture-hint { color: var(--muted); font-size: 12px; }

.overview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 22px; }
.metric { padding: 14px; }
.metric b { display: block; margin-top: 5px; font-size: 23px; }
.metric span { color: var(--muted); font-size: 12px; }

.task-list { display: grid; gap: 8px; }
.task { min-width: 0; display: grid; grid-template-columns: 30px minmax(0,1fr) auto; align-items: start; gap: 10px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); transition: border-color .15s, transform .15s, box-shadow .15s; }
.task:hover { border-color: #d6d7ef; box-shadow: 0 6px 20px rgba(43,47,80,.06); transform: translateY(-1px); }
.task-check { width: 22px; height: 22px; margin: 1px 0 0; padding: 0; border: 2px solid #c9cad3; border-radius: 50%; background: #fff; color: #fff; }
.task-check.checked { border-color: var(--success); background: var(--success); }
.task-main { min-width: 0; text-align: left; border: 0; padding: 0; background: transparent; color: inherit; }
.task-title { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.38; font-weight: 700; word-break: break-word; }
.task.completed .task-title { color: #9699a4; text-decoration: line-through; }
.task-preview { display: -webkit-box; overflow: hidden; margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.4; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; color: var(--muted); font-size: 11px; }
.tag { padding: 2px 7px; border-radius: 20px; background: #f1f1ed; }
.tag.danger { color: var(--danger); background: #fff0ef; }
.tag.today { color: #bd6c27; background: #fff3e7; }
.task-open { padding: 3px 2px; border: 0; background: transparent; color: #9a9dab; font-size: 18px; }
.empty { padding: 25px 14px; color: #a0a3ad; text-align: center; font-size: 13px; }

.time-section { margin-top: 18px; }
.time-section-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.time-section-head h2 { margin: 0; font-size: 15px; }
.time-section-head p { margin: 0; color: var(--muted); font-size: 11px; }

.calendar-card { padding: 17px; }
.calendar-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.calendar-toolbar h2 { min-width: 145px; margin: 0; font-size: 18px; }
.segmented { display: flex; padding: 3px; border-radius: 10px; background: #eeeeea; }
.segmented button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 2px 8px rgba(40,44,70,.08); font-weight: 700; }
.calendar-actions { margin-left: auto; display: flex; gap: 5px; }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: 6px; }
.calendar-weekdays div { padding: 5px; color: var(--muted); text-align: center; font-size: 11px; }
.calendar-day { position: relative; min-height: 82px; padding: 8px; border: 1px solid #ecece7; border-radius: 11px; background: #fff; color: var(--text); text-align: left; }
.calendar-day:hover { border-color: #cfd1f5; }
.calendar-day.outside { color: #b8bac2; background: #fafaf7; }
.calendar-day.selected { border-color: var(--primary); background: var(--primary-soft); }
.calendar-day.today:not(.selected) { border: 2px solid var(--warning); padding: 7px; }
.calendar-day-number { display: inline-grid; min-width: 24px; height: 24px; place-items: center; border-radius: 50%; font-size: 12px; font-weight: 650; }
.calendar-day.today .calendar-day-number { color: #fff; background: var(--warning); }
.calendar-day small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.calendar-dots { display: flex; gap: 3px; margin-top: 12px; }
.calendar-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }
.calendar-count { position: absolute; right: 7px; bottom: 7px; color: var(--primary); font-size: 10px; font-weight: 750; }
.selected-day { margin-top: 14px; padding: 15px; }
.selected-day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.selected-day-head h3 { margin: 0; font-size: 16px; }
.week-view .calendar-day { min-height: 106px; }

.teaching-banner { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; padding: 10px 13px; border: 1px solid #dfe1f8; border-radius: 12px; background: #f2f3ff; color: #555b8b; font-size: 12px; }
.teaching-banner b { color: var(--primary); }
.teaching-banner button { margin-left: auto; border: 0; background: transparent; color: var(--primary); font-weight: 700; }

.matrix-intro { margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.matrix { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); align-items: start; gap: 12px; }
.quadrant { overflow: hidden; border: 1px solid color-mix(in srgb, var(--q) 28%, white); border-radius: 16px; background: color-mix(in srgb, var(--q) 5%, white); }
.quadrant-head { display: flex; align-items: center; gap: 9px; padding: 13px 14px 10px; }
.quadrant-icon { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: color-mix(in srgb, var(--q) 13%, white); color: var(--q); }
.quadrant-head h2 { margin: 0; font-size: 15px; }
.quadrant-head p { margin: 2px 0 0; color: var(--q); font-size: 10px; }
.quadrant-head .count { margin-left: auto; }
.quadrant .task-list { padding: 0 10px 10px; }
.quadrant .task { background: rgba(255,255,255,.82); }
.quadrant .empty { padding: 12px; }

.modal { width: min(620px, calc(100% - 28px)); max-height: min(88dvh, 820px); padding: 0; border: 0; border-radius: 20px; background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(20,24,50,.22); }
.modal::backdrop { background: rgba(34,37,53,.42); backdrop-filter: blur(2px); }
.compact-modal { width: min(470px, calc(100% - 28px)); }
.settings-modal { width: min(900px, calc(100% - 28px)); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 17px 19px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 19px; overflow: auto; }
.modal-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 9px; padding: 13px 19px; border-top: 1px solid var(--line); background: rgba(255,255,255,.96); }
.detail-title { margin: 0 0 12px; font-size: 22px; line-height: 1.4; word-break: break-word; }
.detail-summary { margin: 0 0 16px; padding: 14px; border-radius: 12px; background: #f5f5f1; line-height: 1.65; white-space: pre-wrap; }
.detail-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.detail-field { padding: 11px; border: 1px solid var(--line); border-radius: 11px; }
.detail-field span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.source-details { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; }
.source-details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.source-details p { margin: 10px 0 0; color: #5d6272; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

.settings-tabs { display: flex; gap: 5px; padding: 10px 14px 0; border-bottom: 1px solid var(--line); }
.settings-tabs button { min-height: 39px; padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); }
.settings-tabs button.active { border-color: var(--primary); color: var(--primary); font-weight: 750; }
.settings-section h3 { margin: 0 0 5px; }
.settings-section > p { margin: 0 0 18px; color: var(--muted); font-size: 12px; }
.user-list { display: grid; gap: 9px; }
.user-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.user-row h4 { margin: 0 0 4px; }
.user-row p { margin: 0; color: var(--muted); font-size: 11px; }
.user-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.user-actions button { min-height: 32px; padding: 0 9px; font-size: 11px; }
.badge { display: inline-block; margin-left: 6px; padding: 2px 6px; border-radius: 20px; background: var(--primary-soft); color: var(--primary); font-size: 9px; vertical-align: 2px; }

.busy { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 9px; padding: 10px 16px; border-radius: 40px; background: #2f3344; color: #fff; box-shadow: var(--shadow); font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; z-index: 110; left: 50%; bottom: 26px; max-width: calc(100% - 30px); transform: translate(-50%, 16px); padding: 10px 16px; border-radius: 10px; background: #303444; color: #fff; opacity: 0; pointer-events: none; transition: .2s; font-size: 13px; }
.toast.show { transform: translate(-50%,0); opacity: 1; }
.toast.error { background: #b74843; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .mobile-header { position: sticky; top: 0; z-index: 20; height: 46px; display: flex; align-items: center; justify-content: space-between; padding: env(safe-area-inset-top) 10px 0 14px; border-bottom: 1px solid rgba(231,231,225,.86); background: rgba(247,247,243,.92); backdrop-filter: blur(12px); }
  .mobile-context { min-width: 0; font-size: 14px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .header-actions { display: flex; }
  .bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: calc(58px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4,1fr); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); }
  .bottom-nav button { display: grid; place-items: center; align-content: center; gap: 1px; border: 0; background: transparent; color: #8a8e9c; font-size: 10px; }
  .bottom-nav button span { font-size: 19px; line-height: 1.1; }
  .bottom-nav button.active { color: var(--primary); font-weight: 750; }
  .main-content { min-height: calc(100dvh - 46px); }
  .page { padding: 12px 11px calc(76px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 11px; align-items: center; }
  .page-head h1, .page-head p { display: none; }
  .head-actions { margin-left: auto; }
  .head-actions .desktop-only { display: none; }
  .capture { margin-bottom: 12px; border-radius: 14px; }
  .capture summary { min-height: 46px; padding: 0 13px; font-size: 13px; }
  .capture .capture-body { padding: 0 12px 12px; }
  .capture-actions { align-items: flex-end; }
  .capture-hint { max-width: 58%; font-size: 10px; }
  .overview { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; margin-bottom: 14px; }
  .metric { padding: 9px 7px; border-radius: 11px; text-align: center; }
  .metric b { margin-top: 2px; font-size: 18px; }
  .metric span { font-size: 9px; }
  .section { margin-top: 15px; }
  .task { grid-template-columns: 28px minmax(0,1fr) 18px; padding: 10px; gap: 7px; border-radius: 12px; }
  .task-title { font-size: 14px; }
  .task-preview { font-size: 11px; -webkit-line-clamp: 1; }
  .time-section { margin-top: 15px; }
  .time-section-head p { display: none; }
  .calendar-card { padding: 10px; border-radius: 14px; }
  .calendar-toolbar { flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
  .calendar-toolbar h2 { min-width: 120px; font-size: 15px; }
  .calendar-actions { margin-left: 0; }
  .calendar-actions .teaching-button { display: none; }
  .calendar-weekdays, .calendar-grid { gap: 2px; }
  .calendar-day { min-height: 52px; padding: 4px; border-radius: 8px; }
  .calendar-day.today:not(.selected) { padding: 3px; }
  .calendar-day-number { min-width: 20px; height: 20px; font-size: 10px; }
  .calendar-day small { display: none; }
  .calendar-dots { margin-top: 6px; }
  .calendar-count { right: 4px; bottom: 3px; font-size: 8px; }
  .week-view .calendar-day { min-height: 66px; }
  .selected-day { margin-top: 9px; padding: 11px; }
  .teaching-banner { margin-bottom: 9px; padding: 8px 10px; }
  .matrix { grid-template-columns: 1fr; gap: 9px; }
  .matrix-intro { margin: 0 2px 10px; }
  .quadrant-head { padding: 10px 11px 8px; }
  .quadrant .task-list { padding: 0 7px 7px; }
  .quadrant .empty { padding: 7px; }
  .modal { width: calc(100% - 16px); max-height: calc(100dvh - 16px); border-radius: 17px; }
  .modal-head { padding: 13px 14px; }
  .modal-body { padding: 14px; }
  .modal-actions { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .detail-title { font-size: 19px; }
  .detail-grid, .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .settings-tabs { overflow-x: auto; padding-left: 9px; }
  .settings-tabs button { white-space: nowrap; }
  .user-row { grid-template-columns: 1fr; }
  .user-actions { justify-content: flex-start; }
  .busy, .toast { bottom: calc(70px + env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
  .login-card { padding: 26px 20px; }
  .overview { grid-template-columns: repeat(2,1fr); }
  .calendar-toolbar .segmented { order: 3; }
  .calendar-day { min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
