/* Copied from app/ui/styles.css (the desktop app) so both look the same.
   Browser-only additions are at the end. Keep the tokens in sync. */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --sidebar: #efeee9;
  --text: #1f2120;
  --muted: #6c6f6c;
  --faint: #9a9d99;
  --border: #e4e2dc;
  --hover: #f1f0ec;
  --accent: #2f5d52;
  --accent-text: #ffffff;
  --accent-soft: #e3ece8;
  --danger: #b3402f;
  --focus: rgba(47, 93, 82, .28);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171817;
    --surface: #1e201f;
    --sidebar: #1a1c1b;
    --text: #e9eae7;
    --muted: #a0a39f;
    --faint: #707370;
    --border: #2d302e;
    --hover: #242725;
    --accent: #7fb3a4;
    --accent-text: #10201b;
    --accent-soft: #233630;
    --danger: #e58572;
    --focus: rgba(127, 179, 164, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
input, textarea, button { font: inherit; color: inherit; }
input, textarea { user-select: text; -webkit-user-select: text; }
code, .mono { font-family: var(--mono); font-size: .92em; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.dragbar { position: fixed; inset: 0 0 auto 0; height: 28px; z-index: 5; }

/* ----- buttons & fields ----- */
button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 12px;
  background: none;
  cursor: default;
}
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 500; }
button.primary:hover { filter: brightness(1.06); }
button.ghost { color: var(--muted); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--hover); }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}
input[type="password"], input[type="text"], input[type="search"], textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 10px;
}
textarea { resize: none; font-family: var(--mono); min-height: 38px; }

/* ----- gate screens ----- */
.gate { height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(340px, 100%); display: grid; gap: 12px; text-align: center; }
.gate-card label { display: grid; gap: 6px; text-align: left; color: var(--muted); font-size: 13px; }
.gate-card h1 { margin: 4px 0 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.gate-card .lede { margin: 0 0 8px; color: var(--muted); }
.gate-card button.primary { padding: 9px 12px; }
.mark {
  width: 48px; height: 48px; margin: 0 auto; border-radius: 12px; background: var(--accent);
  position: relative;
}
.mark::after {
  content: ""; position: absolute; inset: 12px 13px 12px 13px; border-radius: 3px;
  background: var(--bg); clip-path: polygon(0 0, 68% 0, 100% 32%, 100% 100%, 0 100%);
}
.hint { margin: 0; color: var(--faint); font-size: 12.5px; }
.error { margin: 0; min-height: 1em; color: var(--danger); font-size: 13px; }

/* ----- main shell ----- */
.shell { display: grid; grid-template-columns: 210px 1fr; height: 100%; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-top { height: 44px; flex: none; }
#projects { flex: 1; overflow: auto; padding: 4px 8px; }
.nav-label { color: var(--faint); font-size: 11.5px; font-weight: 500; padding: 12px 8px 4px; text-transform: uppercase; letter-spacing: .04em; }
.nav-item {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  text-align: left; padding: 5px 8px; border-radius: 6px; color: var(--text);
}
.nav-item:hover { background: var(--hover); }
.nav-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item .count { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.sidebar-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px; padding: 8px; border-top: 1px solid var(--border); }
.sidebar-foot button { padding: 6px 8px; font-size: 13px; }
#bio-toggle[aria-checked="true"] { color: var(--accent); }
#bio-btn + .hint { margin-top: -4px; }
.gate-card .or { color: var(--faint); font-size: 12px; margin: 2px 0; }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 16px 8px; padding-top: 12px; }
.search { position: relative; flex: 1; }
.search input { padding-right: 44px; }
.search input:not(:placeholder-shown) + kbd { display: none; }
.search kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font: 11px var(--font); color: var(--faint); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px;
}
.envbar { display: flex; gap: 4px; align-items: center; padding: 0 16px 6px; min-height: 30px; }
.chip { padding: 3px 10px; border-radius: 999px; color: var(--muted); font-size: 13px; }
.chip:hover { background: var(--hover); color: var(--text); }
.chip[aria-current="true"] { background: var(--surface); color: var(--text); border-color: var(--border); }
.envbar .spacer { flex: 1; }
.envbar .title { font-weight: 600; margin-right: 8px; }

.bulkbar {
  display: flex; gap: 6px; align-items: center; margin: 0 16px 6px; padding: 6px 8px 6px 12px;
  border-radius: var(--radius); background: var(--accent-soft); color: var(--accent);
}
.bulkbar .spacer { flex: 1; }
.bulkbar input { width: 130px; padding: 4px 8px; }

