/* Hakili — styles.
   Mobile-first, thumb-first. Light and dark are both chosen rather than one
   flipped into the other: the dark values are re-stepped against the dark
   surface, not the light ones inverted. */

:root {
  color-scheme: light;

  --page:        #F6F2EA;
  --surface:     #FCFAF6;
  --surface-2:   #EFEAE0;
  --ink:         #14231E;
  --ink-2:       #4C5A54;
  --muted:       #8A9089;
  --line:        #E2DCD0;
  --baseline:    #C6BFB1;
  --brand:       #14231E;
  --on-brand:    #F6F2EA;
  --accent:      #B4661F;
  --accent-soft: #F2E3D2;

  --overdue:     #C4342F;
  --today:       #B4661F;
  --soon:        #8A6A12;
  --good:        #1F7A4D;

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --shadow: 0 1px 2px rgba(20,35,30,.05), 0 8px 24px rgba(20,35,30,.07);
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:        #0C0F0E;
    --surface:     #171A19;
    --surface-2:   #212523;
    --ink:         #F4F2EC;
    --ink-2:       #B8BEB8;
    --muted:       #868C86;
    --line:        #2B302D;
    --baseline:    #3A403C;
    --brand:       #E8E4DA;
    --on-brand:    #14231E;
    --accent:      #E09147;
    --accent-soft: #2E2318;
    --overdue:     #E5695F;
    --today:       #E09147;
    --soon:        #D2B156;
    --good:        #46B37C;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0C0F0E;
  --surface:     #171A19;
  --surface-2:   #212523;
  --ink:         #F4F2EC;
  --ink-2:       #B8BEB8;
  --muted:       #868C86;
  --line:        #2B302D;
  --baseline:    #3A403C;
  --brand:       #E8E4DA;
  --on-brand:    #14231E;
  --accent:      #E09147;
  --accent-soft: #2E2318;
  --overdue:     #E5695F;
  --today:       #E09147;
  --soon:        #D2B156;
  --good:        #46B37C;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  max-width: 100%;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
/* Any rule that sets `display` beats the browser's own [hidden] styling, so
   `el.hidden = true` would silently do nothing on a flex row. This puts the
   attribute back in charge everywhere. */
[hidden] { display: none !important; }
.spacer { height: 130px; }
mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 2px; font-weight: 700; }

/* ── splash ──────────────────────────────────────────────────────── */
.splash {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--brand); color: var(--on-brand);
  transition: opacity .45s ease;
}
.splash.gone { opacity: 0; pointer-events: none; }
.splash-mark img { width: 92px; height: 92px; object-fit: contain; }
.splash-name { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.splash-tag { font-size: 14px; opacity: .72; }

/* ── onboarding ──────────────────────────────────────────────────── */
.onb { position: fixed; inset: 0; z-index: 80; background: var(--page); overflow-y: auto; }
.onb-slide { display: none; padding: calc(56px + var(--safe-t)) 22px calc(40px + var(--safe-b)); max-width: 560px; margin: 0 auto; min-height: 100%; }
.onb-slide.active { display: block; }
.onb h1 { font-size: 27px; font-weight: 800; letter-spacing: -.02em; line-height: 1.18; margin-bottom: 10px; }
.onb-sub { color: var(--ink-2); font-size: 15px; line-height: 1.55; margin-bottom: 26px; }
.onb-art { height: 120px; display: grid; place-items: center; margin-bottom: 22px; }
.onb-knot {
  width: 92px; height: 92px; border-radius: 26px;
  border: 12px solid var(--brand);
  position: relative; transform: rotate(45deg);
}
.onb-knot::before, .onb-knot::after {
  content: ""; position: absolute; background: var(--brand); border-radius: 4px;
}
.onb-knot::before { left: -30px; top: 22px; width: 104px; height: 12px; }
.onb-knot::after { top: -30px; left: 22px; width: 12px; height: 104px; }
.onb-list { list-style: none; margin: 0 0 30px; padding: 0; display: grid; gap: 14px; }
.onb-list li { display: grid; grid-template-columns: 30px 1fr; row-gap: 2px; column-gap: 10px; align-items: start; }
.onb-ic { grid-row: span 2; font-size: 20px; line-height: 1.2; }
.onb-list b { font-size: 15px; font-weight: 700; }
.onb-list em { font-style: normal; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; }
.onb-skip { display: block; margin: 12px auto 0; }
.onb-dots { position: fixed; bottom: calc(14px + var(--safe-b)); left: 0; right: 0; display: flex; gap: 7px; justify-content: center; }
.onb-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--baseline); }
.onb-dots i.on { background: var(--brand); width: 18px; border-radius: 3px; }

