/* Today — application stylesheet (Phase 2). Plain CSS, no framework. */

:root {
  --bg: #f4f2fb;
  --surface: #ffffff;
  --surface-2: #faf9fe;
  --ink: #1e1b2e;
  --ink-2: #4a4763;
  --muted: #7a7791;
  --border: #e6e3f1;
  --border-strong: #d4d0e6;
  --accent: #6b4ee6;
  --accent-ink: #4f36c4;
  --accent-soft: #ede9fc;
  --accent-soft-2: #e2dcfa;
  --ok: #2f9e6b;
  --ok-soft: #e4f6ec;
  --warn: #b86e00;
  --danger: #c43d3d;
  --danger-soft: #fdeaea;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(30, 27, 46, .04), 0 8px 24px rgba(107, 78, 230, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 232px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent-ink); }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
svg.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .4rem; }
.error { color: var(--danger); font-size: .9rem; margin-top: .3rem; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: .5rem .8rem; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }

:focus-visible { outline: 3px solid rgba(107, 78, 230, .45); outline-offset: 2px; border-radius: 6px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 1.5rem;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.brand { font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; padding: 0 .6rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .7rem; border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .3rem; padding: 0 .7rem; font-size: .9rem; }
.who { color: var(--muted); }
.link { background: none; border: 0; padding: 0; color: var(--accent-ink); text-decoration: underline; }
.mobile-bar, .nav-mobile { display: none; }

.main { padding: 2rem 2.5rem 3rem; max-width: 1280px; width: 100%; min-width: 0; }

.messages { margin: 0 0 1rem; display: flex; flex-direction: column; gap: .4rem; }
.msg { padding: .6rem .9rem; border-radius: var(--radius-sm); background: var(--ok-soft); color: #1d6d47; font-weight: 500; }
.msg.error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-title { flex: 1 1 260px; }
.eyebrow { color: var(--muted); font-weight: 500; font-size: .95rem; margin-bottom: .2rem; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.daynav { text-decoration: none; color: var(--muted); padding: 0 .35rem; border-radius: 6px; font-size: 1.2rem; line-height: 1; }
.daynav:hover { background: var(--surface); color: var(--ink); }
.daynav-back { margin-left: .5rem; font-size: .85rem; }
.search { position: relative; flex: 0 1 260px; }
.search .ic { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input {
  width: 100%; padding: .65rem .9rem .65rem 2.4rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .65rem 1.1rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; white-space: nowrap; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--accent-soft); color: var(--accent-ink); }
.btn-small { padding: .4rem .85rem; min-height: 36px; font-size: .9rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted);
}
.icon-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-ink); }
.icon-btn.is-on { color: var(--accent-ink); background: var(--accent-soft); }
.icon-btn:disabled { opacity: .3; cursor: default; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.5rem;
}
.card.narrow { max-width: 640px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.today-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1.5rem; align-items: start; }
.side { display: grid; gap: 1.5rem; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; align-items: start; }

/* ---------- Quick add ---------- */
.quick { position: relative; margin-bottom: 1.25rem; }
.quick-label { display: block; font-weight: 650; margin-bottom: .4rem; }
.quick-row { display: flex; gap: .75rem; align-items: stretch; }
.quick textarea {
  flex: 1; resize: vertical; min-height: 64px;
  padding: .8rem 1rem; border: 1px solid var(--border-strong); border-radius: 14px;
  background: var(--surface-2); font-size: 1.05rem; line-height: 1.4;
}
.quick textarea:focus { background: var(--surface); border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(107, 78, 230, .18); }
.quick .btn-primary { align-self: flex-start; }
.suggest {
  position: absolute; z-index: 10; left: 0; right: 0; margin-top: .3rem;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(30, 27, 46, .12); overflow: hidden;
  max-width: 480px;
}
.suggest button {
  display: flex; width: 100%; justify-content: space-between; gap: 1rem; align-items: baseline;
  padding: .65rem .9rem; border: 0; background: none; text-align: left;
}
.suggest button:hover, .suggest button:focus { background: var(--accent-soft); outline: none; }
.suggest .kind { font-size: .8rem; color: var(--muted); }

