/* FS components: top bar, language selector, user menu, meter, forms, cards, login, profile. */

/* ---------------------------------------------------------------- skip link */
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 2000;
  background: var(--accent); color: var(--accent-text);
  padding: 10px 14px; border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: 8px; color: var(--accent-text); }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  transition: box-shadow 0.2s ease;
}
.topbar.scrolled { box-shadow: var(--shadow-1); }
.topbar-inner {
  height: var(--bar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 var(--gutter);
  max-width: 1600px; margin: 0 auto;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding-right: 6px;
  color: var(--text); text-decoration: none; flex: none;
  border-radius: var(--radius-sm);
}
.brand:hover { color: var(--text); }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 750; font-size: 14px; letter-spacing: 0.02em;
}
.brand-text { font-weight: 650; font-size: 16px; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }

/* ---------------------------------------------------------------- language selector (§2.5) */
.lang-selector-wrapper { position: relative; }
.lang-selector-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); min-width: var(--tap); padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-2); cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.lang-selector-btn:hover { background: var(--surface-2); color: var(--text); }
.lang-dropdown {
  display: none;
  position: absolute; right: 0; top: calc(100% + 6px);
  width: min(260px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: 6px; z-index: 1100;
}
.lang-dropdown.active { display: block; }
.lang-search input {
  width: 100%; min-height: var(--tap); padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.lang-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: min(320px, 60vh); overflow-y: auto; }
.lang-item {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 0 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.lang-item:hover { background: var(--surface-2); }
.lang-item.active { background: var(--accent-soft); color: var(--accent-soft-text); font-weight: 600; }
.lang-endonym { margin-left: auto; color: var(--text-3); font-size: 13px; }

/* ---------------------------------------------------------------- free-space meter */
.meter { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.meter-bar { width: 72px; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; flex: none; }
.meter-fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter-fill.meter-high { background: var(--danger); }
.meter-detail { display: none; }
.meter-in-menu { flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.meter-in-menu .meter-bar { width: 100%; order: 2; }
.meter-in-menu .meter-detail { display: block; order: 3; color: var(--text-3); white-space: normal; }
#nav-meter + .lang-selector-wrapper { margin-left: 4px; }
@media (max-width: 719px) { #nav-meter { display: none; } }
@media (min-width: 720px) { .usermenu-meter { display: none; } }

/* ---------------------------------------------------------------- user menu */
.usermenu { position: relative; }
.usermenu-btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 0 8px 0 4px;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: var(--text); cursor: pointer;
}
.usermenu-btn:hover, .usermenu-btn[aria-expanded="true"] { background: var(--surface-2); border-color: var(--border); }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-soft-text); font-weight: 700; font-size: 14px;
}
.usermenu-name { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.usermenu-chev { width: 16px; height: 16px; color: var(--text-3); }
@media (max-width: 559px) { .usermenu-name, .usermenu-chev { display: none; } .usermenu-btn { padding: 0 4px; } }
.usermenu-pop {
  position: absolute; right: 0; top: calc(100% + 6px);
  width: min(260px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: 0 0 6px; z-index: 1100; overflow: hidden;
}
.usermenu-head { display: flex; flex-direction: column; padding: 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.usermenu-head span { color: var(--text-3); font-size: 13px; }
.usermenu-meter:empty { display: none; }
.usermenu-item {
  display: flex; align-items: center; gap: 10px; width: calc(100% - 12px); margin: 0 6px;
  min-height: var(--tap); padding: 0 10px; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); text-decoration: none; text-align: left; cursor: pointer; font-size: 14px;
}
.usermenu-item:hover, .usermenu-item:focus-visible { background: var(--surface-2); color: var(--text); }
.usermenu-item .icon { color: var(--text-3); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); cursor: pointer;
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.is-busy { cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger-hover); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 0 12px; font-size: 13px; }
.btn-icon { padding: 0; width: var(--tap); }
.btn-icon .icon { width: 18px; height: 18px; }

/* ---------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label-row label, .fieldset legend { font-weight: 600; font-size: 14px; }
.label-row { display: flex; align-items: center; gap: 8px; }
.field input, .field select, .lang-search input {
  min-height: var(--tap); padding: 0 12px; width: 100%;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .lang-search input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.field input[readonly] { background: var(--surface-2); color: var(--text-2); }
.hint { color: var(--text-3); font-size: 13px; }
.fieldset { border: 0; padding: 0; margin: 0; }
.fieldset legend { padding: 0; margin-bottom: 8px; }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.form-error {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger); font-size: 14px;
}
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 650; line-height: 1.5;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------------------------------------------------------------- cards and pages */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: clamp(18px, 3vw, 28px); box-shadow: var(--shadow-1); min-width: 0;
}
.page-head { margin-bottom: 20px; }
.page-head h1 { margin-bottom: 4px; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------------------------------------------------------------- login */
.auth {
  min-height: calc(100vh - var(--bar-h));
  display: grid; grid-template-columns: 1fr;
}
.auth-aside { display: none; }
.auth-panel { display: flex; align-items: flex-start; justify-content: center; padding: 32px var(--gutter) 64px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 20px; }
@media (min-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr) minmax(460px, 0.9fr); }
  .auth-panel { align-items: center; padding: 48px; }
  .auth-aside {
    display: flex; align-items: center;
    padding: 48px clamp(48px, 6vw, 112px);
    background:
      radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%),
      linear-gradient(160deg, var(--accent-soft), var(--bg));
    border-right: 1px solid var(--border);
  }
}
.auth-aside-inner { max-width: 520px; }
.auth-mark {
  display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 16px;
  background: var(--accent); color: var(--accent-text); font-weight: 800; font-size: 24px; margin-bottom: 24px;
}
.auth-headline { font-size: clamp(1.6rem, 1.1rem + 1.4vw, 2.3rem); letter-spacing: -0.02em; margin-bottom: 12px; }
.auth-aside p { font-size: 1.05rem; color: var(--text-2); }
.auth-points { margin: 24px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.auth-points li { position: relative; padding-left: 28px; color: var(--text-2); }
.auth-points li::before {
  content: ""; position: absolute; left: 0; top: 0.3em; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent-soft); border: 4px solid var(--accent);
}

