/* FB Stats — styles of the admin screens (track D): profiles, proxies, settings, login.
 * Loaded last. */

.settings-form { gap: 16px; }
.rates { display: flex; flex-direction: column; gap: 6px; }
.rate-row { display: flex; align-items: center; gap: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0;
  border: 2px solid transparent; border-radius: 50%; color: var(--on-fill); cursor: pointer;
}
.swatch-none { border: 2px dashed var(--border-strong); background: none; color: var(--text); }
.swatch.is-active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
/* Several short fields on one line (proxy type / host / port, login / password). */
.form-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: 100%; align-items: start; }
.form-cols-address { grid-template-columns: 112px minmax(0, 1fr) 92px; }
.form-cols-auth { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
.form-cols > .form-row { min-width: 0; }
.form-check { font-size: 12px; color: var(--text-secondary); }
.form-check.is-disabled { opacity: 0.55; cursor: default; }
.about { display: flex; flex-direction: column; gap: 8px; }
.about-list { margin: 0; padding-left: 18px; color: var(--text-secondary); }

/* -------------------------------------------------------------- profiles */

.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.profile {
  display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--border);
  border-top: 3px solid var(--profile-color, var(--border-strong)); border-radius: var(--radius); background: var(--surface); min-width: 0;
}
.profile.is-disabled > :not(.profile-head):not(.profile-actions) { opacity: 0.55; }
.profile-head { display: flex; align-items: center; gap: 10px; }
.profile-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.profile-token-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.profile-hint { margin-top: 4px; font-size: 12px; color: var(--tone-ink, var(--text-secondary)); overflow-wrap: anywhere; }
.profile-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.profile-counts dt { color: var(--text-muted); font-size: 12px; }
.profile-counts dd { margin: 0; font-size: 18px; font-weight: 700; }
.profile-sync { font-size: 13px; }
.profile-note { color: var(--text-secondary); font-size: 13px; overflow-wrap: anywhere; }
.profile-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.profile-proxy { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; font-size: 13px; }
.profile-proxy .icon { color: var(--text-muted); }
.profile-proxy-name { font-weight: 600; overflow-wrap: anywhere; }

/* --------------------------------------------------------------- proxies */

.table-proxies .col-name { min-width: 150px; }
.table-proxies .col-address { min-width: 140px; overflow-wrap: anywhere; }
.table-proxies .col-login { overflow-wrap: anywhere; }
.table-proxies .col-type, .table-proxies .col-password { white-space: nowrap; }
.table-proxies .col-check { min-width: 136px; overflow-wrap: anywhere; }
.table-proxies .col-check .cell-sub { max-width: 300px; }
.narrow-only { display: none; }
.table-proxies th.col-actions { text-align: right; }
/* The buttons wrap inside their cell instead of pushing the table wider than the page. */
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 6px; }
/* Narrow window: type, login and password of a proxy move under its address, so that the table
 * still fits without scrolling sideways. */