/* ----- list ----- */
.list { list-style: none; margin: 0; padding: 0 8px 16px; overflow: auto; flex: 1; }
.row {
  display: grid; grid-template-columns: 20px minmax(120px, 1.1fr) minmax(80px, 1fr) auto;
  gap: 10px; align-items: center; padding: 7px 8px; border-radius: 6px;
}
.row:hover { background: var(--hover); }
.row.cursor { background: var(--hover); box-shadow: inset 2px 0 0 var(--accent); }
.row input[type="checkbox"] { margin: 0; accent-color: var(--accent); }
.row .name { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .where { color: var(--faint); font-size: 12px; margin-left: 6px; font-family: var(--font); }
.row .value { color: var(--faint); font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .value.shown { color: var(--text); user-select: text; -webkit-user-select: text; }
.row .actions { display: flex; gap: 2px; opacity: 0; }
.row:hover .actions, .row.cursor .actions, .row:focus-within .actions { opacity: 1; }
.row .actions button { padding: 3px 8px; font-size: 12.5px; color: var(--muted); }
.row .actions button:hover { background: var(--surface); color: var(--text); }

.editor {
  margin: 4px 0 8px; padding: 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); display: grid; gap: 10px;
  grid-template-columns: 1fr 1fr;
}
.editor label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.editor .wide { grid-column: 1 / -1; }
.editor input[name="name"] { font-family: var(--mono); }
.editor .buttons { grid-column: 1 / -1; display: flex; gap: 6px; }
.editor .buttons .spacer { flex: 1; }
.editor .error { grid-column: 1 / -1; }

.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px 24px; max-width: 360px; }
.empty-title { color: var(--text); font-weight: 600; margin: 0 0 4px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }

/* ----- overlays ----- */
.dropzone {
  position: fixed; inset: 10px; border: 2px dashed var(--accent); border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center;
  font-size: 15px; z-index: 20;
}
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 8px 8px 14px; border-radius: 10px;
  display: flex; gap: 10px; align-items: center; font-size: 13px; z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: calc(100% - 32px);
}
.toast button { color: var(--bg); font-weight: 600; padding: 3px 8px; }
.toast button:hover { background: rgba(127,127,127,.25); }
.toast.plain { padding-right: 14px; }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .row { grid-template-columns: 20px 1fr auto; }
  .row .value { display: none; }
}

/* ----- recovery ----- */
button.link { color: var(--muted); padding: 2px; font-size: 13px; justify-self: center; }
button.link:hover { color: var(--text); text-decoration: underline; }
.kit { width: min(400px, 100%); }
.kit-code {
  font-size: 19px; letter-spacing: .06em; padding: 16px 12px; border-radius: 10px;
  border: 1px dashed var(--accent); background: var(--surface); color: var(--text);
  user-select: all; -webkit-user-select: all; word-break: break-all;
}
.kit-actions { display: flex; gap: 8px; justify-content: center; }
.check { display: flex !important; flex-direction: row; gap: 8px; align-items: center; justify-content: center; color: var(--text) !important; font-size: 13.5px !important; }
.check input { accent-color: var(--accent); margin: 0; }
.print-only { display: none; }
.notice {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between;
  margin: 0 16px 8px; padding: 8px 8px 8px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--muted);
}
.notice form { display: flex; gap: 6px; }
.notice input { width: 170px; padding: 5px 8px; }
.notice button { padding: 5px 10px; }

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #333; --faint: #555; --accent: #000; }
  body { overflow: visible; }
  .no-print, .dragbar, .toast, .shell, [data-screen]:not([data-screen="kit"]) { display: none !important; }
  .print-only { display: block; }
  .gate { height: auto; padding: 40px 0; }
  .kit-code { font-size: 24px; }
}

button:disabled { opacity: .45; filter: none !important; }

/* ===================== browser vault additions ===================== */

:root[data-theme="light"] { color-scheme: light; }
html { background: var(--bg); }
body { overflow: hidden; }
.noscript { padding: 24px; text-align: center; color: var(--muted); }
input[type="email"] {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius); padding: 8px 10px;
}
input[type="email"]:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
input[type="text"]:focus-visible, input[type="search"]:focus-visible { outline: none; }
a.button {
  display: block; text-decoration: none; border-radius: var(--radius); padding: 9px 12px; text-align: center;
}
a.button.primary { background: var(--accent); color: var(--accent-text); font-weight: 500; }
a.button.primary:hover { filter: brightness(1.06); }
a.button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
button { cursor: pointer; }
button:disabled { cursor: default; }

/* sidebar brand + footer */
.sidebar-top { display: flex; align-items: center; padding: 0 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.01em; }
.mark.small { width: 20px; height: 20px; border-radius: 5px; margin: 0; }
.mark.small::after { inset: 5px 5px 5px 6px; border-radius: 1.5px; }
.sidebar-foot { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 4px; }
.foot-row { display: flex; justify-content: space-between; align-items: center; gap: 2px; }
.who { color: var(--faint); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 8px; min-width: 0; }
.sync { display: flex; align-items: center; gap: 6px; padding: 2px 8px 4px; font-size: 12px; color: var(--faint); min-height: 22px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .7; flex: none; }
.sync[data-state="busy"]::before { background: var(--faint); animation: pulse 1s ease-in-out infinite; }
.sync[data-state="error"] { color: var(--danger); }
.sync[data-state="error"]::before { background: var(--danger); }
.sync button { padding: 0 4px; font-size: 12px; color: inherit; text-decoration: underline; }
@keyframes pulse { 50% { opacity: .25; } }

