/* Newli Time: Apple HIG styling shared with Newli Agenda. Weights 400/500/600 only, no text-transform.
   Light = :root, Dark = [data-theme="dark"], System = prefers-color-scheme when no data-theme is set.
   Newli magenta is a UI accent only (selection, toggles, weekend marks), never in the logo. */
:root {
  color-scheme: light;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --bg: #FFFFFF; --soft: #F6F6F5; --elev: #FFFFFF;
  --text: #111111; --text-2: #6B6B6B; --text-3: #8A8A8A;
  --hairline: #EDEDED; --hairline-strong: #D9D9D7;
  --accent: #FF2E8A; --accent-ink: #FFFFFF; --accent-soft: rgba(255, 46, 138, .10);
  --primary: #111111; --primary-ink: #FFFFFF;
  --gap: #E4E4E2;
  --c-day: #FFFFFF; --c-day-ink: #111111;
  --c-eve: #EAF0F7; --c-eve-ink: #2A2E39;
  --c-night: #2B2F3A; --c-night-ink: #EEEEF1;
  --c-wkend: rgba(255, 46, 138, .07);
  --shadow-pop: 0 18px 48px rgba(17, 17, 17, .18), 0 0 0 1px rgba(17, 17, 17, .06);
  --scrim: rgba(17, 17, 17, .28);
  --toast-bg: #111111; --toast-ink: #FFFFFF;
  --cw: 34px; --ch: 44px;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111216; --soft: #1A1B20; --elev: #1A1B20;
  --text: #F2F2F0; --text-2: #9E9EA4; --text-3: #7E7E86;
  --hairline: #26272D; --hairline-strong: #34353C;
  --accent: #FF2E8A; --accent-ink: #FFFFFF; --accent-soft: rgba(255, 46, 138, .16);
  --primary: #F2F2F0; --primary-ink: #111111;
  --gap: #111216;
  --c-day: #555966; --c-day-ink: #FFFFFF;
  --c-eve: #2C2E36; --c-eve-ink: #D6D6DB;
  --c-night: #16171B; --c-night-ink: #8E8E96;
  --c-wkend: rgba(255, 46, 138, .12);
  --shadow-pop: 0 18px 48px rgba(0, 0, 0, .6), 0 0 0 1px #2E2F36;
  --scrim: rgba(0, 0, 0, .5);
  --toast-bg: #F2F2F0; --toast-ink: #111111;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --bg: #111216; --soft: #1A1B20; --elev: #1A1B20;
    --text: #F2F2F0; --text-2: #9E9EA4; --text-3: #7E7E86;
    --hairline: #26272D; --hairline-strong: #34353C;
    --accent-soft: rgba(255, 46, 138, .16);
    --primary: #F2F2F0; --primary-ink: #111111;
    --gap: #111216;
    --c-day: #555966; --c-day-ink: #FFFFFF;
    --c-eve: #2C2E36; --c-eve-ink: #D6D6DB;
    --c-night: #16171B; --c-night-ink: #8E8E96;
    --c-wkend: rgba(255, 46, 138, .12);
    --shadow-pop: 0 18px 48px rgba(0, 0, 0, .6), 0 0 0 1px #2E2F36;
    --scrim: rgba(0, 0, 0, .5);
    --toast-bg: #F2F2F0; --toast-ink: #111111;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 400 17px/22px var(--font-ui); letter-spacing: -0.012em;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  overflow-x: hidden; min-height: 100vh; min-height: 100dvh;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  padding-bottom: calc(env(safe-area-inset-bottom) + 88px);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; letter-spacing: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, .strip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
[hidden] { display: none !important; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  height: calc(48px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
/* header wordmark: official Newli logo (black in light, white in dark; never colored) + lowercase "time", as in Agenda.
   The logo's letters fill the image height, so the image bottom sits on the text baseline and its height matches the
   ascender height of "time". */
.brand { display: flex; align-items: baseline; gap: 6px; color: var(--text); min-width: 0; }
.brand .logo { display: block; height: 16px; width: auto; flex: 0 0 auto; }
.logo-dark { display: none !important; }
[data-theme="dark"] .logo-light { display: none !important; }
[data-theme="dark"] .logo-dark { display: block !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .logo-light { display: none !important; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .logo-dark { display: block !important; }
}
.wordmark { font-size: 22px; line-height: 22px; font-weight: 400; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; }
.actions { display: flex; align-items: center; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--text); flex: 0 0 auto; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--soft); }
.icon-btn[aria-pressed="true"] { background: var(--soft); color: var(--accent); }

/* ---- date bar ---- */
.datebar { display: flex; align-items: center; gap: 2px; padding: 2px 6px 10px 2px; border-bottom: 1px solid var(--hairline); }
.days { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.day {
  position: relative; flex: 1 0 auto; min-width: 44px; height: 48px; padding: 0 4px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--text);
}
.day .dw { font-size: 11px; line-height: 13px; font-weight: 500; letter-spacing: 0.01em; color: var(--text-2); }
.day .dn { font-size: 15px; line-height: 20px; font-weight: 500; white-space: nowrap; }
.day.wkend { background: var(--soft); }
.day.today:not(.sel) .dn { color: var(--accent); font-weight: 600; }
.day.sel { background: var(--accent); color: var(--accent-ink); flex-grow: 1.6; }
.day.sel .dw { color: inherit; opacity: .9; }
.day.sel .dn { font-weight: 600; }
.day .clear {
  position: absolute; top: -5px; right: -5px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--text); color: var(--bg); box-shadow: 0 0 0 2px var(--bg);
}
.day .clear svg { width: 10px; height: 10px; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.day .clear::after { content: ''; position: absolute; inset: -12px; }

.edit-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; font-size: 15px; line-height: 20px; color: var(--text-2); border-bottom: 1px solid var(--hairline); }
.edit-bar b { font-weight: 600; color: var(--text); }
.text-btn { min-height: 44px; padding: 0 14px; font-weight: 600; color: var(--accent); border-radius: 10px; }

/* ---- rows ---- */
.rows { position: relative; padding: 4px 0 0; }
.row { padding: 10px 16px 12px; border-bottom: 1px solid var(--hairline); background: var(--bg); }
.info { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.lead { flex: 0 0 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; font-size: 15px; line-height: 20px; font-weight: 500; color: var(--text-2); }
.lead svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.lead.home { color: var(--text); }
.lead.home svg { fill: currentColor; }
.name { flex: 1; min-width: 0; }
.name .label { font-size: 17px; line-height: 22px; font-weight: 600; letter-spacing: -0.012em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline; }
.name .abbr { font-size: 11px; line-height: 13px; font-weight: 500; color: var(--text-2); margin-left: 4px; vertical-align: super; letter-spacing: 0.01em; }
.name .sub { font-size: 13px; line-height: 18px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name .title { display: flex; align-items: baseline; min-width: 0; }
.time { flex: 0 0 auto; text-align: right; font-size: 22px; line-height: 28px; font-weight: 500; letter-spacing: -0.018em; white-space: nowrap; }
.time small { font-size: 15px; font-weight: 400; margin-left: 1px; color: var(--text-2); letter-spacing: 0; }
.row.is-home .time { font-weight: 600; }
.edit-ctl { display: none; align-items: center; gap: 2px; }

.strip {
  margin-top: 8px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch; border-radius: 10px; touch-action: pan-x pan-y; cursor: pointer;
}
.strip::-webkit-scrollbar { display: none; }
.cells {
  --n: 24; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 1px; width: 100%; min-width: calc(var(--n) * (var(--cw) + 1px) + 1px);
  background: var(--gap); border: 1px solid var(--gap); border-radius: 10px; overflow: hidden;
}
.cell {
  position: relative; height: var(--ch); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 13px; line-height: 15px; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap; user-select: none; -webkit-user-select: none;
}
.cell small { font-size: 9px; line-height: 11px; font-weight: 400; opacity: .78; letter-spacing: 0.01em; }
.cell.half { font-size: 11px; letter-spacing: -0.02em; }
.cell.sh-day { background: var(--c-day); color: var(--c-day-ink); }
.cell.sh-eve { background: var(--c-eve); color: var(--c-eve-ink); }
.cell.sh-night { background: var(--c-night); color: var(--c-night-ink); }
.cell.mid { font-weight: 600; }
.cell.mid small { font-size: 9px; font-weight: 600; opacity: 1; letter-spacing: 0.02em; }
.cell.mid b { font-weight: 600; font-size: 13px; }
.mark-wk .cell.wk::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent); opacity: .7; }
.mark-wk .cell.wk.sh-day { background-image: linear-gradient(var(--c-wkend), var(--c-wkend)); }
.cell.now::before { content: ''; position: absolute; top: 3px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.cell.sel { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 6px; z-index: 1; font-weight: 600; }
.frame { display: none; }

/* ---- edit mode ---- */
.editing .strip { display: none; }
.editing .row { padding-top: 6px; padding-bottom: 6px; touch-action: auto; }
.editing .time { font-size: 17px; line-height: 22px; color: var(--text-2); }
.editing .time small { font-size: 13px; }
.editing .edit-ctl { display: flex; }
@media (max-width: 599px) { .editing .time { display: none; } }
.editing .lead { flex-basis: 44px; width: 44px; height: 44px; color: var(--text-2); border: 1px solid var(--hairline-strong); }
.editing .lead.home { color: var(--bg); background: var(--text); border-color: var(--text); }
.editing .lead .offv { display: none; }
.lead .homev { display: none; }
.editing .lead .homev, .lead.home .homev { display: grid; }
.lead.home .offv { display: none; }
.ctl { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; color: var(--text-2); }
.ctl:hover { background: var(--soft); color: var(--text); }
.ctl:disabled { opacity: .3; cursor: default; }
.ctl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.handle { cursor: grab; touch-action: none; }
.row.dragging { position: relative; z-index: 5; box-shadow: var(--shadow-pop); border-radius: 12px; cursor: grabbing; transition: none; }
.row.shifting { transition: transform .16s ease; }

/* ---- now pill ---- */
.now-pill {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 15;
  display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 18px 0 14px; border-radius: 22px;
  background: var(--primary); color: var(--primary-ink); font-size: 15px; font-weight: 600; box-shadow: var(--shadow-pop);
}
.now-pill svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.now-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); order: 3; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(74px + env(safe-area-inset-bottom)); transform: translate(-50%, 8px); z-index: 60;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px; background: var(--toast-bg); color: var(--toast-ink);
  font-size: 15px; line-height: 20px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- sheets ---- */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: calc(100dvh - 40px - env(safe-area-inset-top));
  display: flex; flex-direction: column; background: var(--elev); border-radius: 16px 16px 0 0; box-shadow: var(--shadow-pop);
  padding-bottom: env(safe-area-inset-bottom); animation: sheet-up .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.tall { height: calc(100dvh - 40px - env(safe-area-inset-top)); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 4px 20px; min-height: 56px; }
.sheet-head h2 { margin: 0; font-size: 20px; line-height: 25px; font-weight: 600; letter-spacing: -0.016em; }
.sheet-head .kicker { font-size: 13px; line-height: 18px; color: var(--text-2); }
.sheet-body { overflow-y: auto; padding: 4px 20px 20px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--hairline); }
.btn { flex: 1; min-height: 44px; padding: 0 16px; border-radius: 12px; font-size: 17px; font-weight: 500; background: var(--soft); color: var(--text); }
.btn.primary { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn.danger { color: #D1343B; }
[data-theme="dark"] .btn.danger { color: #FF6B70; }

/* search */
.search-wrap { padding: 0 20px 8px; }
.search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border-radius: 12px; background: var(--soft); }
.search svg { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: var(--text-2); stroke-width: 2; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; color: var(--text); font: inherit; font-size: 17px; outline: none; }
.search input::placeholder { color: var(--text-3); }
.results { list-style: none; margin: 0; padding: 0; }
.results .group { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--text-2); padding: 12px 0 4px; }
.result { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 0; text-align: left; border-bottom: 1px solid var(--hairline); }
.result .rn { flex: 1; min-width: 0; }
.result .rn b { display: block; font-weight: 500; font-size: 17px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .rn span { display: block; font-size: 13px; line-height: 18px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .rt { text-align: right; flex: 0 0 auto; }
.result .rt b { display: block; font-weight: 500; font-size: 15px; line-height: 20px; }
.result .rt span { display: block; font-size: 13px; line-height: 18px; color: var(--text-2); }
.result.added .rn b::after { content: ' ✓'; color: var(--accent); }
.empty { padding: 24px 0; text-align: center; color: var(--text-2); font-size: 15px; }

/* calendar */
.cal-nav { display: flex; align-items: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px 0; text-align: center; }
.cal-grid .wd { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--text-2); padding: 6px 0; }
.cal-grid .wd.we, .cal-day.we { color: var(--text-2); }
.cal-day { height: 44px; display: grid; place-items: center; font-size: 17px; font-weight: 400; border-radius: 22px; margin: 0 auto; width: 44px; }
.cal-day.we { background: var(--soft); }
.cal-day.today { color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-day.sel { background: var(--accent); color: var(--accent-ink); font-weight: 600; box-shadow: none; }
.cal-day:hover:not(.sel) { background: var(--hairline); }

/* settings */
.set-group { margin: 8px 0 18px; }
.set-label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--text-2); margin: 0 0 8px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 2px; border-radius: 10px; background: var(--soft); }
.seg button { min-height: 40px; border-radius: 8px; font-size: 15px; font-weight: 500; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }
[data-theme="dark"] .seg button[aria-pressed="true"] { background: #34363F; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; border-bottom: 1px solid var(--hairline); }
.set-row span { font-size: 17px; }
.set-row small { display: block; font-size: 13px; line-height: 18px; color: var(--text-2); }
.switch { position: relative; flex: 0 0 51px; width: 51px; height: 31px; border-radius: 16px; background: var(--hairline-strong); transition: background .18s; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); transition: transform .18s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.field { width: 100%; height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--hairline-strong); background: var(--bg); color: var(--text); font: inherit; font-size: 17px; }
.hint { font-size: 13px; line-height: 18px; color: var(--text-2); margin: 8px 0 0; }

/* ---- desktop >= 900px ---- */
@media (min-width: 900px) {
  body { font-size: 14px; line-height: 20px; letter-spacing: -0.006em; padding-bottom: 96px; }
  :root { --cw: 38px; --ch: 52px; }
  .top { padding: 0 20px 0 28px; height: 56px; }
  .brand .logo { height: 18px; }
  .wordmark { font-size: 25px; line-height: 25px; }
  .datebar { padding: 4px 28px 12px 22px; gap: 8px; }
  .days { flex: 0 1 auto; }
  .day { min-width: 64px; flex: 0 0 auto; }
  .edit-bar { padding: 10px 28px; font-size: 14px; }
  .rows { padding: 12px 28px 0; }
  .row { display: grid; grid-template-columns: 300px minmax(0, 1fr); align-items: center; gap: 20px; padding: 6px 0; }
  .row:last-child { border-bottom: 0; }
  .strip { margin-top: 0; }
  .name .label { font-size: 15px; line-height: 20px; }
  .time { font-size: 20px; line-height: 25px; }
  .time small { font-size: 13px; }
  .cell { font-size: 13px; }
  .cell small { font-size: 10px; }
  .cell.sel { box-shadow: none; }
  .frame { display: block; position: absolute; z-index: 6; pointer-events: none; border: 2px solid var(--accent); border-radius: 8px; transition: left .12s ease; }
  .frame.off { display: none; }
  .editing .row { grid-template-columns: 1fr; max-width: 720px; }
  .editing ~ .frame { display: none; }
  .scrim { animation: fade .18s; }
  .sheet { left: 50%; right: auto; top: 50%; bottom: auto; width: 440px; max-height: min(720px, calc(100vh - 80px)); transform: translate(-50%, -50%); border-radius: 16px; animation: none; padding-bottom: 0; }
  .sheet.tall { height: min(640px, calc(100vh - 80px)); }
  .sheet-head h2 { font-size: 18px; line-height: 24px; }
  .btn { font-size: 15px; }
  .result .rn b, .set-row span, .search input, .field { font-size: 15px; }
  .cal-day { font-size: 15px; height: 40px; width: 40px; }
}
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
