/* ---------- App shell ---------- */
.shell { min-height: calc(100vh - var(--banner-h, 0px)); }
.sidebar { display: none; }
.topbar {
  position: sticky; top: var(--banner-h, 0px); z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  height: calc(56px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) var(--s4) 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .logo-mark { width: 32px; height: 32px; flex: none; }
.topbar-title { font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.01em; }
.main { padding: var(--s4); padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--s6)); }
.main-inner { max-width: 1200px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; border: 0; background: none; color: var(--muted);
  font-size: var(--fs-xs); font-weight: 500; text-decoration: none;
  transition: color var(--t) var(--ease);
}
.tab:hover { text-decoration: none; }
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--brand-600); font-weight: 600; }

body.is-auth .sidebar, body.is-auth .topbar, body.is-auth .tabbar { display: none; }
body.is-auth .main { padding: var(--s4); display: grid; place-items: center; min-height: calc(100vh - var(--banner-h, 0px)); }
body.is-auth .main-inner { width: 100%; }

@media (min-width: 1024px) {
  .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: var(--banner-h, 0px); bottom: 0; left: 0; width: 248px; z-index: 20;
    background: var(--surface); border-right: 1px solid var(--line);
    padding: var(--s5) var(--s3) var(--s4);
  }
  .topbar, .tabbar { display: none; }
  .main { margin-left: 248px; padding: var(--s8); }
  body.is-auth .main { margin-left: 0; padding: var(--s6); }
}

.brand { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2) var(--s5); }
.brand .logo-mark { width: 36px; height: 36px; flex: none; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
.brand-sub { font-size: var(--fs-xs); color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: var(--s3);
  height: 40px; padding: 0 var(--s3); border-radius: var(--r-md);
  color: var(--ink-2); font-weight: 500; text-decoration: none;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.nav-item.is-active::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--brand-600);
}
.sidebar-foot { border-top: 1px solid var(--line); padding-top: var(--s3); display: flex; flex-direction: column; gap: 2px; }
.conn { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s3); height: 32px; font-size: var(--fs-sm); color: var(--muted); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
body.is-offline .conn-dot { background: var(--bad); }
.nav-item.logout { width: 100%; border: 0; background: none; text-align: left; font-size: var(--fs-md); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-xl); }
.page-head p { color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; }
.page-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
@media (max-width: 1023px) { .page-head h1 { font-size: var(--fs-lg); } .page-head { margin-bottom: var(--s4); } }
@media (max-width: 639px) { .page-head { flex-direction: column; align-items: stretch; } .page-actions .btn { flex: 1; } }

/* ---------- Card, tile ---------- */
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-1); padding: var(--s5); }
.card-title { font-size: var(--fs-md); font-weight: 600; margin-bottom: var(--s3); }
@media (max-width: 639px) { .card { padding: var(--s4); } }

.tile {
  position: relative; display: block; background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: var(--s5); color: inherit; text-decoration: none;
  transition: box-shadow var(--t) var(--ease), transform var(--t) var(--ease);
}
a.tile:hover { box-shadow: var(--shadow-2); transform: translateY(-1px); text-decoration: none; }
.tile-label { font-size: var(--fs-sm); color: var(--muted); }
.tile-value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin-top: var(--s1); }
.tile-sub { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s1); }
.tile-chip { position: absolute; top: var(--s4); right: var(--s4); width: 28px; height: 28px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); }
.tile-chip svg { width: 16px; height: 16px; }
.tile-chip.warn { background: var(--warn-50); color: var(--warn); }
.tile-chip.ok { background: var(--ok-50); color: var(--ok); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s4); border-radius: var(--r-md);
  border: 1px solid transparent; font-weight: 600; font-size: var(--fs-md); line-height: 1;
  text-decoration: none; white-space: nowrap;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:focus-visible { box-shadow: var(--ring); border-radius: var(--r-md); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad-50); }
.btn-danger.solid { background: var(--bad); color: #fff; }
.btn-danger.solid:hover:not(:disabled) { background: #991b1b; }
.btn-block { width: 100%; }
.btn-lg { height: 48px; }
@media (pointer: coarse), (max-width: 1023px) { .btn { height: 44px; } }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); }
.field label, .label { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 var(--s3);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  font-size: var(--fs-md);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.textarea { height: auto; min-height: 88px; padding: var(--s3); resize: vertical; }
.input::placeholder, .textarea::placeholder { color: #66768c; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand-600); box-shadow: var(--ring); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad); }
.money { position: relative; }
.money > span { position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%); color: var(--muted); font-size: var(--fs-sm); font-weight: 500; pointer-events: none; }
.money .input { padding-left: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.field-error { color: var(--bad); font-size: var(--fs-sm); min-height: 0; }
.field-error:empty { display: none; }
.field-hint { color: var(--muted); font-size: var(--fs-sm); }
.check { display: flex; align-items: center; gap: var(--s2); min-height: 44px; font-size: var(--fs-md); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand-600); flex: none; }
.form-error { background: var(--bad-50); color: var(--bad); border-radius: var(--r-md); padding: var(--s3); font-size: var(--fs-sm); margin-bottom: var(--s4); }
.form-error:empty { display: none; }

/* ---------- Segmented ---------- */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.segmented button { height: 34px; min-width: 44px; padding: 0 var(--s4); border: 0; background: none; border-radius: 999px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); transition: background var(--t) var(--ease), color var(--t) var(--ease); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 var(--s2); border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.chip.warn { background: var(--warn-50); color: var(--warn); }
.chip.bad { background: var(--bad-50); color: var(--bad); }
.chip.ok { background: var(--ok-50); color: var(--ok); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 0 var(--s3); height: 36px; border-bottom: 1px solid var(--line); }
.table td { height: 48px; padding: 0 var(--s3); border-bottom: 1px solid var(--line); }
.table .num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table tr.clickable td:last-child { color: var(--faint); width: 32px; }
.table tr.clickable td:last-child svg { width: 16px; height: 16px; }
@media (max-width: 639px) {
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { background: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-1); padding: var(--s3); margin-bottom: var(--s3); }
  .table.stack td { height: auto; min-height: 32px; border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: var(--s3); text-align: right; }
  .table.stack td::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-sm); text-align: left; }
}

