:root {
  color-scheme: light;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --text: #1c1c1e;
  --text-2: #6e6e73;
  --hairline: rgba(60, 60, 67, 0.12);

  /* The accent does two jobs that need different values. As text or a border
     it must clear 4.5:1 on every surface it sits on; as a filled button it has
     to carry a white label. One value cannot do both in both themes, so the
     filled role gets its own token. */
  --accent: #0069d9;
  --accent-solid: #0069d9;
  --accent-text: #ffffff;

  /* Feedback colours in three roles: the base is the hue used for tints and
     borders, -ink is text that stays readable on top of that tint, and -solid
     is a fill that carries white text. Light mode needs the ink variants
     because the raw hues land at 1.95:1 to 2.91:1 on their own tint, which is
     unreadable at caption size. */
  --strong: #34c759;
  --strong-ink: #1e7a34;
  --ok: #ff9500;
  --ok-ink: #b25000;
  --weak: #ff3b30;
  --weak-ink: #d30015;
  --weak-solid: #d30015;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius-card: 12px;
  --radius: 8px;

  /* Type scale as roles rather than measurements, so a component asks for a
     caption instead of inventing a number. The steps are the ones the design
     actually uses, and the smallest is 12px, which is the floor for readable
     text. The 11px caption size is gone. */
  --fs-caption: 12px;
  --fs-small: 13px;
  --fs-body: 14px;
  --fs-base: 15px;
  --fs-h3: 16px;
  --fs-h2: 19px;
  --fs-h1: 22px;
  --fs-input: 16px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #ffffff;
    --text-2: #98989d;
    --hairline: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    /* A filled #0a84ff button only reaches 3.65:1 with a white label, so the
       solid role uses the deeper blue that reaches 5.22:1. */
    --accent-solid: #0069d9;
    --accent-text: #ffffff;
    /* Dark tints are light enough that the raw hues read fine as text, except
       red, which needs lifting off its own tint. */
    --strong: #30d158;
    --strong-ink: #30d158;
    --ok: #ff9f0a;
    --ok-ink: #ff9f0a;
    --weak: #ff453a;
    --weak-ink: #ff6961;
    --weak-solid: #d70015;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* The hidden attribute only suppresses rendering while no author rule sets
   display. Several components set display: flex, which silently beats it, so
   an element can be correctly marked hidden and still render: that is how an
   unstarted signup showed its "Account created" note, and how an empty notice
   box sat on the lock screen. One rule beats every component rule. */
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html { background: var(--bg); }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
#root { min-height: 100%; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
code, .mono { font-family: var(--mono); }

/* ---- Screens ---- */
.screen { display: none; }
.screen.visible { display: flex; }

.auth-screen, .lock-screen {
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* auto margins keep the card centred but scroll from the top when the keyboard shrinks the viewport */
.auth-screen .card, .lock-screen .card { margin: auto; }
.lock-screen.visible {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
}

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 28px;
}
.auth-card { width: 100%; max-width: 360px; position: relative; z-index: 1; }
.auth-card h2 { margin-bottom: 4px; }

/* Text links used inside the auth cards. */
.link-btn {
  border: none; background: none; padding: 0;
  color: var(--accent); font-size: inherit; font-weight: 500;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.auth-alt {
  margin: 14px 0 0; font-size: var(--fs-small);
  color: var(--text-2); text-align: center;
}

/* Live strength feedback for the master password. The bar is decorative: the
   written level underneath is what carries the meaning, so colour alone never
   has to be read. */
.pw-meter { display: flex; flex-direction: column; gap: 6px; margin: -2px 0 16px; }
.pw-meter[hidden] { display: none; }
.pw-meter-bar {
  height: 4px; border-radius: 3px; overflow: hidden;
  background: color-mix(in srgb, var(--text) 10%, transparent);
}
.pw-meter-fill {
  display: block; height: 100%; width: 0; border-radius: 3px;
  transition: width 0.15s ease, background-color 0.15s ease;
}
.pw-meter-fill.weak { width: 34%; background: var(--weak); }
.pw-meter-fill.ok { width: 67%; background: var(--ok); }
.pw-meter-fill.strong { width: 100%; background: var(--strong); }
.pw-meter-text { font-size: var(--fs-caption); color: var(--text-2); }
.pw-meter-text.weak { color: var(--weak-ink); }
.pw-meter-text.ok { color: var(--ok-ink); }
.pw-meter-text.strong { color: var(--strong-ink); }

/* Quiet corner motif on the auth and lock screens, desktop only. Decorative,
   so it carries no meaning and is hidden from assistive tech by being a
   generated pseudo-element. */
@media (min-width: 768px) {
  .auth-screen, .lock-screen { position: relative; overflow-x: hidden; }
  .auth-screen::before, .auth-screen::after,
  .lock-screen::before, .lock-screen::after {
    content: "";
    position: absolute;
    bottom: -56px;
    width: 250px; height: 250px;
    border: 2px solid var(--accent);
    border-radius: 58px;
    opacity: 0.10;
    pointer-events: none;
  }
  .auth-screen::before, .lock-screen::before { left: -56px; transform: rotate(14deg); }
  .auth-screen::after, .lock-screen::after { right: -56px; transform: rotate(-14deg); }
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent);
  display: inline-block; position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E") center/18px no-repeat;
}
.brand-mark.small { width: 22px; height: 22px; border-radius: 6px; }
.brand-mark.small::after { background-size: 14px; }

.tagline { color: var(--text-2); margin: 0 0 20px; }
.hint { color: var(--text-2); font-size: var(--fs-small); margin: 0 0 16px; }

.lock-notice {
  display: flex; align-items: flex-start; gap: 8px;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 38%, transparent);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px; font-size: var(--fs-small); line-height: 1.4;
  margin: 0 0 16px;
}
.lock-notice .ico { flex: none; margin-top: 1px; color: var(--ok-ink); }

