/* TabVault PWA — mobile-first shell. Self-contained tokens for now; once the
   design system stabilizes we can share newtab.css's variables. */
:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242e;
  --border: #2a2f3a;
  --text: #e6e9ef;
  --text-dim: #99a1b3;
  --accent: #5b4fff;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 12px;
  --tap: 44px; /* min touch target */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
.app { display: flex; flex-direction: column; min-height: 100dvh; }
.loading { padding: 2rem; text-align: center; color: var(--text-dim); }

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .5rem;
  padding: max(.6rem, env(safe-area-inset-top)) .8rem .6rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar__back {
  background: none; border: 0; color: var(--text); font-size: 1.4rem;
  width: var(--tap); height: var(--tap); border-radius: 8px; cursor: pointer;
}
.topbar__back:active { background: var(--surface-2); }
.topbar__title { flex: 1; font-size: 1.05rem; font-weight: 600; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__meta { color: var(--text-dim); font-size: .8rem; margin-left: .25rem; }
.icon-btn {
  background: none; border: 0; color: var(--text-dim);
  width: var(--tap); height: var(--tap); border-radius: 8px; cursor: pointer;
  display: grid; place-items: center; font-size: 1.2rem;
}
.icon-btn:active { background: var(--surface-2); color: var(--text); }

.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-dim); flex: 0 0 auto; }
.sync-dot.is-active { background: var(--ok); }
.sync-dot.is-paused { background: var(--text-dim); }
.sync-dot.is-error  { background: var(--danger); }

/* ── Lists ─────────────────────────────────────────────────── */
.list { flex: 1; overflow-y: auto; padding: .5rem 0 6rem; -webkit-overflow-scrolling: touch; }
.row {
  display: flex; align-items: center; gap: .65rem;
  min-height: var(--tap); padding: .55rem .9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none; cursor: pointer;
}
.row:active { background: var(--surface-2); }
.row__swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.row__title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__count { color: var(--text-dim); font-size: .82rem; }
.row__chev { color: var(--text-dim); }

.item { font-size: .95rem; }
.item--heading { font-weight: 600; color: var(--text); background: var(--surface);
  text-transform: none; letter-spacing: .01em; }
.item--heading:active { background: var(--surface); }
/* Tappable open-area inside a row; sits beside the kebab. */
.row__open { flex: 1; min-width: 0; display: flex; align-items: center; gap: .65rem;
  color: inherit; text-decoration: none; }
.row__open--heading { cursor: default; }
.row__kebab { background: none; border: 0; color: var(--text-dim);
  width: 34px; height: 34px; margin: -.4rem -.3rem -.4rem 0; border-radius: 8px;
  cursor: pointer; flex: 0 0 auto; display: grid; place-items: center; font-size: 1.2rem; }
.row__kebab:active { background: var(--surface-2); color: var(--text); }
/* Drag-to-reorder grip. touch-action:none so the gesture starts a drag, not a
   list scroll. */
.row__grip { background: none; border: 0; color: var(--text-dim);
  width: 28px; height: 34px; margin: -.4rem .05rem -.4rem -.35rem; border-radius: 8px;
  cursor: grab; flex: 0 0 auto; display: grid; place-items: center; font-size: 1.05rem;
  touch-action: none; }
.row__grip:active { cursor: grabbing; color: var(--text); }
.row.is-dragging { opacity: .95; background: var(--surface-2); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); position: relative; z-index: 25; }
.drop-line { position: fixed; left: 0; right: 0; height: 2px; background: var(--accent);
  z-index: 24; pointer-events: none; box-shadow: 0 0 6px var(--accent); }
.item__fav { width: 16px; height: 16px; border-radius: 3px; flex: 0 0 auto; background: var(--surface-2); }
.item__sub { color: var(--text-dim); font-size: .75rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }

.empty { padding: 2.5rem 1.5rem; text-align: center; color: var(--text-dim); }

/* ── Floating add button ───────────────────────────────────── */
.fab {
  position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 1.8rem; line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); cursor: pointer; z-index: 20;
}
.fab:active { transform: scale(.96); }

/* ── Sheet / forms ─────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; background: var(--surface);
  border-radius: 16px 16px 0 0; padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
  border: 1px solid var(--border); border-bottom: 0;
}
.sheet { max-height: 88dvh; overflow-y: auto; }
.sheet__grip { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto .9rem; }
.sheet h2 { margin: 0 0 .9rem; font-size: 1.1rem; }
.field { margin-bottom: .8rem; }
.field label { display: block; font-size: .8rem; color: var(--text-dim); margin-bottom: .3rem; }
/* Inline status note in a field label (e.g. the share screen's "Fetching title…"). */
.field__hint { margin-left: .5rem; font-style: italic; opacity: .85; }
.field input, .field textarea, .field select {
  width: 100%; padding: .7rem .8rem; font-size: 1rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit;
}
.field textarea { resize: vertical; }
.field select { appearance: none; cursor: pointer; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--accent); border-color: transparent;
}

/* Status chips */
.statusrow { display: flex; gap: .45rem; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .7rem;
  font-size: .85rem; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); cursor: pointer; }
.chip.is-on { border-color: var(--accent); color: var(--text); background: #221f3d; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

/* Shared-image preview on the share landing */
.share-preview { margin: 0 0 .9rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); padding: .4rem; display: flex; justify-content: center; }
.share-preview img { max-width: 100%; max-height: 220px; border-radius: 6px; object-fit: contain; }

/* Attachments (edit sheet) */
.attach { display: flex; flex-direction: column; gap: .5rem; }
.attach-list { display: flex; flex-direction: column; gap: .4rem; }
.attach-empty { font-size: .82rem; color: var(--text-dim); }
.attach-row { display: flex; align-items: center; gap: .6rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .4rem; }
.attach-thumb { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 8px;
  background: var(--bg) center/cover no-repeat; display: grid; place-items: center; font-size: 1.1rem; }
.attach-meta { flex: 1; min-width: 0; }
.attach-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.attach-size { color: var(--text-dim); font-size: .75rem; }
.attach-del { flex: 0 0 auto; width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: none; color: var(--text-dim); font-size: 1.3rem; cursor: pointer; }
.attach-del:active { background: var(--border); color: var(--text); }

/* Section divider + label inside a sheet */
.hr { height: 1px; background: var(--border); margin: 1rem 0; }
.section-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); margin: .2rem 0 .5rem; }

/* Lifecycle (archive / trash / delete) action row */
.dangerrow { display: flex; gap: .5rem; }
.sbtn { flex: 1; min-height: var(--tap); display: flex; align-items: center;
  justify-content: center; gap: .4rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2); color: var(--text);
  font-size: .92rem; cursor: pointer; }
.sbtn:active { background: var(--border); }
.sbtn--danger { color: var(--danger); border-color: #52262a; }
.btn {
  min-height: var(--tap); padding: .65rem 1rem; font-size: 1rem; font-weight: 600;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  background: var(--surface-2); color: var(--text);
}
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--ghost { background: none; }
.btn:disabled { opacity: .5; }
.sheet__actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }
.status { font-size: .85rem; margin-top: .4rem; min-height: 1.2em; }
.status.is-ok { color: var(--ok); }
.status.is-error { color: var(--danger); }
.hint { font-size: .8rem; color: var(--text-dim); margin: -.3rem 0 .9rem; }
