:root {
  --bg:        #0d151d;
  --bg-2:      #131f2a;
  --surface:   #182634;
  --surface-2: #1f3040;
  --line:      #2a3d4f;
  --line-soft: #223444;
  --text:      #e8eef4;
  --text-dim:  #9db0c2;
  --text-mute: #6d8296;
  --accent:    #6db3d9;
  --accent-2:  #8fd0ee;
  --warm:      #e0b070;
  --danger:    #e07a6e;
  --good:      #7fbf9a;
  --radius:    14px;
  --tap:       46px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; min-height: 100dvh; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 .7rem; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

.muted { color: var(--text-dim); }
.small { font-size: .82rem; line-height: 1.4; }
.hint  { display: block; color: var(--text-mute); font-size: .76rem; font-weight: 400; line-height: 1.35; margin-top: .15rem; }

/* ── Chrome ─────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 40;
  padding-top: var(--safe-t);
  background: rgba(13,21,29,.86);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-inner {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; max-width: 640px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; letter-spacing: .01em; }
.brand .mark { width: 19px; height: 19px; fill: var(--accent); }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  background: none; border: 0; color: var(--text-dim); cursor: pointer;
  border-radius: 50%;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.small { width: 40px; height: 40px; }
.icon-btn.small svg { fill: none; }
.icon-btn:active { background: var(--surface); }

#main {
  max-width: 640px; margin: 0 auto;
  padding: 16px 14px calc(150px + var(--safe-b));
}
.view-title { font-size: 1.5rem; margin-bottom: .3rem; }
.view-intro { font-size: .87rem; margin-bottom: 1.1rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(13,21,29,.92);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-top: 1px solid var(--line-soft);
  padding-bottom: var(--safe-b);
}
.tab {
  background: none; border: 0; color: var(--text-mute); cursor: pointer;
  padding: 8px 0 7px; display: grid; justify-items: center; gap: 2px;
  font-size: .66rem; font-weight: 550; letter-spacing: .02em;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--accent); }

/* ── Week header ────────────────────────── */

.week-head { display: flex; align-items: center; gap: 4px; margin-bottom: .9rem; }
.week-title { flex: 1; text-align: center; }
.week-title h1 { font-size: 1.18rem; }
.week-title p { font-size: .78rem; margin: 0; }

.banner {
  border-radius: var(--radius); padding: .7rem .85rem; margin-bottom: .9rem;
  font-size: .85rem; line-height: 1.4;
  background: rgba(224,176,112,.11); border: 1px solid rgba(224,176,112,.32); color: #f0d6ab;
}
.banner.tappable { cursor: pointer; }
.banner.tappable:active { filter: brightness(1.15); }
.banner.urgent { background: rgba(224,122,110,.12); border-color: rgba(224,122,110,.36); color: #f3c1bb; }
.banner strong { color: #fff; }

.status-strip {
  border-radius: var(--radius); padding: .7rem .85rem; margin-bottom: .9rem;
  font-size: .83rem; line-height: 1.45;
  background: var(--surface); border: 1px solid var(--line);
}
.status-strip .pill {
  display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; padding: .2rem .5rem; border-radius: 20px; margin-right: .5rem;
  background: rgba(127,191,154,.16); color: var(--good); border: 1px solid rgba(127,191,154,.3);
}
.status-strip .pending {
  display: block; margin-top: .45rem; color: var(--warm); font-weight: 600; font-size: .8rem;
}

/* ── Days ───────────────────────────────── */

.day-list { display: flex; flex-direction: column; gap: 10px; }

.day {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); overflow: hidden;
}
.day.is-today { border-color: rgba(109,179,217,.45); }
.day-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem .85rem; border-bottom: 1px solid transparent;
}
.day.has-trips .day-head { border-bottom-color: var(--line-soft); }
.day-name { font-weight: 650; font-size: .95rem; flex: 1; }
.day-date { color: var(--text-mute); font-size: .78rem; font-weight: 500; }
.day-add {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--accent); font-size: 1.15rem; line-height: 1;
  display: grid; place-items: center; cursor: pointer; padding: 0 0 2px;
}
.day-add:active { background: var(--accent); color: #0d151d; }

.trip {
  display: flex; gap: .7rem; padding: .7rem .85rem;
  border-top: 1px solid var(--line-soft); cursor: pointer;
  align-items: flex-start;
}
.day-head + .trip { border-top: 0; }
.trip:active { background: var(--surface-2); }
.trip-time {
  flex: 0 0 78px; font-variant-numeric: tabular-nums; font-size: .78rem;
  color: var(--accent); font-weight: 600; line-height: 1.35; padding-top: .1rem;
}
.trip-time .to { color: var(--text-mute); font-weight: 500; }
.trip-body { flex: 1; min-width: 0; }
.trip-purpose { font-weight: 600; font-size: .89rem; }
.trip-place { color: var(--text-dim); font-size: .8rem; }
.trip-addr { color: var(--text-mute); font-size: .74rem; }
.trip-note { color: var(--warm); font-size: .74rem; margin-top: .15rem; }

.day-empty { padding: 0 .85rem .75rem; margin-top: -.35rem; color: var(--text-mute); font-size: .8rem; font-style: italic; }

.week-actions { display: flex; gap: 10px; margin-top: 1.1rem; }
.week-actions .btn { flex: 1; }

.submit-dock {
  position: fixed; left: 0; right: 0; z-index: 44;
  bottom: calc(60px + var(--safe-b));
  padding: 10px 14px;
  background: linear-gradient(to top, rgba(13,21,29,.97) 55%, rgba(13,21,29,0));
  pointer-events: none;
}
.submit-dock .btn { pointer-events: auto; max-width: 612px; width: 100%; margin: 0 auto; display: flex; }

/* ── Buttons ────────────────────────────── */

.btn {
  min-height: var(--tap); border-radius: var(--radius); cursor: pointer;
  font-size: .92rem; font-weight: 600; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1rem; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  transition: transform .06s ease;
}
.btn:active { transform: scale(.985); }
.btn .ic { width: 17px; height: 17px; }
.btn.wide { width: 100%; }
.btn.big { min-height: 52px; font-size: 1rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08131c; font-weight: 700; }
.btn.solid { background: var(--surface-2); border-color: var(--accent); color: var(--accent-2); font-weight: 700; }
.btn.ghost { background: var(--surface); }
.btn.danger-text { color: var(--danger); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn + .btn { margin-top: 10px; }
.week-actions .btn + .btn { margin-top: 0; }

.link-btn {
  background: none; border: 0; color: var(--accent); font-size: .93rem; font-family: inherit;
  cursor: pointer; padding: .5rem .1rem; min-width: 64px; text-align: left;
}
.link-btn.strong { font-weight: 700; text-align: right; }
.link-btn.spacer { visibility: hidden; }

/* ── Cards (places / routine / archive) ─── */

.card-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 1.1rem; }
.card {
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: .8rem .9rem; cursor: pointer;
}
.card:active { background: var(--surface-2); }
.card h3 { font-size: .95rem; }
.card .sub { color: var(--text-dim); font-size: .82rem; }
.card .sub2 { color: var(--text-mute); font-size: .76rem; }
.card .meta { display: flex; gap: .5rem; align-items: center; margin-top: .3rem; flex-wrap: wrap; }
.chip {
  font-size: .7rem; font-weight: 600; padding: .16rem .45rem; border-radius: 6px;
  background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--line);
}
.chip.accent { color: var(--accent); border-color: rgba(109,179,217,.35); }
.chip.warm { color: var(--warm); border-color: rgba(224,176,112,.35); }
.chip.good { color: var(--good); border-color: rgba(127,191,154,.35); }
.empty-note {
  text-align: center; color: var(--text-mute); font-size: .85rem;
  padding: 1.6rem .8rem; border: 1px dashed var(--line); border-radius: var(--radius);
}