/* the menu button only shows when the sidebar becomes a drawer */
.menu-btn { display: none; padding: 6px 7px; line-height: 0; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .28); z-index: 9; }

/* read-only rows (shared projects you can only read) */
.row .ro { color: var(--faint); font-size: 11.5px; margin-left: 6px; font-family: var(--font); }

/* .env importer */
.importer {
  margin: 0 16px 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); display: grid; gap: 10px;
}
.importer-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.importer textarea { min-height: 120px; resize: vertical; font-size: 12.5px; }
.importer-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.importer-foot label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; width: 160px; }
.importer-foot .spacer { flex: 1; }
.importer .error:empty { display: none; }

/* keyboard help */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .28); z-index: 40; padding: 16px; }
.help-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px 14px;
  width: min(420px, 100%); box-shadow: 0 12px 40px rgba(0, 0, 0, .2); display: grid; gap: 10px;
}
.help-card h2 { margin: 0; font-size: 15px; }
.help-card > button { justify-self: end; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
kbd.k { font: 11.5px var(--font); color: var(--muted); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; margin-right: 2px; }

/* busy (key derivation takes a second) */
.busy { position: fixed; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 50; }
.busy-card { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, .12); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner, .sync[data-state="busy"]::before { animation: none; } }

/* phone and narrow windows: the sidebar slides in as a drawer */
@media (max-width: 720px) {
  .sidebar {
    display: flex; position: fixed; inset: 0 auto 0 0; width: min(280px, 84vw); z-index: 10;
    transform: translateX(-102%); transition: transform .18s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .2);
  }
  body.drawer .sidebar { transform: none; }
  .menu-btn { display: inline-block; }
  .toolbar { padding: 10px 16px 8px; }
  .search kbd { display: none; }
  .envbar { flex-wrap: wrap; row-gap: 6px; }
  .row { grid-template-columns: 20px minmax(0, 1fr) auto; }
  .row .actions { opacity: 1; }
  .editor { grid-template-columns: 1fr; }
  .bulkbar { flex-wrap: wrap; }
  .importer-foot label { width: calc(50% - 4px); }
  .gate-card { padding-top: 8vh; align-self: start; }
  .gate { padding: 16px; }
}
@media (hover: none) {
  .row .actions { opacity: 1; }
}

/* ----- icons (inline SVG sprite in index.html) ----- */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg.icon {
  width: 16px; height: 16px; display: block; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
button.icon-btn, .sidebar-foot button.icon-btn { padding: 6px; line-height: 0; display: inline-grid; place-items: center; }
.row .actions button.icon-btn { padding: 5px 6px; }
.row .actions button.icon-btn[data-act="delete-row"]:hover { color: var(--danger); }
.toolbar .add-btn { padding: 8px 10px; }
.toolbar .add-btn svg.icon { width: 17px; height: 17px; stroke-width: 2; }
.bulkbar button.icon-btn { color: var(--accent); }
.bulkbar button.icon-btn.danger { color: var(--danger); }
.bulkbar button.icon-btn:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.editor .buttons button.icon-btn { padding: 7px 9px; }
.foot-icons { display: inline-flex; align-items: center; gap: 0; flex: none; }
.sidebar-foot .foot-row { gap: 4px; }
.sidebar-foot .sync { padding: 0 8px; min-width: 0; }

/* ----- language picker ----- */
.lang-pick {
  position: relative; display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); border-radius: var(--radius); padding: 0 4px 0 6px; font-size: 12.5px;
}
.lang-pick:hover { background: var(--hover); color: var(--text); }
.lang-pick select {
  appearance: none; -webkit-appearance: none; border: 0; background: none; color: inherit;
  font: inherit; padding: 5px 2px; cursor: pointer; max-width: 76px;
}
.lang-pick select:focus-visible { outline: none; }
.lang-pick:focus-within { box-shadow: 0 0 0 3px var(--focus); }
.lang-pick select option { color: var(--text); background: var(--surface); }
.gate { position: relative; }
.gate-lang { position: absolute; left: 0; right: 0; bottom: 18px; display: flex; justify-content: center; }
.gate-lang .lang-pick select { max-width: none; }
@media (max-width: 720px) {
  .gate-lang { position: static; margin-top: 16px; }
  .gate { align-content: start; grid-auto-rows: min-content; }
}
/* the drawer button is for narrow screens only (after the icon-btn rule on purpose) */
button.icon-btn.menu-btn { display: none; }
@media (max-width: 720px) { button.icon-btn.menu-btn { display: inline-grid; } }
