:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ee;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --primary: #5b5bd6;
  --primary-soft: #eef0ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --neutral: #9ca3af;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}

.app-error {
  margin: 12px 32px 0;
  padding: 10px 14px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.brand:hover { opacity: 0.75; }
.brand-logo {
  width: auto; height: 36px;
  display: block; object-fit: contain;
}
.brand-subtitle { font-size: 12px; color: var(--text-muted); }

.header-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.current-user { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 1; }
.current-user-label { color: var(--text-muted); }
.current-user-name { font-weight: 600; color: var(--text); }
.logout-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 24px; white-space: nowrap;
  margin-left: 6px; padding: 2px 9px 4px; border-radius: 6px;
  border: 1px solid var(--border); background: transparent;
  font: inherit; font-size: 12px; line-height: 16px; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

nav { display: flex; gap: 4px; justify-content: flex-end; }
nav button {
  background: transparent; border: none;
  padding: 2px 10px; border-radius: 6px;
  font: inherit; font-size: 13px; line-height: 20px; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s;
}
nav button:hover { background: var(--surface-2); color: var(--text); }
nav button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

main { max-width: 1180px; margin: 28px auto; padding: 0 32px; }

.preset {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s;
}
.preset:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 8px 16px; border-radius: 8px; font: inherit; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.btn-primary:hover { filter: brightness(1.05); }
.grow { flex: 1; }

.row-delete {
  background: transparent; color: #991b1b; border: 1px solid #fecaca;
  padding: 4px 10px; border-radius: 6px; font: inherit; font-size: 12px;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.row-delete:hover { background: #fee2e2; border-color: #f87171; }
.row-confirm {
  background: transparent; color: #059669; border: 1px solid #059669;
  padding: 4px 10px; border-radius: 6px; font: inherit; font-size: 12px;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.row-confirm:hover { background: #d1fae5; }
.row-cancel {
  background: transparent; color: var(--text-muted); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 6px; font: inherit; font-size: 12px;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.row-cancel:hover { background: var(--surface-2); color: var(--text); }
.row-actions {
  text-align: right;
  width: auto;
  white-space: nowrap;
}
.row-actions button + button { margin-left: 6px; }
tr.user-grant .row-actions button,
tr.service-member .row-actions button,
tr.row-pending-grant .row-actions button,
tr.row-pending-revoke .row-actions button { opacity: 0; }
tr.user-grant:hover .row-actions button,
tr.service-member:hover .row-actions button,
tr.row-pending-grant:hover .row-actions button,
tr.row-pending-revoke:hover .row-actions button,
tr.user-grant:focus-within .row-actions button,
tr.service-member:focus-within .row-actions button,
tr.row-pending-grant:focus-within .row-actions button,
tr.row-pending-revoke:focus-within .row-actions button { opacity: 1; }

.status-dot {
  position: relative;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: 0.1em;
}
.status-dot-grant  { background: var(--warning); }
.status-dot-revoke { background: var(--danger); }
.status-dot-text {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
@media (hover: hover) {
  .status-dot { cursor: help; }
  .status-dot::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; }
  .status-dot:hover .status-dot-text {
    left: 16px; top: -6px; z-index: 5;
    width: auto; height: auto; margin: 0; padding: 2px 8px;
    overflow: visible; clip: auto;
    border-radius: 6px; background: var(--text); color: var(--surface);
    font-size: 12px; font-weight: 500; line-height: 16px;
  }
}
@media (hover: none) {
  .status-dot {
    display: table;
    width: auto; height: auto;
    margin: 0 0 4px; padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px; font-weight: 600; line-height: 16px;
    color: var(--text);
  }
  .status-dot-grant  { background: color-mix(in srgb, var(--warning) 20%, var(--surface)); }
  .status-dot-revoke { background: color-mix(in srgb, var(--danger) 20%, var(--surface)); }
  .status-dot-text { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }
}
.row-trash {
  background: transparent; color: var(--text-muted); border: none;
  padding: 4px 8px; border-radius: 6px; font: inherit; font-size: 16px;
  line-height: 1; cursor: pointer; opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}
tbody tr:hover .row-trash, .row-trash:focus { opacity: 1; }
.row-trash:hover { background: #fee2e2; color: #991b1b; }
.sub-actions { margin-top: 10px; text-align: right; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: 600; }
.panel-meta { font-size: 13px; color: var(--text-muted); display: flex; gap: 0; align-items: baseline; }
.panel-meta > span:first-child { color: var(--text); font-weight: 600; }
.panel-meta-sep { padding: 0 2px; }

table { width: 100%; border-collapse: collapse; }
/* Balance data columns; Team uses the remainder and wraps naturally. */
table:has(#th-users-fullName) { table-layout: fixed; }
#th-users-fullName { width: 30%; }
/* Target widths: 123.8px measured in Liberation Sans + ~5% headroom for the
   macOS system font + 40px cell padding. */
#th-users-targetName { width: 172px; }
/* Pending grants: keep the button column at the buttons' width so User,
   Service and Request by share the rest instead of leaving a blank right side. */
table:has(#th-pending-fullName) { table-layout: fixed; }
table:has(#th-pending-fullName) th:last-child { width: 280px; }
/* Service members: Name, Team and Target take the rest of the row. The button
   column is only as wide as Confirm/Cancel, and stays inside the card. */
table:has(#th-members-fullName) { table-layout: fixed; }
table:has(#th-members-fullName) th:last-child,
table:has(#th-members-fullName) td.row-actions {
  width: 272px;
  box-sizing: border-box;
  padding-left: 8px;
  padding-right: 12px;
  white-space: nowrap;
  position: static;
}
/* Members widths apply only from 824px: 760px max card + 64px main padding. */
@media (min-width: 824px) {
  #th-members-fullName { width: 18%; }
  #th-members-targetName { width: 172px; }
}
thead th {
  text-align: left; padding: 10px 20px; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 20px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; }
.currency { color: var(--text-muted); font-size: 12px; margin-left: 4px; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.pill.planned { background: #e0e7ff; color: #4338ca; }
.pill.paid { background: #d1fae5; color: #065f46; }
.pill.partially_paid { background: #fef3c7; color: #92400e; }
.pill.failed { background: #fee2e2; color: #991b1b; }
.pill.cancelled { background: #f3f4f6; color: #6b7280; }
.pill.refunded { background: #ede9fe; color: #6d28d9; }

.status-select {
  padding: 3px 8px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase;
  cursor: pointer; appearance: none; -webkit-appearance: none;
}
.status-select.planned { background: #e0e7ff; color: #4338ca; }
.status-select.paid { background: #d1fae5; color: #065f46; }
.status-select.partially_paid { background: #fef3c7; color: #92400e; }
.status-select.failed { background: #fee2e2; color: #991b1b; }
.status-select.cancelled { background: #f3f4f6; color: #6b7280; }
.status-select.refunded { background: #ede9fe; color: #6d28d9; }
.status-select option { text-transform: none; color: var(--text); background: var(--surface); }

.empty { padding: 60px 20px; text-align: center; color: var(--text-muted); }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 6px; font-size: 15px; }

.stat-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.05em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.sub-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}
.sub-grid > div {
  display: flex;
  flex-direction: column;
}
.sub-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
  flex: 1;
  box-sizing: border-box;
}
.sub-title { font-weight: 600; font-size: 15px; }
.prov-badge {
  display: inline-block; min-width: 0; font-size: 11px; line-height: 16px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; overflow-wrap: anywhere;
  background: var(--bg); color: var(--text);
}
.panel-title .prov-badge { margin-left: 8px; vertical-align: middle; }
.prov-none { display: none; }

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  box-sizing: border-box;
  /* Matches the service card (logo row + two text rows + padding). */
  min-height: 194px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.group-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(91, 91, 214, 0.12);
}
.group-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.group-card-name {
  color: #000;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
}
.group-card-count {
  color: #000;
  font-size: 13px;
  font-weight: 600;
}
.group-card-preview {
  display: grid;
  grid-template-columns: repeat(var(--preview-cols, 4), minmax(0, 1fr));
  gap: 8px;
  flex: 1;
  align-content: center;
}
.group-preview-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.group-preview-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}
.group-preview-spacer { display: none; }
.group-preview-name {
  width: 100%;
  font-size: 11px;
  line-height: 1.2;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); }
.sub-amount { font-size: 22px; font-weight: 700; color: var(--text); }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--danger); color: white;
  padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .app-header { padding: 14px 16px; flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-right { width: 100%; align-items: flex-start; }
  main { padding: 0 16px; }
  nav { width: 100%; overflow-x: auto; justify-content: flex-start; }
}

/* ---- Login overlay ------------------------------------------------------- */

.login-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.6);
  z-index: 1000;
}

.login-card {
  background: var(--card, white);
  border-radius: 12px;
  padding: 28px 32px;
  width: min(420px, 92vw);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; gap: 16px;
}

.login-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.login-title {
  font-size: 1.2rem; font-weight: 600;
}

.login-back {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0 2px;
  transform: translate(-4px, 4px);
}
.login-back:hover { color: var(--text); }

/* "Log in with authenticator code (AI agents)" under Send code, and the
   authenticator step it opens (its fields stacked like the card's). */
.login-alt {
  display: block; margin: 16px auto 0;
  background: none; border: none; padding: 0;
  font: inherit; font-size: 0.85rem; color: var(--primary); cursor: pointer;
}
.login-alt:hover { text-decoration: underline; }
.login-step { display: flex; flex-direction: column; gap: 16px; }
.login-step > .btn-primary { align-self: flex-start; }

.login-error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger, #dc2626);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.notify-card .login-error { margin-top: 16px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 0.85rem; color: var(--muted, #64748b); }
.form-hint  { font-size: 0.75rem; color: var(--muted, #94a3b8); }

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  font-size: 1rem;
}

.btn-secondary {
  background: transparent;
  color: var(--muted, #64748b);
  border: 1px solid var(--border, #e2e8f0);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  margin-left: 8px;
}
.btn-secondary:hover { background: var(--surface-2, #f1f5f9); }

/* ---- Add expense form --------------------------------------------------- */

.add-expense {
  max-width: 640px;
  margin: 24px auto;
  padding: 24px;
  background: var(--card, white);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  display: flex; flex-direction: column; gap: 16px;
}

.add-expense h2 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 600; }

.add-expense input,
.add-expense select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  font-size: 1rem;
  background: white;
}

.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

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

.form-flash {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}

/* ---- Dictionaries ------------------------------------------------------- */

.dictionaries {
  max-width: 720px;
  margin: 24px auto;
  padding: 24px;
  background: var(--card, white);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  display: flex; flex-direction: column; gap: 24px;
}

.dictionaries h2 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.dict-section h3 { margin: 0 0 10px; font-size: 1rem; font-weight: 600; }

.dict-list {
  margin: 0 0 12px; padding: 0;
  border: 1px solid var(--border, #e2e8f0); border-radius: 8px;
  max-height: 260px; overflow: auto;
}
.dict-list-item {
  padding: 8px 12px; border-bottom: 1px solid var(--border, #f1f5f9);
  font-size: 0.95rem;
}
.dict-list-item:last-child { border-bottom: none; }

.dict-add-row { display: flex; gap: 8px; align-items: center; }
.dict-add-row input,
.dict-add-row select {
  padding: 9px 11px; border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px; font-size: 0.95rem; background: white;
}
.dict-add-row input { flex: 1; }

/* ---- Add: expense/subscription segmented toggle ------------------------- */

.segmented { display: flex; gap: 0; margin-bottom: 8px; }
.seg-button {
  flex: 1; padding: 9px 14px; cursor: pointer;
  border: 1px solid var(--border, #e2e8f0); background: white;
  font-size: 0.95rem; color: var(--muted, #64748b);
}
.seg-button:first-child { border-radius: 6px 0 0 6px; }
.seg-button:last-child  { border-radius: 0 6px 6px 0; border-left: none; }
.seg-button.active {
  background: var(--primary, #6366f1); color: white;
  border-color: var(--primary, #6366f1);
}

/* ---- Members directory additions ------------------------------------- */
.brand-title {
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  /* Wordmark ink sits above the PNG center; keep "Access" on that line. */
  transform: translateY(-3px);
  letter-spacing: -0.015em;
  color: var(--text);
  margin-left: 4px;
  padding-left: 18px;
  border-left: 1px solid var(--border);
}

.uuid {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #6b7280;
  word-break: break-all;
}

.detail { max-width: 760px; margin: 24px auto; }
.detail .panel { padding: 28px 32px; }
.detail h2 { margin: 0 0 20px; font-size: 22px; }

.detail-row {
  display: flex;
  gap: 28px;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid #eef0f3;
}
.detail-row:last-child { border-bottom: none; }

.detail-label {
  flex: 0 0 170px;
  color: #6b7280;
  font-size: 13px;
}

.detail-row span:last-child { font-size: 15px; }

.detail .form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.clickable-row { cursor: pointer; }

.th-search { position: relative; cursor: pointer; user-select: none; white-space: nowrap; }
.th-search:hover { color: var(--primary, #5b5bd6); }
.th-search.is-open { cursor: text; }
.th-search.is-open:hover { color: inherit; }
.th-search-label {
  display: inline-flex; align-items: center; gap: 6px;
  border-bottom: 1px dashed var(--text-muted);
}
.th-search-glyph { font-size: 13px; line-height: 1; text-transform: none; letter-spacing: 0; }
.th-search.is-open .th-search-label { visibility: hidden; }
.th-search-input {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: calc(100% - 40px);
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  line-height: inherit;
  letter-spacing: normal;
  text-transform: none;
  color: inherit;
  outline: none;
  opacity: 0;
  pointer-events: none;
  box-sizing: border-box;
}
.th-search.is-open .th-search-input {
  opacity: 1;
  pointer-events: auto;
}
.th-search-input::placeholder {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: inherit;
  opacity: 1;
}

/* ---- Access: service cards + grant bar ---------------------------------- */
.clickable-card { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.clickable-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(91, 91, 214, 0.12); }

.service-logo-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 64px; margin-bottom: 6px;
}
.service-logo {
  max-height: 56px; max-width: 100%;
  object-fit: contain; display: block;
}

.detail .panel { padding: 0; overflow: visible; }
.detail .panel-header { padding: 16px 20px; border-radius: 12px 12px 0 0; }
.detail-desc { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }
.prov-hint { color: var(--text-muted); font-size: 13px; margin: -8px 0 16px; }
.auth-note { margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.auth-note-input {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: white;
  color: var(--text);
}
.auth-note-input:focus { outline: none; border-color: var(--primary); }

.grant-bar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 20px;
  position: relative;
  z-index: 20;
}
.suggest { position: relative; flex: 1; min-width: 0; }
.suggest-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: white;
  color: var(--text);
}
.suggest-input:focus { outline: none; border-color: var(--primary); }
.suggest-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: var(--suggest-room, min(420px, calc(100vh - 24px)));
  overflow: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.suggest-group {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.suggest-group:hover { background: #f3f4f8; }
.suggest-group .suggest-meta { margin-left: auto; }
.suggest-caret {
  width: 5px;
  height: 5px;
  margin-right: 2px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(-45deg);
  flex-shrink: 0;
}
.suggest-caret.is-open { transform: rotate(45deg); }
.suggest-logo {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex-shrink: 0;
}
.suggest-service { padding-left: 28px; }
.suggest-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.svc-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.svc-cell-logo {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}
.suggest-item {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: white;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover { background: var(--surface-2); }
.suggest-meta { color: var(--text-muted); font-size: 12px; }
.suggest-empty { padding: 8px 12px; color: var(--text-muted); font-size: 13px; }

.panel-header-actions { display: flex; align-items: center; gap: 8px; }
.services-search {
  width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
}
.services-search:focus { outline: none; border-color: var(--primary); }
.btn-icon {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  width: 36px; height: 36px; padding: 0;
  font-size: 16px; line-height: 1; cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); border-color: var(--primary); }
.btn-icon-bell { color: var(--text-muted); }
.btn-icon-gear { color: var(--text-muted); }
.bell-icon { display: block; width: 18px; height: 18px; margin: 0 auto; }
.gear-icon { display: block; width: 18px; height: 18px; margin: 0 auto; }
.panel-header-actions .btn-secondary { margin-left: 0; }
.panel-header-lead { display: flex; align-items: center; gap: 12px; min-width: 0; }
.panel-header-lead .panel-title { min-width: 0; overflow-wrap: anywhere; }
.panel-header-icons:empty { display: none; }
.btn-back {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  flex-shrink: 0;
  min-height: 36px; margin-left: 0; padding: 0 12px 0 6px;
  border-radius: 8px;
  font: inherit; font-size: 13px; line-height: 1;
  color: var(--text-muted);
}
.btn-back:hover { color: var(--text); }
.back-icon { display: block; width: 18px; height: 18px; }
.back-icon svg { display: block; width: 100%; height: 100%; }

.notify-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.6);
  z-index: 900;
}
.notify-overlay:focus { outline: none; }
.notify-card {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 24px 28px;
  width: min(520px, 92vw);
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; gap: 0;
}
.modal-close {
  position: absolute; top: 10px; right: 10px;
  width: 40px; height: 40px; padding: 0;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text-muted);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.modal-close:hover,
.modal-close:focus-visible { background: var(--surface-2); }
.notify-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
}
/* Keep the title text and the On/Off toggle clear of the ×. */
.notify-card > .notify-title,
.notify-title-row { padding-right: 40px; }
.notify-title { font-size: 1.05rem; font-weight: 600; line-height: 1.35; min-width: 0; overflow-wrap: anywhere; }
.notify-title-suffix { font-weight: 500; color: var(--text-muted); }
.notify-flash {
  margin: 0 0 16px;
  padding: 8px 12px;
  border-radius: 6px;
  background: #ecfdf5;
  color: #047857;
  font-size: 13px;
}

.notify-toggle {
  position: relative;
  display: block;
  flex-shrink: 0;
  width: 52px;
  height: 24px;
  /* First-line x-height center: half-leading + ~0.54em, minus half the shell. */
  margin-top: calc((1.35 * 1.05rem - 1.05rem) / 2 + 0.54 * 1.05rem - 12px);
  cursor: pointer;
}
.notify-toggle input[type=checkbox] {
  appearance: none; -webkit-appearance: none;
  box-sizing: border-box;
  width: 52px; height: 24px; margin: 0;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); position: relative; cursor: pointer;
  overflow: hidden;
  transition: background 0.15s, border-color 0.15s;
}
.notify-toggle input[type=checkbox]::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: white; box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.notify-toggle input[type=checkbox]:checked {
  background: var(--primary); border-color: var(--primary);
}
.notify-toggle input[type=checkbox]:checked::after { transform: translateX(30px); }
.notify-toggle-text {
  position: absolute;
  top: 0;
  height: 24px; line-height: 24px;
  font-size: 0.85rem;
  pointer-events: none;
}
.notify-toggle-off {
  right: 5px;
  color: var(--muted, #64748b);
}
.notify-toggle-on {
  left: 5px;
  color: white;
  display: none;
}
.notify-toggle input:checked ~ .notify-toggle-off { display: none; }
.notify-toggle input:checked ~ .notify-toggle-on { display: block; }

.notify-body { display: flex; flex-direction: column; }
.notify-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
}
.notify-card .form-actions {
  margin-top: 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.notify-card input[type=text] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.mute-slider {
  position: relative;
  height: 28px;
  margin: 6px 0 2px;
}
.mute-track {
  position: absolute;
  left: 9px; right: 9px; top: 12px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.mute-midnight-tick {
  position: absolute;
  left: calc(9px + 720 / 1439 * (100% - 18px));
  top: 7px;
  width: 1px;
  height: 14px;
  background: var(--muted, #64748b);
  transform: translateX(-50%);
}
.mute-scale {
  position: relative;
  display: flex;
  justify-content: space-between;
  margin: 0 0 8px;
  font-size: 0.7rem;
  color: var(--muted, #94a3b8);
  font-variant-numeric: tabular-nums;
}
.mute-scale-mid {
  position: absolute;
  left: calc(9px + 720 / 1439 * (100% - 18px));
  transform: translateX(-50%);
}
.mute-night {
  position: absolute;
  top: 0; height: 100%;
  background: #312e81;
  border-radius: 999px;
}
.mute-slider input[type=range] {
  position: absolute; left: 0; width: 100%;
  top: 5px; height: 18px;
  margin: 0; background: transparent;
  pointer-events: none; appearance: none; -webkit-appearance: none;
}
.mute-slider .mute-from { z-index: 1; }
.mute-slider .mute-to { z-index: 2; }
.mute-slider input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px; background: transparent;
}
.mute-slider input[type=range]::-webkit-slider-thumb {
  pointer-events: auto; appearance: none; -webkit-appearance: none;
  box-sizing: border-box; width: 18px; height: 18px; border-radius: 50%;
  background: #312e81; border: 2px solid white;
  box-shadow: var(--shadow);
  margin-top: -7px;
  cursor: pointer;
}
.mute-slider input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--primary); outline-offset: 1px; }
.mute-slider input[type=range]::-moz-range-track {
  height: 4px; border-radius: 999px; background: transparent;
}
.mute-slider input[type=range]::-moz-range-thumb {
  pointer-events: auto;
  box-sizing: border-box; width: 18px; height: 18px; border-radius: 50%;
  background: #312e81; border: 2px solid white;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.mute-label { font-variant-numeric: tabular-nums; }

/* ---- Segmented one-time-code input ------------------------------------ */
.otp-field { position: relative; }
.otp-cells {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.otp-cell {
  display: flex; align-items: center; justify-content: center;
  height: 52px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2, #fafbfc);
  font-size: 24px; font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.otp-cell--filled {
  border-color: var(--primary);
  background: var(--surface);
}
.otp-cell--active {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.otp-cell--active::after {
  content: "";
  width: 2px; height: 24px;
  background: var(--primary);
  border-radius: 1px;
  animation: otp-caret 1s steps(1) infinite;
}
@keyframes otp-caret { 50% { opacity: 0; } }

.otp-field .otp-input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  letter-spacing: 0;
  cursor: text;
  z-index: 2;
}
.otp-field .otp-input:focus { outline: none; }

.owner-bar { margin: 4px 0 16px; }
.owner-bar .suggest { margin-top: 8px; }
.owner-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.owner-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.9rem;
}
.owner-chip-x {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}
.notify-card { max-height: none; overflow: visible; }
.notify-overlay { overflow: auto; align-items: flex-start; padding: 24px 0; }
.notify-overlay .notify-card { margin: auto 0; }
.notify-apply-check { margin: 0; pointer-events: none; flex-shrink: 0; }
.suggest-folder {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.suggest-item.notify-apply-row { align-items: center; }
.notify-picks {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
}
.notify-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.approve-actions { display: none; }
.approve-actions.is-on { display: contents; }

.notify-pick-kind {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Phone layout only. Desktop rules above stay as they are. */
@media (max-width: 640px) {
  .panel-header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
  }
  .panel-header-actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
  }
  .btn-back { width: 36px; padding: 0; }
  .btn-back-label { display: none; }
  .panel-header-single-row { flex-wrap: nowrap; align-items: center; }
  .panel-header-single-row .panel-header-lead { flex: 1 1 auto; }
  .panel-header-icons {
    flex: 0 0 auto;
    width: auto;
    flex-wrap: nowrap;
  }
  .services-search {
    flex: 1 1 100%;
    width: 100%;
    max-width: 100%;
  }
  .sub-grid { grid-template-columns: minmax(0, 1fr); }
  .grant-bar { flex-wrap: wrap; }

  .table-scroll {
    overflow: auto;
    max-height: 65vh;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .table-scroll table {
    width: max-content;
    min-width: 0;
    table-layout: auto;
  }
  .table-scroll th,
  .table-scroll td { white-space: nowrap; }
  table:has(#th-users-fullName),
  table:has(#th-pending-fullName),
  table:has(#th-members-fullName) { table-layout: auto; }
  #th-users-fullName,
  #th-users-targetName { width: auto; }
  table:has(#th-pending-fullName) th:last-child,
  table:has(#th-members-fullName) th:last-child,
  table:has(#th-members-fullName) td.row-actions { width: auto; }
  .table-scroll .row-actions { text-align: left; }
  .table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 1;
  }
  tr.user-grant .row-actions button,
  tr.service-member .row-actions button,
  tr.row-pending-grant .row-actions button,
  tr.row-pending-revoke .row-actions button { opacity: 1; }
}

@media (max-width: 360px) {
  .brand { gap: 8px; }
  .brand-logo { height: 32px; }
  .brand-title { font-size: 24px; margin-left: 0; padding-left: 12px; }
}