.chain-state {
  border-radius: var(--radius); padding: .65rem .85rem; margin-bottom: 1rem;
  font-size: .8rem; border: 1px solid var(--line); background: var(--surface); color: var(--text-dim);
}
.chain-state.ok { border-color: rgba(127,191,154,.35); color: var(--good); }
.chain-state.bad { border-color: rgba(224,122,110,.45); color: var(--danger); }

/* ── Forms ──────────────────────────────── */

.field-group {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: .9rem; margin-bottom: 14px;
}
.group-title { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-mute); margin-bottom: .8rem; }

.field { display: block; margin-bottom: .85rem; }
.field:last-child { margin-bottom: 0; }
.field > span, .field-label { display: block; font-size: .78rem; font-weight: 600; color: var(--text-dim); margin-bottom: .3rem; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

input[type=text], input[type=email], input[type=time], input[type=password], select, textarea {
  width: 100%; min-height: var(--tap);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 16px; font-family: inherit;
  padding: .6rem .7rem; appearance: none; -webkit-appearance: none;
}
textarea { min-height: 62px; resize: vertical; line-height: 1.4; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239db0c2' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .6rem center; background-size: 18px;
  padding-right: 2.1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=time] { font-variant-numeric: tabular-nums; }

.check { display: flex; gap: .65rem; align-items: flex-start; margin-bottom: .8rem; cursor: pointer; }
.check:last-child { margin-bottom: 0; }
.check input { width: 21px; height: 21px; margin: .12rem 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.check span { font-size: .86rem; color: var(--text); }

.dow-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.dow {
  height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2);
  color: var(--text-dim); font-size: .78rem; font-weight: 650; cursor: pointer; font-family: inherit;
}
.dow.on { background: var(--accent); border-color: var(--accent); color: #08131c; }

.addr-preview {
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 10px;
  padding: .55rem .7rem; font-size: .8rem; color: var(--text-dim); margin: -.4rem 0 .85rem;
  white-space: pre-line;
}
.inline-warn {
  background: rgba(224,176,112,.1); border: 1px solid rgba(224,176,112,.3); color: #f0d6ab;
  border-radius: 10px; padding: .5rem .7rem; font-size: .8rem; margin: -.4rem 0 .85rem;
}

/* ── Sheets ─────────────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  background: var(--bg-2); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  max-height: 92dvh; display: flex; flex-direction: column;
  animation: rise .22s cubic-bezier(.32,.72,.35,1);
  max-width: 640px; margin: 0 auto;
}
@keyframes rise { from { transform: translateY(100%) } to { transform: translateY(0) } }
.sheet.tall { height: 92dvh; }

.sheet-grip { width: 36px; height: 4px; border-radius: 3px; background: var(--line); margin: 8px auto 0; flex: 0 0 auto; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .3rem .9rem .5rem; border-bottom: 1px solid var(--line-soft); flex: 0 0 auto;
}
.sheet-head h2 { font-size: .98rem; text-align: center; flex: 1; }
.sheet-body {
  padding: 1rem .9rem calc(1.6rem + var(--safe-b));
  overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto;
}

.notice {
  background: rgba(224,176,112,.1); border: 1px solid rgba(224,176,112,.34);
  border-radius: var(--radius); padding: .75rem .85rem; font-size: .82rem;
  color: #f0d6ab; line-height: 1.45; margin-bottom: 1rem;
}
.notice strong { display: block; color: #fff; margin-bottom: .15rem; }

.kind-picker { display: flex; gap: 8px; margin-bottom: 1rem; }
.kind-picker button {
  flex: 1; min-height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text-dim); font-size: .82rem; font-weight: 600;
  font-family: inherit; cursor: pointer;
}
.kind-picker button.on { background: var(--surface-2); border-color: var(--accent); color: var(--accent-2); }

.diff-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .7rem .85rem; font-size: .82rem; margin-bottom: 1rem;
}
.diff-box h4 { margin: 0 0 .4rem; font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-mute); }
.diff-box ul { margin: 0; padding-left: 1.1rem; color: var(--text-dim); }
.diff-box li { margin-bottom: .2rem; }

.preview-head { display: flex; align-items: baseline; justify-content: space-between; }
.preview {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .74rem; line-height: 1.55; color: var(--text-dim);
  white-space: pre-wrap; word-break: break-word; overflow-x: auto;
  max-height: 320px; overflow-y: auto; margin: .35rem 0 1.1rem;
}
.review-actions { margin-bottom: 1.3rem; }

.seal-box { border-top: 1px solid var(--line-soft); padding-top: 1rem; }

.entry-field { margin-bottom: .9rem; }
.entry-field .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-mute); margin-bottom: .2rem; }
.entry-field .v { font-size: .87rem; }
.hashline {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .68rem;
  color: var(--text-mute); word-break: break-all; line-height: 1.45;
}

.persist-state { font-size: .8rem; color: var(--text-dim); margin-bottom: .8rem; line-height: 1.45; }

/* Utility classes rather than inline styles — the CSP forbids style attributes. */
.is-good { color: var(--good); }
.is-warm { color: var(--warm); }
.banner.spaced { margin-top: 1rem; }
.preview.short { max-height: 180px; }
.reply-k {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mute); margin-bottom: .4rem;
}
#reply-save { margin-top: 10px; }
.offscreen { position: fixed; top: 0; left: 0; opacity: 0; pointer-events: none; }
body.sheet-open { overflow: hidden; }

/* ── Login ──────────────────────────────── */

#login {
  min-height: 100dvh; display: grid; place-items: center;
  padding: 24px 20px calc(24px + var(--safe-b));
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-mark { width: 42px; height: 42px; fill: var(--accent); margin-bottom: .9rem; }
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.login-card > p { margin-bottom: 1.6rem; }
.login-card .field { text-align: left; }
.login-card .inline-warn { margin: 0 0 .85rem; text-align: left; }
.login-card form { margin-bottom: .9rem; }
.link-btn.centered { display: block; width: 100%; text-align: center; font-size: .82rem; color: var(--text-dim); }

/* ── Offline strip ──────────────────────── */

.offline-strip {
  background: rgba(224,176,112,.14); border-bottom: 1px solid rgba(224,176,112,.3);
  color: #f0d6ab; font-size: .76rem; font-weight: 600; text-align: center;
  padding: .3rem .8rem;
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b)); z-index: 90;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); padding: .6rem 1rem; border-radius: 22px;
  font-size: .84rem; font-weight: 550; box-shadow: 0 8px 26px rgba(0,0,0,.45);
  animation: fade .15s ease; max-width: 90vw; text-align: center;
}

