/* Personal CRM — styles. Sections: tokens · base · layout · controls · lists · cards · sheets · toasts · screens · motion */

/* ───── tokens */
:root {
  --bg: #f5f3ee; --surface: #ffffff; --surface-2: #efece5; --line: #e2ded4;
  --text: #1d1f22; --text-2: #5d6168; --text-3: #8b8f96;
  --accent: #2f5d62; --accent-ink: #ffffff; --accent-soft: #e1ecec;
  --ok: #3d7a4f; --warn: #b4741c; --danger: #b2433a; --danger-soft: #f6e3e0;
  --never: #9a9ea5;
  --radius: 14px; --radius-s: 10px;
  --shadow: 0 1px 2px rgba(20,20,20,.05), 0 4px 16px rgba(20,20,20,.06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
  --t-rose:#c2566b; --t-amber:#c18a1d; --t-green:#4b8a5a; --t-blue:#3d6fb0; --t-violet:#7a5bb0;
  --t-slate:#5f6b7a; --t-teal:#2f8a8a; --t-orange:#cc6a2c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --surface: #1c1e22; --surface-2: #25282d; --line: #30333a;
    --text: #eceae5; --text-2: #a9adb4; --text-3: #7d828a;
    --accent: #7fb5b8; --accent-ink: #0e1a1b; --accent-soft: #1f3335;
    --danger-soft: #3a2221; --never: #6c7078;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

/* ───── base */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); }
body { overscroll-behavior-y: none; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* no Safari zoom */
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--text-2); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.s { width: 18px; height: 18px; } svg.i.xs { width: 15px; height: 15px; }

/* ───── layout */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) 8px 6px; min-height: calc(var(--safe-t) + 54px);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar h1 { font-size: 20px; font-weight: 700; flex: 1; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { flex: 1; padding: 6px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); max-width: 760px; width: 100%; margin: 0 auto; outline: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 48px; justify-content: center;
  color: var(--text-3); font-size: 11px; font-weight: 600; background: none; border: 0; padding: 4px 0; }
.tab[aria-current="page"] { color: var(--accent); }
.tab-add { flex: 0 0 64px; }
.tab-add span { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 4px 14px rgba(47,93,98,.35); margin-top: -14px; }
.tab-add svg.i { width: 26px; height: 26px; stroke-width: 2.2; }