/* ---------------------------------------------------------------- profile */
.profile-grid { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
@media (min-width: 1000px) { .profile-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); } }

.phone-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.phone-row {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: minmax(0, 9.5rem) minmax(0, 1fr) auto;
  grid-template-areas: "type value actions" "label label label";
}
.phone-type { grid-area: type; }
.phone-value { grid-area: value; }
.phone-label { grid-area: label; }
.phone-actions { grid-area: actions; display: flex; gap: 2px; }
@media (min-width: 600px) {
  .phone-row:has(.phone-label:not([hidden])) {
    grid-template-columns: minmax(0, 9.5rem) minmax(0, 8rem) minmax(0, 1fr) auto;
    grid-template-areas: "type label value actions";
  }
}
@media (max-width: 420px) {
  .phone-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "type actions" "label label" "value value"; }
}
.phone-empty { margin: 0 0 10px; }

.pk-list { list-style: none; margin: 16px 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); }
.pk-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 14px; }
.pk-row + .pk-row { border-top: 1px solid var(--border); }
.pk-empty { padding: 14px; }
.pk-main { display: flex; align-items: center; gap: 12px; flex: 1 1 220px; min-width: 0; }
.pk-icon { color: var(--accent); width: 20px; height: 20px; }
.pk-text { min-width: 0; }
.pk-name { font-weight: 600; overflow-wrap: anywhere; }
.pk-meta { color: var(--text-3); font-size: 13px; }
.pk-actions { display: flex; gap: 4px; margin-left: auto; }
.pk-add { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.pk-add .field { flex: 1 1 200px; }

/* ---------------------------------------------------------------- dialog */
.dialog {
  width: min(440px, calc(100vw - 32px)); padding: 24px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-2);
}
.dialog::backdrop { background: rgba(10, 16, 18, 0.45); }
.dialog h2 { margin-bottom: 0; }

/* ---------------------------------------------------------------- toasts */
.toast-region {
  position: fixed; z-index: 1500; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(480px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; width: 100%; padding: 12px 16px; border-radius: var(--radius);
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-2); font-size: 14px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-ok { background: var(--ok); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-out { opacity: 0; transform: translateY(6px); }
@media (prefers-color-scheme: dark) { .toast-ok, .toast-error { color: #0b0f10; } }
@media (max-width: 599px) {
  .phone-row { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
}
.phone-link { display: contents; }

/* ---------------------------------------------------------------- more badges */
.badge-info { background: var(--accent-soft); color: var(--accent-soft-text); }
.badge-muted { background: var(--surface-3); color: var(--text-2); }
.badge-role { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-role-admin { background: var(--accent-soft); color: var(--accent-soft-text); border-color: transparent; }

/* ---------------------------------------------------------------- data tables (stack on phones) */
.dt-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.dtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.dtable th, .dtable td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
.dtable thead th { font-size: 12.5px; font-weight: 650; color: var(--text-3); background: var(--surface-2); white-space: nowrap; }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tbody tr:hover { background: var(--surface-2); }
.dtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.dtable .nowrap { white-space: nowrap; }
.dtable .wrap { overflow-wrap: anywhere; }
.dtable code { font-family: var(--mono); font-size: 12.5px; }
.dt-acts { white-space: nowrap; text-align: right; }
.dt-acts .btn + .btn { margin-left: 6px; }
.dt-empty td { text-align: center; color: var(--text-3); padding: 28px 12px; }
@media (max-width: 759px) {
  .dt-wrap { overflow: visible; border: 0; background: none; }
  .dtable, .dtable tbody, .dtable tr, .dtable td { display: block; width: 100%; }
  .dtable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .dtable tr { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 6px 0; }
  .dtable tbody tr:hover { background: var(--surface); }
  .dtable td { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; border: 0; padding: 6px 14px; text-align: right; }
  .dtable td::before { content: attr(data-label); flex: none; color: var(--text-3); font-size: 12.5px; font-weight: 600; text-align: left; }
  .dtable td:not([data-label])::before { content: none; }
  .dtable td.num { text-align: right; }
  .dtable td.dt-acts { justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
  .dt-acts .btn + .btn { margin-left: 0; }
  .dt-empty td { justify-content: center; }
}

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; margin-bottom: -1px;
  color: var(--text-2); text-decoration: none; font-weight: 600; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* Passkey step-up prompt (stepup.js): admin page card, drive purge dialog. */
.stepup { max-width: 520px; margin: 24px auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.stepup-icon { color: var(--accent); margin-bottom: 4px; }
.stepup .btn { margin-top: 8px; }
.stepup .form-error { align-self: stretch; }
.dialog .stepup { margin: 0 auto; padding: 0; border: 0; box-shadow: none; background: none; }
.dialog .stepup-cancel { align-self: center; }