/* ── shell ───────────────────────────────────────────────────────── */
.app { max-width: 620px; margin: 0 auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(16px + var(--safe-t)) 0 12px;
}
.hello { font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.topbar-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.detail-bar { position: sticky; top: 0; z-index: 5; background: var(--page); }
.detail-title { flex: 1; font-size: 17px; font-weight: 700; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-size: 19px;
  background: var(--surface-2); color: var(--ink);
}
.icon-btn.sm { width: 32px; height: 32px; font-size: 16px; }
.icon-btn:active { transform: scale(.94); }
.link-btn { color: var(--accent); font-size: 13.5px; font-weight: 700; }

/* ── search ──────────────────────────────────────────────────────── */
.searchwrap { position: relative; margin-bottom: 14px; }
.searchwrap input {
  width: 100%; height: 52px; border-radius: var(--r-md);
  border: 1.5px solid var(--line); background: var(--surface);
  padding: 0 44px 0 42px; font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.searchwrap.sm input { height: 44px; font-size: 15px; }
.searchwrap input:focus { border-color: var(--accent); }
.searchwrap input::-webkit-search-cancel-button { display: none; }
.search-ic { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 19px; color: var(--muted); pointer-events: none; }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 50%; font-size: 20px; color: var(--muted);
  background: var(--surface-2);
}
.idx-note { font-size: 12.5px; color: var(--muted); margin: -6px 0 12px 4px; }

/* ── cards, sections ─────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.soft { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.card h3 { font-size: 15px; font-weight: 800; margin-bottom: 8px; }
.muted-p { font-size: 13.5px; color: var(--ink-2); line-height: 1.55; }
.muted-p.sm { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.sec { margin-bottom: 20px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.sec-head h2 { font-size: 15px; font-weight: 800; }

.quick-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 10px; text-align: left; }
.tile b { display: block; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.tile span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.tile.hot b { color: var(--overdue); }

/* ── rows ────────────────────────────────────────────────────────── */
.row {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  width: 100%; text-align: left;
  padding: 11px 12px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.row:active { background: var(--surface-2); }
.avatar {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--brand); color: var(--on-brand); font-weight: 800; font-size: 16px; letter-spacing: -.02em;
}
.avatar.k-supplier { background: var(--brand); }
.avatar.k-customer { background: var(--accent); color: #fff; }
.avatar.k-agent    { background: var(--good); color: #fff; }
.avatar.k-school   { background: var(--soon); color: #fff; }
.avatar.k-personal { background: var(--surface-2); color: var(--ink); }
.avatar.k-service  { background: var(--baseline); color: var(--ink); }
.row-main { min-width: 0; }
.row-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.row-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub.wrap { white-space: normal; line-height: 1.45; }
.row-right { text-align: right; font-size: 11.5px; color: var(--muted); flex: none; }
.row-right b { display: block; font-size: 14px; font-weight: 800; color: var(--ink); }
.star { color: var(--accent); font-size: 13px; }

.badge { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.badge.overdue { background: var(--overdue); color: #fff; }
.badge.today   { background: var(--today); color: #fff; }
.badge.soon    { background: var(--accent-soft); color: var(--accent); }
.badge.done    { background: var(--surface-2); color: var(--muted); }

/* ── chips ───────────────────────────────────────────────────────── */
.scope-row { margin-bottom: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.scope-row::-webkit-scrollbar { display: none; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.scope-row .chips { flex-wrap: nowrap; }
.chip {
  flex: none; padding: 8px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); border: 1.5px solid transparent; white-space: nowrap;
}
.chip.on { background: var(--brand); color: var(--on-brand); }
.chip.rm { padding-right: 8px; }
.chip .x { margin-left: 6px; opacity: .6; font-weight: 700; }

/* ── forms ───────────────────────────────────────────────────────── */
.fld { display: block; margin-bottom: 14px; }
.fld > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.fld input, .fld select, .fld textarea {
  width: 100%; border-radius: var(--r-md); border: 1.5px solid var(--line);
  background: var(--surface); padding: 12px 13px; font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
.fld select { background-image: none; }
.fld input:focus, .fld select:focus, .fld textarea:focus { border-color: var(--accent); }
.fld textarea { resize: vertical; line-height: 1.5; }
.hint { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); line-height: 1.45; margin-top: 6px; }

.btn { display: block; width: 100%; padding: 14px 16px; border-radius: var(--r-md); font-size: 15px; font-weight: 700; text-align: center; }
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-line { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-danger { background: var(--overdue); color: #fff; }
.btn-plain { display: block; width: 100%; padding: 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
.btn-row { display: flex; gap: 8px; margin-top: 6px; }
.btn-row .btn { margin: 0; }

.warn { background: var(--accent-soft); color: var(--accent); border-radius: var(--r-sm); padding: 11px 13px; font-size: 13px; line-height: 1.5; font-weight: 600; margin-bottom: 12px; }
.danger-card { border-color: color-mix(in srgb, var(--overdue) 35%, transparent); }

/* ── empty ───────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 30px 14px 20px; }
.empty-ic { font-size: 40px; margin-bottom: 12px; }
.empty h3 { font-size: 18px; font-weight: 800; margin-bottom: 8px; }
.empty p { font-size: 14px; color: var(--ink-2); line-height: 1.55; max-width: 380px; margin: 0 auto 18px; }

/* ── results ─────────────────────────────────────────────────────── */
.results { min-height: 40vh; }
.res-head { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }
.res-head:first-child { margin-top: 4px; }
.msg-hit { padding: 11px 13px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); width: 100%; text-align: left; }
.msg-hit .mh-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; margin-bottom: 4px; }
.msg-hit .mh-who { font-weight: 800; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-hit .mh-when { color: var(--muted); flex: none; }
.msg-hit .mh-x { font-size: 13.5px; line-height: 1.5; color: var(--ink-2); }
.no-res { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* ── person detail ───────────────────────────────────────────────── */
.p-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.p-head .avatar { width: 62px; height: 62px; border-radius: 20px; font-size: 23px; }
.p-name { font-size: 21px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.p-aka { font-size: 13.5px; color: var(--muted); margin-top: 3px; }
.act-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.act {
  padding: 13px 6px; border-radius: var(--r-md); background: var(--surface-2);
  font-size: 12.5px; font-weight: 700; text-align: center; color: var(--ink);
  display: block; text-decoration: none;
}
.act i { display: block; font-style: normal; font-size: 19px; margin-bottom: 4px; }
.act.primary { background: var(--brand); color: var(--on-brand); }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-radius: var(--r-md); overflow: hidden; margin-bottom: 14px; }
.fact { background: var(--surface); padding: 12px 13px; }
.fact.full { grid-column: 1 / -1; }
.fact dt { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.fact dd { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.4; word-break: break-word; }
.linklist { display: grid; gap: 6px; }
.linklist a { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--ink); text-decoration: none; padding: 10px 12px; background: var(--surface-2); border-radius: var(--r-sm); word-break: break-all; }
.linklist .lk { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); flex: none; }
.notebox { white-space: pre-wrap; font-size: 14px; line-height: 1.6; color: var(--ink-2); }

/* ── chat ────────────────────────────────────────────────────────── */
.chat-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.daymark { text-align: center; font-size: 11.5px; font-weight: 700; color: var(--muted); margin: 16px 0 10px; }
.bub { max-width: 84%; padding: 9px 12px; border-radius: 16px; margin-bottom: 6px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.bub.them { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bub.me { background: var(--brand); color: var(--on-brand); margin-left: auto; border-bottom-right-radius: 5px; }
.bub.me mark { background: var(--accent); color: #fff; }
.bub.hit { outline: 2px solid var(--accent); }
.bub .bt { display: block; font-size: 10.5px; opacity: .55; margin-top: 3px; }
.bub.media { font-style: italic; opacity: .75; }
.load-more { display: block; width: 100%; padding: 12px; font-size: 13.5px; font-weight: 700; color: var(--accent); }

/* ── tabbar, fab ─────────────────────────────────────────────────── */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab { padding: 9px 0 7px; display: grid; gap: 2px; justify-items: center; color: var(--muted); }
.tab i { font-style: normal; font-size: 19px; line-height: 1; }
.tab span { font-size: 10.5px; font-weight: 700; }
.tab.active { color: var(--ink); }
.fab {
  position: fixed; right: 18px; bottom: calc(74px + var(--safe-b)); z-index: 45;
  width: 56px; height: 56px; border-radius: 19px;
  background: var(--brand); color: var(--on-brand);
  font-size: 26px; font-weight: 300; display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(20,35,30,.28);
}
.fab:active { transform: scale(.93); }

/* ── sheets ──────────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(12,15,14,.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-width: 620px; margin: 0 auto;
  background: var(--page); border-radius: 24px 24px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  max-height: 88vh; display: flex; flex-direction: column;
  animation: rise .22s cubic-bezier(.2,.8,.3,1);
}
.sheet.tall { height: 88vh; }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--baseline); margin: 4px auto 12px; flex: none; }
.sheet h2 { font-size: 19px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: none; }
.sheet-head h2 { margin-bottom: 0; }
.sheet-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-top: 14px; flex: 1; }

.big-choice {
  display: flex; gap: 13px; align-items: center; width: 100%; text-align: left;
  padding: 14px; margin-bottom: 9px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
}
.big-choice:active { background: var(--surface-2); }
.bc-ic { font-size: 22px; flex: none; }
.big-choice b { display: block; font-size: 15px; font-weight: 700; }
.big-choice em { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.howto { margin: 0 0 18px; padding-left: 20px; display: grid; gap: 9px; }
.howto li { font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.howto b { color: var(--ink); }
.paste-fold { margin-top: 14px; }
.paste-fold summary { font-size: 13.5px; color: var(--muted); font-weight: 600; padding: 10px 0; cursor: pointer; }
.paste-fold textarea { width: 100%; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--surface); padding: 12px; font-size: 14px; margin-bottom: 10px; }

.prev-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.prev-head .avatar { width: 52px; height: 52px; border-radius: 17px; font-size: 20px; }
.prev-name { font-size: 18px; font-weight: 800; }
.prev-conf { font-size: 12px; color: var(--muted); margin-top: 2px; }
.prev-block { margin-bottom: 14px; }
.prev-block > span { display: block; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 7px; }

/* ── toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-b)); z-index: 70;
  max-width: 560px; margin: 0 auto;
  background: var(--brand); color: var(--on-brand);
  padding: 13px 16px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 600; line-height: 1.45;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 8px 26px rgba(0,0,0,.25);
  animation: rise .2s ease;
}
.toast button { color: var(--on-brand); font-weight: 800; font-size: 13px; text-decoration: underline; flex: none; }

.fineprint { padding: 8px 4px 0; }
.fineprint p { font-size: 12px; color: var(--muted); line-height: 1.55; }
.fineprint .ver { margin-top: 8px; opacity: .7; }

@media (min-width: 560px) {
  .quick-tiles { gap: 10px; }
  .act-row { gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* A switch, not a tickbox: this one reads as a mode the app is in. */
.fld.check { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 14px; }
.fld.check > span { margin-bottom: 0; }
.fld.check .hint { grid-column: 1 / -1; }
.fld.check input[type="checkbox"] {
  width: 50px; height: 30px; padding: 0; flex: none;
  border: 0; border-radius: 999px; background: var(--baseline);
  position: relative; transition: background .18s ease;
}
.fld.check input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%; background: #fff;
  transition: transform .18s ease;
}
.fld.check input[type="checkbox"]:checked { background: var(--good); }
.fld.check input[type="checkbox"]:checked::after { transform: translateX(20px); }