/* ---------- Modal / sheet ---------- */
dialog.modal {
  width: calc(100% - 32px); max-width: 560px; max-height: calc(100vh - 64px);
  padding: 0; border: 0; border-radius: var(--r-xl);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
  overflow: auto;
}
dialog.modal::backdrop { background: rgb(11 18 32 / .45); backdrop-filter: blur(2px); }
.modal-body { padding: var(--s6); }
.modal-title { font-size: var(--fs-lg); font-weight: 650; margin-bottom: var(--s2); }
.modal-text { color: var(--ink-2); margin-bottom: var(--s4); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }
.sheet-list { display: flex; flex-direction: column; gap: 2px; margin: calc(var(--s2) * -1) calc(var(--s3) * -1) 0; }
.sheet-list .nav-item { height: 52px; font-size: var(--fs-md); }
.sheet-handle { display: none; }
@media (max-width: 639px) {
  dialog.modal {
    width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 88vh; animation: sheet-up 200ms var(--ease);
  }
  .modal-body { padding: var(--s4) var(--s4) calc(var(--s4) + env(safe-area-inset-bottom, 0px)); }
  .sheet-handle { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto var(--s4); }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

/* ---------- Toast ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: var(--s6); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: var(--s2); pointer-events: none; padding: 0 var(--s4); }
.toast {
  display: flex; align-items: center; gap: var(--s2); max-width: 480px;
  padding: 10px var(--s4); border-radius: 999px; background: var(--ink); color: #fff;
  font-size: var(--fs-sm); font-weight: 500; box-shadow: var(--shadow-2);
  animation: toast-up 200ms var(--ease);
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.error { border-left: 4px solid var(--bad); }
.toast.ok svg { color: #4ade80; }
@keyframes toast-up { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 1023px) { body:not(.is-auth) #toasts { bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--s3)); } }

/* ---------- Banner ---------- */
#banner { position: fixed; top: 0; left: 0; right: 0; z-index: 90; }
.banner { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); font-size: var(--fs-sm); font-weight: 500; border-bottom: 1px solid transparent; }
.banner svg { width: 18px; height: 18px; flex: none; }
.banner.warn { background: var(--warn-50); color: var(--warn); border-color: #f5d9a8; }
.banner.ok { background: var(--ok-50); color: var(--ok); border-color: #b7e4c7; }
.banner.bad { background: var(--bad-50); color: var(--bad); border-color: #f5c2c2; }
.lic-banner > div { min-width: 0; overflow-wrap: anywhere; }
.lic-banner b { font-weight: 700; margin-right: var(--s1); }
.lic-banner a { color: inherit; font-weight: 700; text-decoration: underline; white-space: nowrap; }
.lic-line { margin-right: var(--s1); }
.lic-msg { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }

/* ---------- Empty state, skeleton ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s3); text-align: center; padding: var(--s10) var(--s4); color: var(--muted); }
.empty > svg { width: 40px; height: 40px; color: var(--faint); }
.empty p { color: var(--muted); }
.skeleton { display: flex; flex-direction: column; gap: var(--s3); }
.skeleton i { display: block; height: 16px; border-radius: var(--r-sm); background: linear-gradient(90deg, #eef1f5 25%, #f6f8fa 50%, #eef1f5 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.skeleton i:nth-child(odd) { width: 100%; }
.skeleton i:nth-child(even) { width: 70%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Auth card (setup, login) ---------- */
.auth-card { width: 100%; max-width: 420px; margin: 0 auto; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-2); padding: var(--s8) var(--s6); }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: var(--s2); margin-bottom: var(--s6); text-align: center; }
.auth-logo .logo-mark { width: 56px; height: 56px; }
.auth-logo h1 { font-size: var(--fs-lg); }
.auth-logo p { color: var(--muted); font-size: var(--fs-sm); }
.auth-card h2 { font-size: var(--fs-lg); margin-bottom: var(--s1); }
.auth-card .lead { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--s5); }
@media (max-width: 639px) { .auth-card { padding: var(--s6) var(--s4); } }

/* phone keyboard open: the tab bar gets out of the way */
@media (max-width: 1023px) { body.kbd-open .tabbar { display: none; } body.kbd-open .main { padding-bottom: var(--s4); } }

@media (pointer: coarse), (max-width: 1023px) { .segmented button { height: 44px; } }

/* Phone entries: the badge that is always on a paired phone's screen, and the lists of entries. */
.sync-badge { display: inline-flex; align-items: center; gap: var(--s1); min-height: 32px; padding: 0 var(--s3); border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; text-decoration: none; }
.sync-badge[hidden] { display: none; }
.sync-badge:hover { text-decoration: none; filter: brightness(.97); }
.sync-badge.warn { background: var(--warn-50); border-color: #f5d9a8; color: var(--warn); }
.sync-badge.bad { background: var(--bad-50); border-color: #f5c2c2; color: var(--bad); }
.topbar .sync-badge { margin-left: auto; flex: none; min-height: 36px; }
.sidebar-foot .sync-badge { justify-content: center; margin-bottom: var(--s2); }
