:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0d100e;
  --surface: #151a17;
  --surface-2: #202621;
  --surface-3: #111512;
  --text: #edf1ed;
  --muted: #99a39b;
  --line: #303831;
  --accent: #6bab82;
  --accent-strong: #9bc9aa;
  --accent-soft: #193325;
  --danger: #e28a8a;
  --shadow: 0 14px 42px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; color: var(--text); background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 68px;
  padding: 12px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}
.brand-row, .top-actions, .primary-nav, .month-controls { display: flex; align-items: center; }
.brand-row { gap: 26px; }
.brand {
  border: 0;
  background: transparent;
  padding: 0;
  font-weight: 760;
  font-size: 20px;
  letter-spacing: -0.02em;
  cursor: pointer;
}
.primary-nav { gap: 4px; }
.nav-button, .filter-bar button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 8px 11px;
  cursor: pointer;
  color: var(--muted);
}
.nav-button.active, .filter-bar button.active { color: var(--text); background: var(--surface-2); font-weight: 650; }
.top-actions { gap: 8px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(280px, 30vw);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px 10px;
  color: var(--muted);
}
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.primary-button, .secondary-button, .danger-button, .text-button, .icon-button {
  border-radius: 9px;
  cursor: pointer;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: #08100a; padding: 8px 14px; font-weight: 700; }
.primary-button:hover { background: var(--accent-strong); }
.secondary-button { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; }
.secondary-button.active { border-color: #527a5e; background: var(--accent-soft); color: var(--accent-strong); }
.danger-button { border: 1px solid #633d3d; background: #2a1818; color: var(--danger); padding: 8px 14px; }
.text-button { border: 0; background: transparent; padding: 7px 9px; color: var(--muted); }
.text-button:hover { background: var(--surface-2); color: var(--text); }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); background: var(--surface); font-size: 20px; line-height: 1; }

.data-menu {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  box-shadow: var(--shadow);
  background: var(--surface);
  color: var(--text);
}
.data-menu button { display: block; width: 100%; text-align: left; border: 0; border-radius: 7px; background: transparent; padding: 9px 12px; cursor: pointer; }
.data-menu button:hover { background: var(--surface-2); }

main { padding: 28px clamp(16px, 4vw, 52px) 70px; }
.panel { max-width: 1180px; margin: 0 auto; }
.panel-heading, .calendar-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: clamp(27px, 3vw, 34px); letter-spacing: -0.035em; }
h2 { margin-bottom: 0; font-size: 21px; }
.muted { color: var(--muted); margin: 0; }
.filter-bar { display: flex; gap: 4px; overflow-x: auto; padding: 2px 0 14px; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar button { white-space: nowrap; }

.task-list { display: grid; gap: 10px; }
.task-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  padding: 15px 15px 13px;
}
.task-main { min-width: 0; display: flex; align-items: flex-start; gap: 12px; flex: 1; }
.complete-button { flex: 0 0 auto; width: 21px; height: 21px; margin-top: 2px; border-radius: 50%; border: 1.5px solid #667069; background: transparent; cursor: pointer; }
.complete-button:hover { border-color: var(--accent); box-shadow: inset 0 0 0 5px var(--accent-soft); }
.task-copy { min-width: 0; flex: 1; }
.task-title-row { display: flex; align-items: flex-start; gap: 9px; flex-wrap: wrap; }
.task-title-row h3 { margin: 0; font-size: 16px; line-height: 1.35; }
.status-pill { border-radius: 999px; padding: 3px 7px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.status-pill.ready { background: var(--accent-soft); color: var(--accent-strong); }
.status-pill.quiet { background: var(--surface-2); color: var(--muted); }
.status-pill.sleeping { background: #29243a; color: #c3b5e2; }
.notes { margin: 5px 0 0; color: #c3cac4; white-space: pre-wrap; overflow-wrap: anywhere; }
.timing { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag { border-radius: 999px; background: #252b26; padding: 3px 7px; font-size: 11px; color: #adb6af; }
.task-actions { display: flex; gap: 2px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.empty-state { border: 1px dashed #3b443d; border-radius: 14px; padding: 38px 24px; text-align: center; color: var(--muted); }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { color: var(--text); margin-bottom: 4px; }

.calendar-toolbar { margin-bottom: 18px; }
.month-controls { gap: 5px; }
.calendar-heading-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.calendar-toolbar h1 { min-width: 210px; text-align: right; }
.calendar-sleep-toggle { white-space: nowrap; font-size: 12px; }
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--surface);
}
.weekday { padding: 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.calendar-day { min-height: 126px; padding: 7px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); overflow: hidden; }
.calendar-day.outside { background: var(--surface-3); color: #626b64; }
.day-number { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; margin-bottom: 4px; font-size: 12px; }
.calendar-day.today .day-number { background: var(--accent); color: #08100a; font-weight: 700; }
.calendar-chip { display: block; width: 100%; margin: 3px 0; border: 0; border-radius: 5px; padding: 4px 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; font-size: 11px; cursor: pointer; }
.calendar-chip.event { background: #213047; color: #b9cbed; }
.calendar-chip.task.start { background: #1c3425; color: #b0d6bb; }
.calendar-chip.task.start.sleep-bypassed { outline: 1px dashed #8d79b4; background: #252235; color: #c9bde1; }
.calendar-chip.task.sleep { background: #29243a; color: #c3b5e2; }
.calendar-chip.task.latest { background: #3b3020; color: #e2c28f; }
.calendar-chip.task.due { background: #3a2323; color: #e2abab; }
.more-count { color: var(--muted); font-size: 10px; margin-top: 4px; }
.calendar-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 11px; }
.calendar-legend span { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.legend-dot.event { background: #52709a; }
.legend-dot.start { background: #4d815e; }
.legend-dot.sleep { background: #78669a; }
.legend-dot.latest { background: #9b7948; }
.legend-dot.due { background: #9a5d5d; }

.editor-dialog { width: min(680px, calc(100vw - 26px)); max-height: min(88vh, 860px); border: 1px solid var(--line); border-radius: 16px; padding: 0; box-shadow: var(--shadow); background: var(--surface); color: var(--text); }
.editor-dialog::backdrop { background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(2px); }
.editor-dialog form { padding: 20px; overflow-y: auto; max-height: 88vh; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.kind-switch { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 9px; margin-bottom: 18px; }
.segmented label input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label span { display: block; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.segmented label input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.28); font-weight: 650; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field { display: grid; gap: 6px; margin-bottom: 13px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid #3c453e; border-radius: 9px; background: #101411; padding: 9px 10px; color: var(--text);
}
.field.disabled { opacity: 0.48; }
.field textarea { resize: vertical; min-height: 88px; }
.full { width: 100%; }
.schedule-box { margin-top: 5px; border: 1px solid var(--line); border-radius: 12px; padding: 13px; background: var(--surface-3); }
.toggle-row { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; }
.toggle-row input { margin-top: 3px; }
.toggle-row span { display: grid; gap: 2px; }
.toggle-row small { color: var(--muted); line-height: 1.35; }
.schedule-options { margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--line); }
.schedule-options.disabled { opacity: 0.45; }
.weekday-picks { display: flex; gap: 5px; margin-bottom: 12px; }
.weekday-picks label input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-picks label span { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 11px; font-weight: 700; }
.weekday-picks label input:checked + span { background: var(--accent); border-color: var(--accent); color: #08100a; }
.time-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; translate: -50% 15px; opacity: 0; pointer-events: none; padding: 9px 13px; background: #dce7de; color: #101511; border-radius: 9px; font-size: 13px; transition: 160ms ease; z-index: 100; }
.toast.show { opacity: 1; translate: -50% 0; }
.fatal { margin: 40px auto; max-width: 700px; padding: 20px; border: 1px solid #633d3d; border-radius: 12px; background: #2a1818; }
.full-span { grid-column: 1 / -1; }
.field-hint { color: var(--muted); font-size: 11px; line-height: 1.35; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.attachment { border: 1px solid var(--line); border-radius: 7px; background: var(--surface-3); padding: 4px 7px; font-size: 11px; cursor: pointer; color: #b7c0b9; }
.attachment:hover { background: var(--surface-2); }

@media (max-width: 760px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 10px; padding: 10px 12px; }
  .brand-row { justify-content: space-between; gap: 12px; }
  .primary-nav { margin-left: auto; }
  .top-actions { width: 100%; }
  .search-box { flex: 1; width: auto; }
  main { padding: 20px 12px 72px; }
  .task-card { flex-direction: column; gap: 8px; }
  .task-actions { width: 100%; justify-content: flex-end; }
  .calendar-toolbar { align-items: flex-start; flex-direction: column-reverse; }
  .calendar-heading-actions { width: 100%; align-items: flex-start; justify-content: space-between; }
  .calendar-toolbar h1 { min-width: 0; text-align: left; }
  .calendar-grid { font-size: 10px; }
  .weekday { padding: 6px 2px; text-align: center; }
  .calendar-day { min-height: 92px; padding: 4px 3px; }
  .day-number { width: 23px; height: 23px; }
  .calendar-chip { padding: 3px; font-size: 9px; }
  .form-grid, .time-pair { grid-template-columns: 1fr; }
  .editor-dialog { width: 100vw; max-width: 100vw; max-height: 94vh; margin: auto 0 0; border-radius: 16px 16px 0 0; border-bottom: 0; }
  .editor-dialog form { max-height: 94vh; padding: 17px 14px 22px; }
  .weekday-picks { justify-content: space-between; }
  .weekday-picks label span { width: min(38px, 11vw); }
}