/* Notices never take layout space: a fixed toast, so the schedule never shifts. */
.notice {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 40;
  width: max-content; max-width: min(640px, calc(100vw - 2rem)); margin: 0;
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .7rem .9rem .7rem 1rem; border-radius: 14px;
  background: var(--accent-ink); color: #fff; font-weight: 500; line-height: 1.35;
  box-shadow: 0 12px 32px rgba(30, 27, 46, .28);
}
.notice[hidden] { display: none; }
.notice.is-error { background: #7a1f1f; }
.notice .notice-close {
  flex: none; width: 28px; height: 28px; margin: -2px -4px -2px 0; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .15); color: #fff; display: inline-flex; align-items: center; justify-content: center;
}
.notice .notice-close:hover { background: rgba(255, 255, 255, .28); }
.notice .notice-close .ic { width: 16px; height: 16px; }
.quick textarea.has-error { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(196, 61, 61, .15); }
.js .quick-errors[data-nojs-only] { display: none; }

/* Rows you just added or changed light up briefly, so your eyes find them without scrolling or shifting. */
@keyframes row-flash {
  0%   { background: var(--accent-soft-2); box-shadow: inset 3px 0 0 var(--accent); }
  70%  { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
  100% { background: transparent; box-shadow: none; }
}
.row.is-new { animation: row-flash 3.2s ease-out both; }
@media (prefers-reduced-motion: reduce) { .row.is-new { animation: none; box-shadow: inset 3px 0 0 var(--accent); background: var(--accent-soft); } }

/* ---------- Review ---------- */
.review { margin-bottom: 1.25rem; padding: 1rem 1.1rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; }
.review-list { margin-top: .75rem; display: grid; gap: .5rem; }
.review-list form { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.review-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---------- Schedule ---------- */
/* Fixed-shape header: the summary text can change length without wrapping the
   "Day starts" control onto a new line (which would push every row down). */
.schedule-head {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center;
  gap: .75rem; margin-bottom: .5rem; min-height: 40px;
}
.schedule-head h2 { font-size: 1.25rem; }
.schedule-head .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.daystart { display: flex; align-items: center; gap: .4rem; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.daystart input { padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

.rows { display: flex; flex-direction: column; }
.row {
  display: grid;
  grid-template-columns: 36px 148px 84px minmax(0, 1fr) auto;
  grid-template-areas:
    "check time dur main actions"
    ". drive drive drive drive";
  align-items: center; gap: .35rem .75rem;
  padding: .8rem .5rem; border-top: 1px solid var(--border);
  font-size: 1.05rem; border-radius: 10px;
}
.row-drive { grid-area: drive; min-width: 0; }
.row-drive:empty { display: none; }
.range, .dur-btn, .dur-static { white-space: nowrap; }
.mer { font-size: .68em; font-weight: 700; letter-spacing: .06em; margin-left: .35em; color: var(--muted); vertical-align: .08em; }
.state-locked .mer, .state-fixed .mer { color: var(--accent-ink); }
.row-gap { padding-top: .45rem; padding-bottom: .45rem; font-size: .95rem; color: var(--muted); }
.row-gap .row-time { color: var(--muted); font-weight: 400; }
.dur-static { display: inline-block; padding: .3rem .6rem; font-variant-numeric: tabular-nums; font-weight: 500; color: var(--muted); }
.gap-link {
  display: inline-flex; align-items: center; gap: .4rem; min-height: 36px; padding: .25rem .75rem;
  border: 1px dashed var(--border-strong); border-radius: 999px; color: var(--muted);
  text-decoration: none; font-style: italic; font-weight: 500;
}
.gap-link::before { content: "+"; font-style: normal; font-weight: 700; color: var(--accent); }
.gap-link:hover, .gap-link:focus-visible { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.quick-errors { margin: .5rem 0 0; display: grid; gap: .3rem; padding: .6rem .9rem; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: .9rem; }
.row:first-child { border-top: 0; }
.row.is-dragging { opacity: .4; }
.row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.row.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.row-check { grid-area: check; }
.row-time { grid-area: time; font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 500; font-size: 1rem; }
.row-dur { grid-area: dur; }
.row-main { grid-area: main; min-width: 0; }
.row-actions { grid-area: actions; display: flex; align-items: center; gap: .1rem; }
.state-locked .row-time, .state-fixed .row-time { color: var(--accent-ink); font-weight: 650; }
.is-done .title { text-decoration: line-through; color: var(--muted); }
.is-done .row-time, .is-done .dur-btn { color: var(--muted); }
.is-skipped .title { color: var(--muted); }

.check {
  width: 32px; height: 32px; border-radius: 10px; border: 2px solid var(--border-strong);
  background: var(--surface); color: transparent; display: inline-flex; align-items: center; justify-content: center;
}
.check:hover { border-color: var(--accent); }
.check[aria-checked="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }

.dur-btn {
  padding: .3rem .6rem; border-radius: 8px; border: 1px dashed transparent;
  background: transparent; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink);
}
.dur-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.dur-edit { display: flex; align-items: center; gap: .3rem; }
.dur-edit input { width: 5.5em; padding: .35rem .5rem; border: 1px solid var(--accent); border-radius: 8px; font-weight: 600; }
.dur-edit .icon-btn { width: 34px; height: 34px; }
.dur-error { grid-column: 1 / -1; color: var(--danger); font-size: .85rem; padding-left: 4px; }

.title { font-weight: 600; color: var(--ink); text-decoration: none; display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
.title:hover { color: var(--accent-ink); text-decoration: underline; }
.meta { display: flex; flex-wrap: wrap; gap: .25rem .75rem; color: var(--muted); font-size: .85rem; margin-top: .1rem; }
.tag { display: inline-flex; align-items: center; gap: .25rem; font-weight: 600; }
.tag .ic { width: 14px; height: 14px; }
.tag-fixed, .tag-locked { color: var(--accent-ink); }
.grip { color: var(--border-strong); cursor: grab; padding: 0 .2rem; display: inline-flex; }
.row[draggable="true"]:hover .grip { color: var(--muted); }
.move { display: flex; flex-direction: column; }
.move .icon-btn { width: 30px; height: 22px; border-radius: 6px; }
.move .icon-btn .ic { width: 16px; height: 16px; }

/* ---------- Drive ---------- */
.drive { margin-top: .2rem; padding: .7rem .9rem; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.drive-label { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--ink-2); font-weight: 600; flex-wrap: wrap; }
.drive-label .muted { font-weight: 400; }
.drive-list { margin-top: .3rem; display: grid; gap: .1rem; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.sub {
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
  padding: .45rem .3rem; border: 0; background: none; border-radius: 8px; font-size: 1rem;
}
.sub:hover { background: var(--accent-soft); }
.sub-box { width: 20px; height: 20px; border: 2px solid var(--border-strong); border-radius: 6px; flex: none; }
.sub.is-done { color: var(--muted); text-decoration: line-through; }
.sub.is-done .sub-box { background: var(--ok); border-color: var(--ok); }

/* ---------- Side lists ---------- */
.held-list { display: grid; gap: .5rem; margin-top: .75rem; }
.held-list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .5rem 0; border-top: 1px solid var(--border); }
.held-list li:first-child { border-top: 0; padding-top: 0; }
.held-title { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.side .muted { margin-top: .5rem; display: block; }

/* ---------- Library ---------- */
.list li { display: flex; flex-direction: column; gap: .1rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list a { font-weight: 600; text-decoration: none; color: var(--ink); }
.list a:hover { color: var(--accent-ink); }
.list .is-archived a { color: var(--muted); }
.list .muted { font-size: .85rem; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field input:not([type="checkbox"]), .field select, .field textarea {
  width: 100%; padding: .6rem .8rem; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(107, 78, 230, .18); }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field-check { display: grid; grid-template-columns: auto 1fr; column-gap: .5rem; align-items: center; }
.field-check input { width: 20px; height: 20px; accent-color: var(--accent); }
.field-check label { margin: 0; }
.field-check .hint, .field-check .error { grid-column: 2; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.editor-actions { display: flex; gap: .5rem; margin-top: .5rem; }
.editor-secondary { display: flex; gap: .5rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

dialog.editor { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 2rem)); box-shadow: 0 24px 64px rgba(30, 27, 46, .25); }
dialog.editor::backdrop { background: rgba(30, 27, 46, .35); }
dialog.editor .editor-body { padding: 1.5rem; max-height: calc(100vh - 4rem); overflow: auto; }

.soon { display: grid; gap: 1rem; justify-items: start; }

/* ---------- Auth ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: min(400px, 100%); display: grid; gap: .75rem; }
.auth-card .brand { padding: 0; color: var(--accent-ink); }
.auth-card form { display: grid; gap: .25rem; margin-top: .5rem; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .today-grid { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; }
  .main { padding: 1.5rem; }
}

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .mobile-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
  }
  .mobile-bar .brand { padding: 0; }
  .link.small { font-size: .9rem; }
  .nav-mobile {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
  }
  .nav-mobile a { flex-direction: column; gap: .15rem; padding: .35rem .2rem; font-size: .7rem; font-weight: 600; border-radius: 8px; min-height: 48px; }
  .nav-mobile a[aria-current="page"] { background: transparent; }
  .main { padding: 1rem 1rem 6rem; }
  .notice { bottom: calc(4.6rem + env(safe-area-inset-bottom)); width: auto; left: 1rem; right: 1rem; transform: none; max-width: none; }
  h1 { font-size: 1.5rem; }
  .page-head { margin-bottom: 1rem; }
  .page-head .btn-primary { order: 3; flex: 1 1 100%; }
  .search { flex: 1 1 100%; }
  .card { padding: 1rem; }
  .quick-row { flex-direction: column; }
  .quick .btn-primary { align-self: stretch; }
  /* One column: heading, summary, day-start — each a fixed-height row. */
  .schedule-head { grid-template-columns: minmax(0, 1fr); gap: .25rem; }
  .schedule-head .muted { font-size: .9rem; }
  .daystart { margin-top: .25rem; }
  .grip { display: none; }

  .row {
    grid-template-columns: 40px auto minmax(0, 1fr);
    grid-template-areas:
      "check time dur"
      "check main main"
      "check drive drive"
      "check actions actions";
    gap: .2rem .6rem; padding: .8rem .25rem; font-size: 1rem;
  }
  .row-check { align-self: start; padding-top: .15rem; }
  .row-actions { justify-self: end; gap: .35rem; }
  .row-drive { grid-area: drive; }
  .move { flex-direction: row; }
  .move .icon-btn { width: 40px; height: 40px; border-radius: 10px; }
  .move .icon-btn .ic { width: 18px; height: 18px; }
  .drive-list { grid-template-columns: 1fr; }
  .row-time { font-size: .95rem; }
  .dur-btn { padding: .3rem .4rem; }
  .row-main { padding-top: .1rem; }
  .icon-btn { width: 40px; height: 40px; }
}

@media (max-width: 380px) {
  .row { grid-template-columns: 36px auto minmax(0, 1fr); gap: .2rem .4rem; }
  .row-time { font-size: .9rem; }
  .icon-btn, .move .icon-btn { width: 36px; height: 36px; }
  .btn-small { padding: .35rem .65rem; }
}