@media (max-width: 1380px) {
  .table-proxies .col-type, .table-proxies .col-login, .table-proxies .col-password { display: none; }
  .table-proxies .narrow-only { display: block; }
}
@media (min-width: 1381px) {
  .table-proxies .col-name { min-width: 190px; }
  .table-proxies .col-address { min-width: 200px; }
}
/* Wherever there is room for it, the actions of a row stay on one line. */
@media (min-width: 900px) and (max-width: 1023px), (min-width: 1100px) {
  .table-proxies td.col-actions { min-width: 214px; }
}
@media (max-width: 480px) {
  .form-cols, .form-cols-address, .form-cols-auth { grid-template-columns: minmax(0, 1fr); }
}
.profile-token-fact { margin-top: 4px; font-size: 13px; overflow-wrap: anywhere; }
.profile-access { font-size: 13px; }
.profile-access-line { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px; color: var(--text-secondary); }
.profile-counts dd.is-note { font-size: 13px; font-weight: 500; color: var(--text-muted); line-height: 27px; cursor: help; }
.dialog-section { min-width: 0; }
.dialog-section + .dialog-section { padding-top: 12px; border-top: 1px solid var(--border); }
.dialog-section > .facts { margin-top: 10px; }
.dialog-section > .dialog-text { margin: 8px 0 0; }
.table-access td { white-space: normal; vertical-align: top; }
.table-access .col-meaning { min-width: 200px; overflow-wrap: anywhere; }
.perm-group + .perm-group { margin-top: 10px; }
.perm-group-title { font-size: 13px; font-weight: 600; }
.perm-list { font-size: 13px; }
.perm-list li { overflow-wrap: anywhere; }
/* A profile card opened from a link elsewhere. */
.profile.is-target { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------ round 4, track D (plan 1.3, 2.10, 4.2, 4.4, 4.6, V-17) */

/* Tabs «Профили» · «Прокси» (App.ui.sectionTabs) on top of both views. */
.admin-tabs { min-width: 0; }
.admin-tabs .section-tabs { margin-bottom: 0; }

/* «⋯» menu of a card: a dropdown here, a bottom sheet on a phone (kit CSS for details.menu). */
.admin-more > summary { cursor: pointer; }
.admin-more:not([open]) > .menu-pop { display: none; }
.admin-more > summary .icon { width: 18px; height: 18px; }
.admin-more-pop { min-width: 220px; }
.admin-more-caption {
  padding: 4px 6px 8px; color: var(--text-muted); font-size: var(--fs-sm); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-more-item {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; color: var(--text);
  font: inherit; font-size: var(--fs-md); text-align: left; cursor: pointer; padding: 7px 8px;
}
.admin-more-item .icon { width: 16px; height: 16px; color: var(--text-muted); }
.admin-more-item.is-danger, .admin-more-item.is-danger .icon { color: var(--bad-ink); }

/* Long hints: two lines and «подробнее» on a phone; the whole text elsewhere. */
.clamp-more {
  display: none; align-items: center; padding: 0; border: 0; background: none; color: var(--link);
  font: inherit; font-size: var(--fs-sm); cursor: pointer;
}
.label-short { display: none; }

/* No proxy while one is required (profile.sync_blocked). */
.profile.is-blocked { border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.profile-blocked {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px;
  border-radius: var(--r-md); background: color-mix(in srgb, var(--bad) 10%, transparent);
}
.profile-blocked-line { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; flex: 1 1 220px; }
.profile-blocked-text { font-size: var(--fs-md); color: var(--bad-ink); overflow-wrap: anywhere; }
.profile-proxy-address { font-size: var(--fs-sm); overflow-wrap: anywhere; }
.proxy-required-hint a { color: inherit; text-decoration: underline; }
/* Placeholders end with an ellipsis instead of being cut mid-letter (V-16). */
.form .input { text-overflow: ellipsis; }

/* Proxies: the badge-only column exists for the phone card corner only. */
.table-proxies .col-state { display: none; }

/* V-17: the empty list of proxies is a lead and three points, left-aligned. */
.proxies-empty .empty { align-items: flex-start; text-align: left; padding: 24px 4px; }
.proxies-empty .empty-text { max-width: 640px; }
.empty-lead { margin: 0 0 6px; color: var(--text); }
.empty-points { margin: 0; padding-left: 18px; display: grid; gap: 4px; }

/* V-17: settings fields as wide as what they hold; the select up to 420 px. */
.settings-form .form-row > .select { max-width: 420px; }
.settings-form .form-row > .input.input-short { width: 150px; }
.settings-form .form-row > .input.input-wide { max-width: 420px; }
.settings-form .form-row.is-forced .form-hint { color: var(--text-secondary); }
.form-toggle.is-disabled { cursor: default; color: var(--text-secondary); }
.settings-login-note code, .login-note code { font-family: var(--mono); font-size: 0.95em; overflow-wrap: anywhere; }

/* The «Сохранить» bar: quiet at the end of the form; sticky with unsaved edits. */
.settings-savebar { align-items: center; flex-wrap: wrap; gap: 8px 10px; padding: 10px 0; }
.savebar-text { color: var(--text-muted); font-size: var(--fs-md); }
.settings-savebar.is-dirty {
  position: sticky; bottom: max(12px, var(--safe-bottom)); z-index: 20; padding: 10px 12px 10px 16px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-raised); box-shadow: var(--shadow);
}
.settings-savebar.is-dirty .savebar-text { color: var(--text); font-weight: 600; }

/* «Вход и сеансы». */
.card-text { margin: 0 0 10px; color: var(--text-secondary); font-size: var(--fs-md); }
.table-sessions td { vertical-align: middle; }
.table-sessions .session-device { font-weight: 600; }
.table-sessions td.col-actions { text-align: right; }

/* -------------------------------------------------------------- login */

.login-screen {
  position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: max(24px, var(--safe-top)) max(16px, var(--safe-right)) max(24px, var(--safe-bottom)) max(16px, var(--safe-left));
  background: var(--bg);
}
.login-card {
  display: flex; flex-direction: column; gap: 20px; width: 100%; max-width: 380px; padding: 28px 24px;
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand .brand-mark { flex: none; }
.login-title { margin: 0; font-size: var(--fs-xl); font-weight: 700; }
.login-sub { margin: 2px 0 0; color: var(--text-secondary); font-size: var(--fs-md); }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form .login-password { width: 100%; min-height: 44px; font-size: 16px; }
.login-submit { width: 100%; min-height: 48px; margin-top: 8px; font-size: var(--fs-lg); }
.login-error { font-size: var(--fs-md); }
/* Present for Keychain, invisible and out of the tab order. */
.login-user {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; opacity: 0;
}
.login-note { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }

/* -------------------------------------------------------------- touch: 44 px targets */

@media (pointer: coarse) {
  .profile-actions .btn, .profile-blocked .btn, .profile-access-line .btn, .row-actions .btn,
  .admin-more > summary, .table-sessions .btn, .settings-view .card-actions .btn,
  .settings-form .btn, .admin-toolbar .btn, .proxies-empty .btn { min-height: var(--tap); }
  .admin-more > summary, .row-actions .btn-square { min-width: var(--tap); }
  .admin-more-item { min-height: var(--tap); }
  /* The switch: the invisible input covers the whole 44 px label, so the finger hits it. */
  .profile-head .switch { min-height: var(--tap); }
  .profile-head .switch input { top: 0; left: 0; width: 100%; height: 100%; }
  .settings-form .check, .form-check { min-height: var(--tap); }
  .settings-form .check input, .form-check input { width: 20px; height: 20px; }
  .rate-remove { width: var(--tap); height: var(--tap); }
  .swatch { width: var(--tap); height: var(--tap); }
  .swatches { gap: 10px; }
  .profile .copy-id { min-height: var(--tap); }
  .profile-counts dd a { display: inline-flex; align-items: center; min-width: var(--tap); min-height: var(--tap); }
  .table-proxies a.chip { min-height: var(--tap); padding: 0 12px; }
  .clamp-more { min-height: var(--tap); }
}

/* -------------------------------------------------------------- phone */

@media (max-width: 640px) {
  .admin-toolbar .toolbar-text { flex: 1 1 100%; }
  .admin-toolbar .toolbar-spacer { display: none; }
  .admin-toolbar > .btn-primary { flex: 1 1 100%; }

  /* Profile cards. */
  .profiles { gap: 12px; }
  .profile { padding: 14px 12px; gap: 10px; }
  .profile-head { align-items: center; }
  .profile-counts { gap: 4px; }
  .profile-counts dd { font-size: var(--fs-lg); }
  .label-full { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .label-short { display: inline; }
  .clamp > .clamp-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  .clamp.is-open > .clamp-text { display: block; -webkit-line-clamp: unset; overflow: visible; }
  .clamp-more { display: inline-flex; }
  /* «Синхронизировать» on its own row, then «Изменить» and «⋯»: the same at 360–640 px. */
  .profile-actions { display: grid; grid-template-columns: minmax(0, 1fr) var(--tap); gap: 8px; }
  .profile-actions > .btn:first-child { grid-column: 1 / -1; }
  .profile-actions .toolbar-spacer { display: none; }
  .profile-blocked .btn { flex: 1 1 100%; }
  .profile-access-line .btn { flex: 1 1 100%; }

  /* Proxy cards: type, login and password are in the address line (.narrow-only). */
  .table-proxies.is-cards td.col-type, .table-proxies.is-cards td.col-login, .table-proxies.is-cards td.col-password { display: none; }
  .table-proxies.is-cards .check-badge { display: none; }
  .table-proxies.is-cards td.col-check:has(> .check-badge:only-child) { display: none; }
  .table-proxies.is-cards td.col-name, .table-proxies.is-cards td.col-address, .table-proxies.is-cards td.col-check { min-width: 0; }
  .table-proxies.is-cards .chips-cell { max-width: none; }
  .table-proxies.is-cards td.col-actions { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--border); }
  .table-proxies.is-cards .row-actions { justify-content: flex-start; flex-wrap: nowrap; gap: 8px; }
  .table-proxies.is-cards .row-actions > .btn:first-child { flex: 1 1 auto; }

  /* Settings: full-width fields, labels above, sticky bar above the tab bar and the home bar. */
  .settings-form .form-row > .select, .settings-form .form-row > .input.input-short,
  .settings-form .form-row > .input.input-wide, .settings-form .form-row > .input.input-num { width: 100%; max-width: none; }
  /* Proxy dialog: type and port side by side, the host on its own full row. */
  .form-cols.form-cols-address { grid-template-columns: minmax(0, 1fr) 112px; }
  .form-cols.form-cols-address > .form-row:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .rate-row { flex-wrap: wrap; gap: 8px; }
  .rate-row .input-num { flex: 1 1 96px; width: auto; min-width: 0; }
  .settings-savebar { padding: 8px 0; }
  .settings-savebar .btn { min-height: 48px; }
  .settings-savebar.is-dirty { bottom: max(8px, var(--safe-bottom)); margin: 0 -4px; padding: 8px 8px 8px 12px; }
  .settings-savebar.is-dirty .savebar-text { flex: 1 1 100%; }
  .settings-savebar.is-dirty .toolbar-spacer { display: none; }
  .settings-savebar.is-dirty .btn { flex: 1 1 0; }
  .settings-savebar.is-dirty .btn-primary { order: 2; }
  body:has(.tabbar) .settings-savebar.is-dirty { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px); }

  /* Sessions as cards (dataTable card mode): «Завершить» full width. */
  .table-sessions.is-cards td.col-actions:empty { display: none; }
  .table-sessions.is-cards td.col-actions .btn { width: 100%; min-height: var(--tap); }

  /* Login: the card fills the phone width, the field is 16 px (no iOS zoom). */
  .login-screen { align-items: flex-start; padding-top: max(48px, var(--safe-top)); }
  .login-card { padding: 22px 18px; box-shadow: none; }
}
