@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@500;600;700;800&display=swap');

:root {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #334954;
  background: #fff;
  --ink: #334954;
  --muted: #71828a;
  --line: #b9cbd5;
  --blue: #547f9d;
  --blue-light: #87b4c7;
  --blue-soft: #edf4f7;
  --green: #82a88a;
  --red: #bd6259;
  --red-soft: #fff3f1;
  --card: #fff;
  --surface: #f3f7f9;
  --radius: 18px;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #fff; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}
.app-shell { width: min(100%, 510px); margin: 0 auto; padding: 24px 22px calc(18px + env(safe-area-inset-bottom)); }
.view-stage { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "view"; min-width: 0; }
.view { grid-area: view; min-width: 0; align-self: stretch; }
.view.hidden { display: block !important; visibility: hidden; pointer-events: none; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin: 2px 0 21px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; color: var(--ink); font: 700 30px/1.15 Manrope, sans-serif; letter-spacing: -.04em; }
.topbar-date { margin: 5px 0 0; color: var(--muted); font-size: 15px; }
.streak-pill { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 6px; margin-top: 4px; padding: 9px 12px; border-radius: 999px; background: var(--surface); color: var(--ink); }
.streak-pill span { color: var(--blue); font-size: 16px; }
.streak-pill b { font: 700 16px Manrope, sans-serif; }
.streak-pill small { color: var(--muted); font-size: 12px; }

.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin: 0 -3px 25px; }
.week-day { display: grid; justify-items: center; gap: 5px; min-height: 54px; padding: 8px 2px; border-radius: 14px; background: var(--blue-soft); color: #66808c; font-size: 12px; line-height: 1.2; }
.week-day b { color: var(--blue); font-size: 14px; font-weight: 600; }
.week-day.is-today { background: var(--blue); color: #fff; }
.week-day.is-today b { color: #fff; }

.task-section { margin: 0 0 22px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.section-heading h2, .overdue-section h2 { margin: 0; font-size: 18px; font-weight: 600; }
.section-count { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 500; }
.timeline { position: relative; display: grid; }
.timeline::before { content: ''; position: absolute; z-index: 0; left: 94px; top: 25px; bottom: 25px; width: 3px; border-radius: 999px; background: linear-gradient(to bottom, var(--blue) 0 40%, var(--line) 40% 100%); }
.timeline-event { position: relative; z-index: 1; display: grid; grid-template-columns: 58px 50px minmax(0, 1fr) auto; align-items: center; column-gap: 12px; min-height: 76px; }
.task-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.time-island { position: relative; z-index: 1; display: grid; place-items: center; width: 50px; height: 50px; padding: 0; border: 0; border-radius: 50%; background: var(--blue); color: #fff; }
.time-island .island-symbol { font-size: 20px; line-height: 1; }
.timeline-event.is-current .time-island { background: var(--blue-light); color: #fff; }
.timeline-event.is-complete .time-island { background: #dce9ed; color: var(--blue); }
.timeline-event.is-complete .island-symbol { font-size: 22px; }
.timeline-task { min-width: 0; padding: 12px 0; }
.timeline-task-title { overflow-wrap: anywhere; color: var(--ink); font-size: 16px; font-weight: 600; line-height: 1.35; }
.is-complete .timeline-task-title { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.timeline-task-note { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.timeline-actions { display: flex; align-items: center; gap: 3px; }
.icon-action { display: grid; place-items: center; width: 27px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: #84949b; font-size: 18px; }
.icon-action:hover { background: var(--blue-soft); color: var(--blue); }
.empty-state { display: flex; align-items: center; flex-direction: column; padding: 28px 20px; color: var(--ink); text-align: center; }
.empty-state > span { margin-bottom: 8px; font-size: 25px; }
.empty-state b { font-size: 15px; }
.empty-state p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.overdue-section { margin: 0 0 22px; padding: 14px; border-radius: 16px; background: var(--red-soft); }
.overdue-section h2 { display: flex; align-items: center; gap: 8px; color: #a45149; font-size: 15px; }
.section-dot { width: 8px; height: 8px; border-radius: 50%; background: #d7776d; }
.overdue-list { display: grid; gap: 8px; margin-top: 11px; }
.task-card { display: flex; align-items: flex-start; gap: 11px; padding: 11px 10px; border-radius: 12px; background: #fff; }
.check-button { display: grid; flex: 0 0 auto; place-items: center; width: 21px; height: 21px; padding: 0; border: 1.5px solid #8da4ad; border-radius: 50%; background: #fff; color: #fff; font-size: 13px; }
.check-button:hover { border-color: var(--blue); }
.task-card.is-complete .check-button { border-color: var(--blue); background: var(--blue); }
.task-content { min-width: 0; flex: 1; }
.task-title { color: var(--ink); font-size: 14px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.task-description { margin: 5px 0 0; color: var(--muted); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.tag { padding: 4px 8px; border-radius: 999px; background: var(--blue-soft); color: #66808c; font-size: 10px; }
.tag.red-tag { background: #ffe5e1; color: #a45149; }
.task-actions { display: flex; gap: 2px; }
.task-actions button { width: 25px; height: 28px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: #84949b; font-size: 17px; }
.task-actions button:hover { background: var(--blue-soft); color: var(--ink); }

.untimed-section { margin: 0 0 18px 132px; border-top: 1px solid #e1ebef; padding-top: 11px; }
.untimed-section summary { display: flex; align-items: center; gap: 7px; width: fit-content; min-height: 30px; color: var(--muted); font-size: 14px; list-style: none; }
.untimed-section summary::-webkit-details-marker { display: none; }
.untimed-section summary::before { content: '›'; color: #66808c; font-size: 21px; line-height: 1; transition: transform .15s ease; }
.untimed-section[open] summary::before { transform: rotate(90deg); }
.untimed-list { padding: 5px 0 0; }
.untimed-task { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 44px; margin-left: -30px; color: var(--ink); font-size: 15px; }
.untimed-task input { appearance: none; display: grid; place-items: center; width: 20px; height: 20px; margin: 0; border: 1.5px solid #8da4ad; border-radius: 50%; background: #fff; }
.untimed-task input::after { content: ''; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); opacity: 0; }
.untimed-task input:checked { border-color: var(--blue); background: var(--blue); }
.untimed-task input:checked::after { opacity: 1; }
.untimed-task input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.add-task-button { width: 100%; min-height: 50px; }

.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 10px 15px; border: 0; border-radius: 12px; font-size: 14px; font-weight: 600; }
.primary-button { background: var(--blue); color: #fff; }
.primary-button:hover { background: #426d8b; }
.secondary-button { background: var(--blue-soft); color: var(--blue); }
.secondary-button:hover { background: #dfeaf0; }
.secondary-button:disabled { opacity: .55; }

.bottom-nav { display: flex; justify-content: space-around; gap: 6px; margin-top: 18px; padding-top: 11px; border-top: 1px solid #e8eef1; }
.tab { flex: 1; min-height: 42px; padding: 8px 4px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; }
.tab.active { background: var(--blue-soft); color: var(--blue); font-weight: 700; }

.page-heading { margin: 2px 0 25px; }
.page-heading h1 { margin-bottom: 4px; }
.stats-period-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; color: var(--muted); font-size: 14px; }
#stats-range { min-height: 40px; padding: 8px 11px; border: 1px solid #d5e2e8; border-radius: 11px; background: #fff; color: var(--ink); font-size: 14px; }
.stat-card { margin-bottom: 15px; padding: 17px 0 18px; border-bottom: 1px solid #e1ebef; }
.stat-total-row { display: flex; align-items: baseline; gap: 10px; }
.stat-number { color: var(--ink); font: 700 34px/1 Manrope, sans-serif; letter-spacing: -.04em; }
.stat-label { color: var(--muted); font-size: 14px; }
.stats-chart { display: flex; align-items: stretch; gap: 4px; height: 180px; margin-top: 16px; }
.bar-column { display: grid; flex: 1; grid-template-rows: minmax(0, 1fr) 17px; gap: 7px; min-width: 0; height: 100%; }
.bar-track { display: flex; align-items: flex-end; justify-content: center; min-height: 0; }
.bar { width: min(22px, 75%); min-height: 3px; border-radius: 999px 999px 5px 5px; background: var(--blue-light); }
.bar.today-bar { background: var(--blue); }
.bar-label { overflow: hidden; color: var(--muted); font-size: 10px; line-height: 17px; text-align: center; white-space: nowrap; }
.bar-label.is-empty { visibility: hidden; }
.streak-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 10px; margin: 0; padding: 15px; border: 0; border-radius: 17px; background: var(--surface); }
.streak-stat, .freeze-stat { display: flex; align-items: center; gap: 9px; min-width: 0; }
.streak-icon, .freeze-icon { flex: 0 0 auto; font-size: 21px; }
.streak-stat b, .freeze-stat b { color: var(--ink); font-size: 15px; font-weight: 700; }
.streak-stat p, .freeze-stat p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.3; }
.streak-summary .secondary-button { grid-column: 1 / -1; justify-self: start; min-height: 38px; }

.panel-form { display: grid; gap: 15px; }
.panel-form > label, .form-row > label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 600; }
.panel-form input:not([type=checkbox]), .panel-form select, .panel-form textarea { width: 100%; min-height: 43px; padding: 10px 12px; border: 1px solid #d5e2e8; border-radius: 11px; background: #fff; color: var(--ink); font-size: 15px; }
.panel-form textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.optional { margin-left: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }
.weekdays { display: flex; flex-wrap: wrap; gap: 5px; }
.weekdays label { display: flex; align-items: center; gap: 5px; padding: 7px 9px; border-radius: 9px; background: var(--blue-soft); color: var(--ink); font-size: 12px; }
.weekdays input, .toggle-row input { accent-color: var(--blue); }
.toggle-row { display: flex !important; align-items: center; justify-content: space-between; }
.panel-form > .primary-button { justify-self: start; }
.settings-note { margin: 17px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

dialog { width: min(520px, calc(100% - 24px)); max-height: 90vh; padding: 24px; border: 0; border-radius: 20px; box-shadow: 0 20px 70px #1d263440; }
dialog::backdrop { background: #1e253366; backdrop-filter: blur(2px); }
dialog form { max-height: calc(90vh - 48px); overflow-y: auto; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 3px; }
.dialog-heading h2 { margin: 0; font: 700 23px Manrope, sans-serif; }
.icon-button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 9px; background: var(--blue-soft); color: var(--ink); font-size: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; z-index: 3; bottom: 24px; left: 50%; max-width: calc(100% - 32px); padding: 11px 16px; transform: translate(-50%, 20px); border-radius: 12px; background: #273840; color: #fff; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 480px) {
  .app-shell { padding: 20px 17px calc(14px + env(safe-area-inset-bottom)); }
  h1 { font-size: 28px; }
  .week-strip { gap: 4px; }
  .week-day { min-height: 52px; border-radius: 13px; }
  .timeline { --time-column: 51px; --island-column: 46px; }
  .timeline::before { left: 84px; }
  .timeline-event { grid-template-columns: var(--time-column) var(--island-column) minmax(0, 1fr) auto; column-gap: 9px; min-height: 72px; }
  .time-island { width: 46px; height: 46px; }
  .timeline-task { padding: 10px 0; }
  .timeline-task-title { font-size: 15px; }
  .timeline-actions .icon-action { width: 23px; }
  .untimed-section { margin-left: 115px; }
  .untimed-task { margin-left: -27px; grid-template-columns: 20px minmax(0, 1fr); gap: 7px; font-size: 14px; }
  .stats-chart { gap: 2px; }
  .bar-label { font-size: 9px; }
  .streak-summary { gap: 12px 6px; padding: 13px 11px; }
  .streak-stat, .freeze-stat { gap: 6px; }
  .streak-stat b, .freeze-stat b { font-size: 13px; }
  .streak-stat p, .freeze-stat p { font-size: 10px; }
  .bottom-nav { gap: 2px; }
  .tab { font-size: 12px; }
  .dialog-actions .primary-button, .dialog-actions .secondary-button { padding-inline: 11px; }
}

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