:root {
  --orange: #E87722;
  --orange-dark: #c9611a;
  --bg: #111418;
  --surface: #1a1f26;
  --surface-2: #232a33;
  --line: #2e3742;
  --text: #eef2f6;
  --muted: #8b97a5;
  --green: #2ecc71;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.error { background: #3a1d1d; color: #ff9b9b; border-radius: 10px; padding: .7rem .9rem; font-size: .9rem; margin-top: .8rem; }

/* ── Brand ─────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.05rem; letter-spacing: .2px; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--orange); color: #fff; font-size: .8rem; font-weight: 900;
}

/* ── Login ─────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: .8rem; }
.login-card .brand { justify-content: center; font-size: 1.4rem; margin-bottom: .2rem; }
.login-card .muted { text-align: center; margin-bottom: .6rem; }
.login-card input {
  width: 100%; padding: .95rem 1rem; background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 12px; color: var(--text); font-size: 1rem; outline: none;
}
.login-card input:focus { border-color: var(--orange); }

/* ── Buttons ───────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 1rem; background: var(--orange); color: #fff;
  border: none; border-radius: 12px; font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.btn-primary:active { background: var(--orange-dark); }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 1.2rem; padding: .4rem; cursor: pointer; }

/* ── App shell ─────────────────────────────────────── */
.app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(1rem + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(.8rem + var(--safe-top)) 1rem .8rem; border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.pill { font-size: .72rem; font-weight: 700; padding: .25rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.warn { background: #3a2f16; color: #f5c451; }
.pill.ok { background: #14361f; color: var(--green); }

.tabs { display: flex; gap: .3rem; padding: .7rem 1rem 0; }
.tab {
  flex: 1; padding: .7rem; background: none; border: none; border-bottom: 2.5px solid transparent;
  color: var(--muted); font-size: .98rem; font-weight: 700; cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--orange); }
.count { font-size: .75rem; background: var(--surface-2); border-radius: 999px; padding: .05rem .4rem; margin-left: .2rem; }

.tab-panel { padding: 1rem; }

/* ── Client search + list ──────────────────────────── */
.search-wrap { position: sticky; top: calc(3.4rem + var(--safe-top)); z-index: 10; background: var(--bg); padding-bottom: .7rem; }
#client-search {
  width: 100%; padding: .9rem 1rem; background: var(--surface); border: 1.5px solid var(--line);
  border-radius: 12px; color: var(--text); font-size: 1rem; outline: none;
}
#client-search:focus { border-color: var(--orange); }

.client-list { display: flex; flex-direction: column; gap: .4rem; }
.group-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 800; margin: .9rem .2rem .3rem; }
.group-label:first-child { margin-top: .2rem; }
.client-row {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  width: 100%; text-align: left; padding: 1rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; color: var(--text); font-size: 1.02rem; cursor: pointer;
}
.client-row:active { background: var(--surface-2); }
.client-row .cname { font-weight: 600; }
.client-row .csub { display: block; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.client-row .tag { font-size: .68rem; font-weight: 800; padding: .2rem .5rem; border-radius: 999px; background: #14361f; color: var(--green); white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.add-row { margin-top: .5rem; border-style: dashed; border-color: var(--orange); background: transparent; }
.add-row .cname { color: var(--orange); font-weight: 700; }
.add-row:active { background: var(--surface-2); }

/* ── Entry list (Today) ────────────────────────────── */
.today-summary { display: flex; gap: .6rem; margin-bottom: 1rem; }
.stat { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem; }
.stat .n { font-size: 1.5rem; font-weight: 800; }
.stat .l { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.entry-list { display: flex; flex-direction: column; gap: .5rem; }
.entry-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; cursor: pointer; }
.entry-card:active { background: var(--surface-2); }
.entry-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.entry-client { font-weight: 700; }
.entry-dur { font-weight: 800; color: var(--orange); white-space: nowrap; }
.entry-meta { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.ref { color: var(--orange); font-weight: 700; }
.sheet-ref { color: var(--orange); font-weight: 700; font-size: .85rem; margin: -.4rem 0 1rem; }
.sheet-ref:empty { display: none; }
.entry-notes { font-size: .88rem; margin-top: .45rem; color: #cdd6df; }
.badge { font-size: .66rem; font-weight: 800; padding: .12rem .45rem; border-radius: 999px; margin-left: .4rem; }
.badge.nb { background: #2e2433; color: #c79be0; }
.badge.pending { background: #3a2f16; color: #f5c451; }
.badge.synced { background: #14361f; color: var(--green); }

/* ── Bottom sheet ──────────────────────────────────── */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-height: 92vh; overflow-y: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: .6rem 1.1rem calc(1.4rem + var(--safe-bottom));
  border-top: 1px solid var(--line); animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 42px; height: 5px; border-radius: 999px; background: var(--line); margin: .3rem auto .7rem; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.sheet-head h2 { font-size: 1.25rem; }

.field-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.field-row > label { font-weight: 600; color: var(--muted); }
.field-block { margin-bottom: 1rem; }
.field-block > label { display: block; font-weight: 600; color: var(--muted); margin-bottom: .5rem; }

.sheet input[type=date], .sheet input[type=time], .sheet input[type=number], .sheet input[type=text],
.sheet input[type=email], .sheet input[type=tel], .sheet textarea {
  background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 10px;
  color: var(--text); font-size: 1rem; padding: .7rem .8rem; outline: none;
}
.sheet input:focus, .sheet textarea:focus { border-color: var(--orange); }
.sheet textarea { width: 100%; resize: vertical; font-family: inherit; }
#f-contact { width: 100%; }
#contact-chips:empty { display: none; }

.contact-details { margin-top: .6rem; }
.contact-details summary { color: var(--orange); font-size: .85rem; font-weight: 600; cursor: pointer; padding: .2rem 0; list-style: none; }
.contact-details summary::-webkit-details-marker { display: none; }
.contact-details summary::before { content: '＋ '; }
.contact-details[open] summary::before { content: '− '; }
.contact-details input { width: 100%; margin-top: .5rem; }

.time-group { display: flex; align-items: center; gap: .4rem; }
.time-group input[type=time] { flex: 1; text-align: center; }
.nudge { background: var(--surface-2); border: 1.5px solid var(--line); color: var(--text); border-radius: 10px; padding: .7rem .6rem; font-weight: 700; font-size: .85rem; cursor: pointer; }
.nudge:active { border-color: var(--orange); }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .6rem; }
.chip { background: var(--surface-2); border: 1.5px solid var(--line); color: var(--text); border-radius: 999px; padding: .55rem .95rem; font-size: .92rem; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--orange); border-color: var(--orange); color: #fff; }
.dur-custom { display: flex; align-items: center; gap: .5rem; }
.dur-custom input { width: 6rem; }
.timer-btn { margin-left: auto; background: var(--surface-2); border: 1.5px solid var(--line); color: var(--text); border-radius: 10px; padding: .6rem 1rem; font-weight: 700; cursor: pointer; }
.timer-btn.running { background: #3a1d1d; border-color: #ff6b6b; color: #ff9b9b; }

.toggle-row { margin-top: .3rem; }
.switch { appearance: none; width: 52px; height: 30px; background: var(--line); border-radius: 999px; position: relative; cursor: pointer; transition: background .15s; }
.switch:checked { background: var(--green); }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch:checked::after { transform: translateX(22px); }

.btn-save { margin-top: .4rem; }

/* ── Toast ─────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(1.4rem + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  padding: .8rem 1.2rem; border-radius: 999px; font-size: .92rem; font-weight: 600; z-index: 80;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); animation: pop .2s ease-out;
}
.toast.ok { border-color: var(--green); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