.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: color-mix(in srgb, var(--text) 6%, var(--surface-2)); }
.btn:active { background: color-mix(in srgb, var(--text) 11%, var(--surface-2)); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent-solid); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { background: color-mix(in srgb, #000 8%, var(--accent-solid)); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.ghost:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.btn.danger { color: var(--weak-ink); }
.btn.danger:hover { background: color-mix(in srgb, var(--weak) 12%, transparent); }
.btn.small { padding: 5px 10px; font-size: var(--fs-small); }
.btn.icon { padding: 7px; border-radius: var(--radius); }
.btn.icon .ico { display: block; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Forms ---- */
.field { display: block; margin-bottom: 14px; font-size: var(--fs-small); color: var(--text-2); }
.field input, .field select, .field textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
}
.field-error { color: var(--weak-ink); font-size: var(--fs-small); margin: 0 0 12px; }

.inline-note {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 18px; padding: 14px;
  background: color-mix(in srgb, var(--strong) 12%, transparent);
  border-radius: var(--radius);
  font-size: var(--fs-body);
}
.inline-note > div { min-width: 0; overflow-wrap: anywhere; }
.ico-wrap.ok { color: var(--strong-ink); flex: none; margin-top: 1px; }

/* ---- App shell ---- */
.app-screen.visible {
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* track mobile browser chrome */
  overflow: hidden; /* panes scroll internally so the detail pane stays put */
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.who {
  color: var(--text-2); font-size: var(--fs-small);
  min-width: 0; max-width: 44vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.org-select {
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  font-weight: 600;
  max-width: 220px; min-width: 0;
}

.tabs {
  display: flex; gap: 2px;
  padding: 6px 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs.is-hidden { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border: none; background: transparent;
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.tab.active { color: var(--text); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab-ico { display: inline-flex; }

.views { flex: 1; display: flex; min-height: 0; min-width: 0; }
.view { flex: 1; display: flex; min-height: 0; min-width: 0; }
.view[hidden] { display: none; }
.view-split { min-height: 0; min-width: 0; }

.pane { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.list-pane {
  width: 320px; flex: none;
  border-right: 1px solid var(--hairline);
  background: var(--surface);
  display: flex; flex-direction: column;
  overflow: hidden; /* only the inner .entries list scrolls, not the pane */
}
.detail-pane { flex: 1; min-width: 0; padding: 20px; overflow-x: hidden; }

.panel { flex: 1; padding: 20px; overflow-y: auto; }
.panel-inner { max-width: 760px; }

/* ---- Toolbar / search ---- */
.toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--hairline);
}
.search-wrap { position: relative; flex: 1; }
.search-wrap .search-ico {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--text-2); display: inline-flex; pointer-events: none;
}
.search-wrap input {
  width: 100%; padding: 8px 30px 8px 32px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--text);
}
.search-wrap input:focus { outline: none; border-color: var(--accent); }

.statsline {
  padding: 8px 14px;
  font-size: var(--fs-caption); color: var(--text-2);
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* A fade under the list tells you the list continues past the pane edge. */
.list-pane { position: relative; }
.list-pane::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 26px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s ease;
}
.list-pane.list-overflow::after { opacity: 1; }

/* ---- Entry list ---- */
.entries { list-style: none; margin: 0; padding: 4px; flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.entry-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 10px 10px;
  border: none; background: transparent;
  border-radius: var(--radius);
  transition: background 0.12s ease;
}
.entry-row:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.entry-row.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.entry-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.entry-main { flex: 1; min-width: 0; }
.entry-name, .entry-sub { display: block; }
.entry-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-sub { color: var(--text-2); font-size: var(--fs-caption); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  font-size: var(--fs-caption); font-weight: 600; padding: 2px 7px; border-radius: 20px; flex: none;
  text-transform: lowercase;
}
.pill.strong { color: var(--strong-ink); background: color-mix(in srgb, var(--strong) 15%, transparent); }
.pill.ok { color: var(--ok-ink); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.pill.weak { color: var(--weak-ink); background: color-mix(in srgb, var(--weak) 15%, transparent); }

.empty, .placeholder { color: var(--text-2); text-align: center; padding: 40px 20px; }

/* ---- Grouping ---- */
.group-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  min-width: 0;
  border-bottom: 1px solid var(--hairline);
}
.group-bar-label { color: var(--text-2); font-size: var(--fs-caption); flex: none; }
.seg {
  display: flex; flex: 1; min-width: 0;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.seg-btn {
  flex: 1 1 0; min-width: 0; text-align: center;
  padding: 5px 8px;
  border: none; background: transparent;
  border-radius: 6px;
  color: var(--text-2); font-size: var(--fs-caption); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.group-head { margin: 4px 0 0; }
.group-toggle {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 8px 10px;
  border: none; background: transparent;
  border-radius: var(--radius);
  color: var(--text-2); font-size: var(--fs-caption); font-weight: 600;
  transition: background 0.12s ease, color 0.12s ease;
}
.group-toggle:hover { background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--text); }
.group-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.group-toggle .chev { display: inline-flex; flex: none; transform: rotate(90deg); transition: transform 0.15s ease; }
.group-head.is-collapsed .group-toggle .chev { transform: rotate(0deg); }
.group-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-count {
  flex: none; font-size: var(--fs-caption); font-weight: 600;
  color: var(--text-2);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  border-radius: 20px; padding: 1px 7px;
}

/* ---- Detail ---- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.detail-head h2 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.detail-back { display: none; margin-bottom: 6px; }

/* Bottom sheet grab handle and backdrop (active only on stacked layouts). */
.sheet-handle {
  display: none;
  position: sticky; top: 0; z-index: 1;
  justify-content: center;
  padding: 10px 0 6px;
  margin: 0 -16px;
  background: var(--surface);
  touch-action: none;
  cursor: grab;
}
.sheet-handle::after {
  content: ""; display: block;
  width: 38px; height: 4px; border-radius: 3px;
  background: color-mix(in srgb, var(--text) 26%, transparent);
}
.sheet-handle:active { cursor: grabbing; }

.sheet-scrim {
  position: fixed; inset: 0; z-index: 44;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
}
.detail-sub { color: var(--text-2); margin: 0 0 18px; font-size: var(--fs-small); }
.field-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
}
.field-row .fr-label { width: 96px; flex: none; color: var(--text-2); font-size: var(--fs-small); }
.field-row .fr-value { flex: 1; min-width: 0; word-break: break-word; overflow-wrap: anywhere; }
.field-row .fr-value.masked { letter-spacing: 2px; }
.fr-actions { display: flex; gap: 4px; flex: none; }
.detail-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

/* ---- Team / audit / import panels ---- */
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.panel-title h2 { min-width: 0; overflow-wrap: anywhere; }
.panel-sub { color: var(--text-2); font-size: var(--fs-small); margin: 0 0 20px; }
.section { margin-bottom: 28px; }
.section > h3 { margin-bottom: 12px; }

.table { width: 100%; border-collapse: collapse; }
.table-wrap { width: 100%; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.table th, .table td {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--hairline);
  font-size: var(--fs-body);
}
.table th { color: var(--text-2); font-weight: 500; font-size: var(--fs-caption); text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }

/* A solid chip rather than accent text on an accent tint: a tint lifts the
   background, and in dark mode a bright blue on a lifted background lands at
   3.95:1. Solid with a white label passes in both themes. */
.role-tag {
  font-size: var(--fs-caption); font-weight: 600; padding: 2px 8px; border-radius: 6px;
  background: var(--accent-solid); color: var(--accent-text);
}
.status-tag { font-size: var(--fs-caption); padding: 2px 8px; border-radius: 6px; }
.status-tag.pending { color: var(--ok-ink); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.status-tag.active { color: var(--strong-ink); background: color-mix(in srgb, var(--strong) 15%, transparent); }
.status-tag.revoked { color: var(--weak-ink); background: color-mix(in srgb, var(--weak) 15%, transparent); }

.audit-list { list-style: none; margin: 0; padding: 0; }
.audit-item {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--hairline);
  font-size: var(--fs-body);
}
.audit-when { color: var(--text-2); font-size: var(--fs-caption); flex: none; width: 150px; }
.audit-who { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.audit-action { color: var(--text-2); min-width: 0; overflow-wrap: anywhere; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  font-size: var(--fs-body); margin-bottom: 18px;
}
.notice.warn { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.notice .ico { flex: none; margin-top: 1px; }
.notice > div { min-width: 0; overflow-wrap: anywhere; }

/* ---- Modal ---- */
.modal-root {
  position: fixed; inset: 0;
  /* Above the bottom sheet and its scrim, still below the lock screen. */
  z-index: 46;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
}
.modal-root[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
.modal {
  position: relative; width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  padding: 22px;
  max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  margin: auto;
}
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.pw-row { display: flex; gap: 6px; align-items: center; }
.pw-row input { flex: 1; min-width: 0; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 22px;
  font-size: var(--fs-body); opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  max-width: calc(90vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--weak-solid); color: #fff; }

/* ---- Responsive ---- */

/* Layout: stack the list over the detail pane on narrow screens. */
@media (max-width: 760px) {
  .view-split { flex-direction: column; }
  .list-pane {
    width: 100%; border-right: none; border-bottom: 1px solid var(--hairline);
    max-height: 52vh;
  }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .who { display: none; }
  .field-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .field-row .fr-label { width: auto; }
  .fr-actions { align-self: flex-end; }
  .audit-item { flex-direction: column; gap: 2px; }
  .audit-when { width: auto; }
  .panel, .detail-pane { padding: 16px; }
  .card { padding: 22px; }
  .toolbar { padding: 10px; }
  .group-bar { padding: 6px 10px; gap: 6px; }
  .group-bar-label { display: none; }
  .statsline { padding: 6px 12px; }
  .empty, .placeholder { padding: 28px 16px; }
  .modal { padding: 18px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; }
  .table th, .table td { padding: 8px 10px; font-size: var(--fs-small); }
}

/* Touch sizing. Keyed to pointer type as well as width so landscape phones
   and tablets get it too. Fields render at 16px so the keyboard does not zoom. */
@media (max-width: 760px), (pointer: coarse) {
  .field input, .field select, .field textarea,
  .search-wrap input, .org-select, .review-table input { font-size: var(--fs-input); }
  .field input, .field select, .field textarea { padding: 12px; }
  .field { margin-bottom: 16px; }
  .search-wrap input { padding: 11px 40px 11px 34px; }
  .search-clear { width: 40px; height: 40px; right: 2px; }
  .org-select { padding: 10px 12px; }
  .btn { min-height: 48px; padding: 12px 16px; }
  .btn.small { min-height: 44px; padding: 10px 12px; }
  .btn.icon { min-width: 48px; min-height: 48px; padding: 0; }
  .tab { flex: none; min-height: 44px; padding: 10px 12px; }
  /* All three grouping options must fit. Horizontal padding stays minimal and
     the bar scrolls rather than clipping if a label is ever scaled up. */
  .group-bar {
    padding: 6px 10px; gap: 6px; min-width: 0;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  }
  .group-bar::-webkit-scrollbar { display: none; }
  .seg { flex: 1 1 0; min-width: 0; }
  .seg-btn { min-height: 44px; padding: 10px 4px; font-size: var(--fs-caption); }
  .group-toggle { min-height: 44px; padding: 12px 10px; }
  .entry-row { padding: 12px 10px; }
  .dropzone { padding: 22px 16px; }
  .show-pw { min-height: 44px; }
  .show-pw input { width: 18px; height: 18px; }
}

/* Small phones: tighten chrome and let cards use the full width. */
@media (max-width: 480px) {
  .auth-screen, .lock-screen {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .card { padding: 20px; }
  .auth-card { max-width: none; }
  .topbar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .org-select { max-width: 52vw; }
  .tabs { padding: 4px 8px; }
  .tab { padding: 10px 10px; gap: 4px; }
  /* Headings step down on small screens by redefining the scale rather than
     by overriding individual rules. */
  :root { --fs-h1: 20px; --fs-h2: 18px; }
  .panel, .detail-pane { padding: 14px; }
  .toolbar { padding: 8px; }
  .group-bar { padding: 6px 8px; }
  .list-pane { max-height: 54vh; }
  .entry-row { gap: 8px; }
  .review-bar { gap: 8px; }
  .modal-actions { justify-content: stretch; }
  .modal-actions .btn { width: 100%; }
  .overlay-card { width: calc(100vw - 40px); }
}

/* Stacked portrait: the list fills the screen and opening an entry raises a
   bottom sheet over it. The sheet can be dragged down to dismiss. */
@media (max-width: 760px) and (min-height: 521px) {
  .list-pane { max-height: none; flex: 1; }
  .detail-back { display: inline-flex; }
  .sheet-handle { display: flex; }

  .detail-pane {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    display: flex; flex-direction: column;
    max-height: 82dvh;
    background: var(--surface);
    border-top: 1px solid var(--hairline);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.25);
    padding: 0 16px calc(16px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.28s;
  }
  .view-split:not(.no-selection) .detail-pane {
    transform: translateY(0);
    visibility: visible;
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0s;
  }
  .view-split.no-selection .detail-pane { visibility: hidden; pointer-events: none; }
  .detail-pane.dragging { transition: none; }

  .detail-head { padding-top: 4px; }

  /* Scrim behind the sheet. Tapping it closes the entry. */
  .view-split:not(.no-selection) .sheet-scrim { opacity: 1; pointer-events: auto; }
}

/* Short landscape (phone turned sideways): split side by side again so the
   list does not eat the whole height, and compact the chrome. Needs enough
   width for two readable panes, otherwise a short window squeezes the list
   and truncates the grouping control. */
@media (max-width: 760px) and (min-width: 560px) and (max-height: 520px) {
  .view-split { flex-direction: row; }
  .list-pane {
    width: 46%; max-height: none;
    border-right: 1px solid var(--hairline);
    border-bottom: none;
  }
  .detail-pane { padding: 14px; }
  .field-row { flex-direction: row; align-items: center; gap: 10px; }
  .field-row .fr-label { width: 84px; }
  .fr-actions { align-self: auto; }
  .topbar { padding-top: calc(6px + env(safe-area-inset-top, 0px)); padding-bottom: 6px; }
  .tabs { padding-top: 2px; padding-bottom: 2px; }
  .tab { min-height: 38px; padding: 6px 10px; }
  .toolbar { padding: 8px; }
  .group-bar { padding: 4px 8px; }
  .statsline { padding: 4px 10px; }
  .group-toggle { min-height: 34px; padding: 5px 8px; }
  .seg-btn { min-height: 32px; padding: 5px 8px; }
  .entry-row { padding: 8px 10px; }
  .empty, .placeholder { padding: 18px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .tabs { scroll-behavior: auto; }
}

/* ---- Paste text import + review table ---- */
.field textarea { resize: vertical; min-height: 140px; line-height: 1.5; }

.review-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 12px 0; flex-wrap: wrap;
}
.show-pw { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-small); color: var(--text-2); cursor: pointer; }
.show-pw input { accent-color: var(--accent); }

.row-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.review-table-wrap { overflow-x: auto; }
.review-table { width: 100%; border-collapse: collapse; }
.review-table th, .review-table td {
  text-align: left; padding: 6px 6px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}
.review-table th {
  color: var(--text-2); font-weight: 500; font-size: var(--fs-caption);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.review-table td.right, .review-table th.right { text-align: right; width: 1%; white-space: nowrap; }
.review-table input {
  width: 100%; min-width: 90px;
  padding: 7px 9px;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  color: var(--text);
  font-size: var(--fs-small);
  transition: border-color 0.15s ease;
}
.review-table input:focus { outline: none; border-color: var(--accent); }
.review-table input.missing {
  border-color: var(--weak-ink);
  background: color-mix(in srgb, var(--weak) 10%, var(--surface-2));
}
.review-table td:first-child input { min-width: 130px; }

/* ---- Dropzone (CSV drag and drop) ---- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; text-align: center;
  padding: 26px 20px; margin-top: 4px;
  background: var(--surface-2);
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-card);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease;
}
.dropzone .ico { color: var(--text-2); transition: color 160ms ease; }
.dropzone-title { font-size: var(--fs-body); color: var(--text); font-weight: 500; }
.dropzone-sub { font-size: var(--fs-small); }
.dropzone-browse { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.dropzone:hover { border-color: var(--accent); }
.dropzone:hover .ico { color: var(--accent); }
.dropzone.is-over {
  border-color: var(--accent); border-style: solid;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface-2));
}
.dropzone.is-over .ico { color: var(--accent); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Loading indicators ---- */
.spin { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.spin .ico { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn.is-loading { cursor: progress; opacity: 0.75; }
.btn .spin { vertical-align: middle; }
.spin-label { margin-left: 8px; }

.overlay-loader {
  position: fixed; inset: 0; z-index: 70;
  display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.overlay-loader.visible { display: flex; }
.overlay-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: min(280px, calc(100vw - 48px)); text-align: center;
  background: var(--surface); color: var(--text);
  padding: 28px 24px; border-radius: var(--radius-card);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow);
}
.overlay-card .brand-mark { width: 34px; height: 34px; border-radius: 8px; }
.overlay-card .brand-mark::after { background-size: 20px; }
.overlay-label { font-size: var(--fs-body); color: var(--text-2); }
.overlay-card .spin .ico { animation-duration: 0.9s; }

.inline-loader { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: var(--fs-small); }

@media (prefers-reduced-motion: reduce) {
  .spin .ico { animation: none; }
  .dropzone, .dropzone .ico { transition: none; }
}

/* ---- Keyboard focus on fields ----
   Buttons already draw a 2px ring on :focus-visible, but fields only swapped
   their border colour, which is easy to miss. This has to come after every
   `:focus { outline: none }` rule above so source order gives it the win. */
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible,
.search-wrap input:focus-visible, .review-table input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---- Search clear ---- */
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  border: none; background: transparent; border-radius: 6px;
  color: var(--text-2); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.search-clear:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.search-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.search-clear[hidden] { display: none; }

/* ---- Empty state ----
   The first-run screen offers the two things worth doing rather than only
   describing what is missing. */
.empty-lead { color: var(--text); font-weight: 500; margin: 0 0 6px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---- Utilities ----
   Small spacing and layout helpers. These exist so inline style attributes
   can stay out of the markup, which is what lets style-src remain 'self'. */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.table td.right { text-align: right; white-space: nowrap; }
.invite-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.field-grow { flex: 1; min-width: 200px; margin-bottom: 0; }
.field-role { width: 140px; margin-bottom: 0; }
.token-code { word-break: break-all; font-size: var(--fs-caption); }

/* ---- Audit controls ---- */
.audit-bar {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 12px; min-width: 0;
}
.audit-bar .search-wrap { min-width: 0; }
.pager {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  margin-top: 14px; flex-wrap: wrap;
}
.pager-label { font-size: var(--fs-caption); color: var(--text-2); }

/* ---- Confirmations with an option ---- */
.check-row {
  display: flex; align-items: flex-start; gap: 9px;
  margin: 4px 0 6px; font-size: var(--fs-small); color: var(--text);
  line-height: 1.45; cursor: pointer;
}
.check-row input {
  width: 18px; height: 18px; margin: 2px 0 0; flex: none;
  accent-color: var(--accent); cursor: pointer;
}
.check-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Vault health ---- */
.health-note {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--weak) 10%, transparent);
  border-bottom: 1px solid var(--hairline);
  font-size: var(--fs-small);
}
.health-note[hidden] { display: none; }
.health-note > .ico { color: var(--weak-ink); flex: none; display: inline-flex; margin-top: 2px; }
.health-body { min-width: 0; }
.health-title { color: var(--weak-ink); font-weight: 600; }
.health-list {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-top: 7px;
}
.health-link {
  max-width: 100%; min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--hairline); background: var(--surface-2);
  border-radius: 6px; cursor: pointer;
  font-size: var(--fs-caption); color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: border-color 0.15s ease;
}
.health-link:hover { border-color: var(--weak-ink); }
.health-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.health-more { font-size: var(--fs-caption); color: var(--text-2); }

@media (max-width: 760px), (pointer: coarse) {
  .health-link { min-height: 44px; padding: 10px 12px; }
  .check-row { min-height: 44px; align-items: center; margin-top: 8px; margin-bottom: 8px; }
  .check-row input { width: 20px; height: 20px; margin-top: 0; }
  .invite-item { flex-wrap: wrap; min-height: 44px; }
  .invite-actions .btn { min-height: 44px; }
  .org-item { min-height: 44px; }
}

/* ---- Account: vault membership ---- */
.org-list, .invite-list { list-style: none; margin: 0; padding: 0; }
.org-item, .invite-item {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: var(--fs-body);
}
.org-list li:last-child, .invite-list li:last-child { border-bottom: none; }
.org-name {
  display: flex; gap: 8px; align-items: center; min-width: 0;
  overflow-wrap: anywhere;
}
.invite-who {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  min-width: 0; overflow-wrap: anywhere;
}
.invite-expiry { font-size: var(--fs-caption); color: var(--text-2); }
.invite-actions { display: flex; gap: 6px; flex: none; }