/* ───── controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; font-size: 15px;
  cursor: pointer; user-select: none; -webkit-user-select: none; position: relative; transition: transform .08s, background .15s;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; }
.btn.busy { color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--text-3); border-top-color: transparent; animation: spin .7s linear infinite; }
.btn.primary.busy::after { border-color: var(--accent-ink); border-top-color: transparent; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--text); display: grid; place-items: center; position: relative; }
.press:active, .btn:active, .iconbtn:active, .tab:active, .row:active, .card.tap:active, .chip:active { transform: scale(.97); opacity: .85; }

.field { display: block; margin: 0 0 14px; }
.field > span.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 6px; }
.field .help { display: block; font-size: 12px; color: var(--text-3); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); outline: none; -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 96px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 0 30%; }
.seg button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; font-weight: 600; color: var(--text-2); white-space: nowrap; padding: 0 10px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.switch { display: flex; align-items: center; justify-content: space-between; min-height: 44px; gap: 12px; }
.switch input { width: 46px; height: 28px; -webkit-appearance: none; appearance: none; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked { background: var(--accent); } .switch input:checked::after { transform: translateX(18px); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.chip[aria-pressed="true"], .chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip .x { margin-right: -4px; opacity: .7; }
.tagchip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--tc) 14%, transparent); color: var(--tc); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tc); flex: none; display: inline-block; }
.c-rose{--tc:var(--t-rose)} .c-amber{--tc:var(--t-amber)} .c-green{--tc:var(--t-green)} .c-blue{--tc:var(--t-blue)}
.c-violet{--tc:var(--t-violet)} .c-slate{--tc:var(--t-slate)} .c-teal{--tc:var(--t-teal)} .c-orange{--tc:var(--t-orange)}

/* ───── lists */
.listbar { position: sticky; top: calc(var(--safe-t) + 54px); z-index: 10; background: var(--bg); padding: 4px 0 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.search { position: relative; margin-bottom: 8px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search input { padding-left: 40px; border-radius: 12px; background: var(--surface-2); border-color: transparent; }
.listmeta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 2px 6px; font-size: 13px; color: var(--text-2); }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list + .list { margin-top: 12px; }
.rowwrap { position: relative; overflow: hidden; }
.rowwrap + .rowwrap { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 14px; background: var(--surface); position: relative; z-index: 1;
  cursor: pointer; touch-action: pan-y; transition: transform .2s; }
.row.dragging { transition: none; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.row .sub { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row .end { font-size: 12px; color: var(--text-3); text-align: right; flex: none; }
.swipe-act { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; padding: 0 22px; color: #fff; font-size: 13px; font-weight: 700; gap: 6px; }
.swipe-act.left { left: 0; background: var(--t-amber); } .swipe-act.right { right: 0; background: var(--t-slate); justify-content: flex-end; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none;
  background: color-mix(in srgb, var(--tc, var(--t-slate)) 16%, var(--surface)); color: var(--tc, var(--t-slate)); }
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.avatar.sq { border-radius: 12px; }
.star { color: var(--t-amber); }
.empty { text-align: center; padding: 36px 20px; color: var(--text-2); }
.empty svg.i { width: 40px; height: 40px; color: var(--text-3); stroke-width: 1.4; margin-bottom: 8px; }
.empty h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 0 16px; font-size: 14px; }
.skel { background: linear-gradient(90deg, var(--surface-2) 0%, var(--line) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
.skel-row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.skel-row .skel.c { width: 40px; height: 40px; border-radius: 50%; }
.skel-row .skel.l { height: 12px; flex: 1; }

/* ───── cards and sections */
.section { margin: 22px 0 0; }
.section > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 700; margin: 0 4px 8px; display: flex; align-items: center; gap: 8px; }
.section > h2 .count { background: var(--surface-2); border-radius: 99px; padding: 1px 8px; font-size: 12px; letter-spacing: 0; }
.section > h2 .more { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--accent); font-weight: 600; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card + .card { margin-top: 10px; }
.card.tap { cursor: pointer; }
.banner { display: flex; gap: 12px; align-items: center; background: var(--accent-soft); color: var(--text); border-radius: var(--radius); padding: 12px 14px; margin-top: 10px; }
.banner .main { flex: 1; min-width: 0; }
.banner .title { font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; overflow-wrap: anywhere; }

/* person header */
.phead { display: flex; gap: 14px; align-items: center; margin: 6px 0 4px; }
.phead h2 { font-size: 24px; font-weight: 700; }
.phead .about { color: var(--text-2); font-size: 14px; margin-top: 2px; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 0; }
.action { display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 64px; justify-content: center;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); border: 0; font-size: 12px; font-weight: 600; color: var(--accent); }
.action[disabled] { color: var(--text-3); }

/* timeline */
.tl { position: relative; }
.tl-item { display: flex; gap: 12px; padding: 12px 14px; }
.tl-item + .tl-item { border-top: 1px solid var(--line); }
.tl-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.tl-body { flex: 1; min-width: 0; }
.tl-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-2); }
.tl-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.flag { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); display: inline-flex; gap: 4px; align-items: center; }
.flag.yes { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.flag.ask { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.flag.never { background: var(--surface-2); color: var(--never); }
.flag.due { background: var(--danger-soft); color: var(--danger); }
.note-never .tl-text { color: var(--never); }
.locked .tl-text { filter: blur(5px); user-select: none; cursor: pointer; }
.pending-sync { opacity: .7; }

/* brief */
.brief-person { margin-top: 14px; }
.brief-person > .card { padding: 0; overflow: hidden; }
.brief-h { display: flex; gap: 12px; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.brief-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.brief-sec:last-child { border-bottom: 0; }
.brief-sec h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.brief-sec ul { margin: 0; padding-left: 18px; } .brief-sec li { margin: 3px 0; }

/* ───── sheets (slide in from the top) */
.backdrop { position: fixed; inset: 0; background: rgba(10,12,14,.38); z-index: 60; opacity: 0; transition: opacity .22s; }
.backdrop.show { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; top: 0; z-index: 61; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 0 0 20px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  transform: translateY(-104%); transition: transform .28s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto; }
.sheet.show { transform: translateY(0); }
.sheet-h { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 8px) 8px 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-h h3 { flex: 1; font-size: 17px; }
.sheet-b { overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.sheet-f { padding: 10px 16px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.sheet-f .btn { flex: 1; }
.sheet-grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 8px; }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 0 6px; border: 0; background: none; font-size: 16px; text-align: left; border-radius: 10px; }
.menu-item + .menu-item { border-top: 1px solid var(--line); }
.menu-item .sub { font-size: 13px; color: var(--text-2); }
.menu-item.danger { color: var(--danger); }
.dup { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: -4px 0 14px; }

/* ───── toasts (slide in from the top) */
.toasts { position: fixed; top: calc(var(--safe-t) + 8px); left: 0; right: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 520px; width: 100%; padding: 12px 14px; border-radius: 14px;
  background: #23262b; color: #f2f2f2; box-shadow: 0 8px 28px rgba(0,0,0,.25); font-size: 15px; transform: translateY(-140%); opacity: 0; transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .2s; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast .msg { flex: 1; }
.toast button { background: none; border: 0; color: #9fd3d6; font-weight: 700; min-height: 36px; padding: 0 6px; }
.toast.error { background: #5b2420; } .toast.error button { color: #ffd2cc; }

/* sync status */
.sync { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; }
.sync i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: block; }
.sync.waiting i { background: var(--warn); animation: pulse 1.2s infinite; }
.sync.error i { background: var(--danger); }
.sync.offline i { background: var(--text-3); }

/* footer */
.footer { text-align: center; margin: 34px 0 6px; }
.footer button { background: none; border: 0; color: var(--text-3); font-size: 12px; min-height: 36px; padding: 0 12px; display: inline-flex; align-items: center; gap: 4px; }
.changelog h4 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.changelog .ver { margin: 10px 0; } .changelog .ver b { display: block; }
.changelog ul { margin: 4px 0 0; padding-left: 18px; color: var(--text-2); font-size: 14px; }

.privacy-cover { position: fixed; inset: 0; z-index: 200; background: var(--bg); display: none; }
.privacy-cover.on { display: block; }

.offline { text-align: center; padding: 60px 20px; }

/* desktop */
@media (min-width: 900px) {
  .view { padding-top: 16px; }
  .tabbar { top: 0; bottom: 0; right: auto; width: 88px; height: auto; flex-direction: column; justify-content: flex-start; padding-top: 80px; gap: 8px; border-top: 0; border-right: 1px solid var(--line); }
  .tab { flex: 0 0 auto; min-height: 60px; width: 100%; }
  .tab-add { order: -1; flex: 0 0 auto; margin-bottom: 12px; } .tab-add span { margin-top: 0; }
  .app { padding-left: 88px; }
  .view { padding-bottom: 40px; }
  .sheet { top: 40px; border-radius: 20px; }
  .listbar { top: 54px; }
}

/* ───── motion */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