/* ── Print ──────────────────────────────── */

#print-area { display: none; }

@media print {
  body { background: #fff; }
  #app, .sheet, .scrim, .toast { display: none !important; }
  #print-area {
    display: block; color: #000; font-family: Georgia, "Times New Roman", serif;
    padding: 0; margin: 0;
  }
  #print-area .pr-head { border-bottom: 1.5px solid #000; padding-bottom: 8px; margin-bottom: 16px; }
  #print-area .pr-title { font-size: 15pt; font-weight: 700; margin: 0; }
  #print-area .pr-meta { font-size: 8.5pt; color: #333; margin-top: 3px; font-family: Helvetica, Arial, sans-serif; }
  #print-area .pr-notice {
    font-family: Helvetica, Arial, sans-serif; font-size: 8pt; border: 1px solid #666;
    padding: 6px 8px; margin-bottom: 14px; color: #222;
  }
  #print-area pre {
    font-family: Georgia, "Times New Roman", serif; font-size: 10.5pt; line-height: 1.5;
    white-space: pre-wrap; margin: 0;
  }
  #print-area .pr-foot {
    margin-top: 20px; padding-top: 8px; border-top: 0.75px solid #999;
    font-family: Helvetica, Arial, sans-serif; font-size: 7.5pt; color: #444; line-height: 1.5;
    word-break: break-all;
  }
  @page { margin: 0.75in; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
