/* Maria VPN — панель сотрудников. Айдентика «Ганаш & золото» (см. skill maria-design).
   Шрифты сайта (Roboto Serif / Mulish) недоступны офлайн — задача требует
   self-contained вёрстку без внешних ресурсов, поэтому здесь их роль играют
   системные serif/sans-стеки того же характера (засечка для заголовков,
   гуманистический гротеск для интерфейса, моно с tabular-nums для цифр). */

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любые авторские display (flex у .screen-login,
   block у #chart и .qr-img и т.д.) — иначе UA-правило [hidden]{display:none}
   проигрывает по каскаду и экран логина не прячется после входа. */
[hidden] { display: none !important; }

:root {
  --bg:          #FAF8F5;
  --surface:     #FFFFFF;
  --panel:       #FFFFFF;
  --ink:         #221A16;
  --ink-2:       #6B5F62;
  --line:        #E9E1DA;
  --accent:      #D61F37;
  --accent-ink:  #FFFFFF;
  --accent-soft: #FBE2E6;
  --secondary:   #F6F2EE;
  --gold:        #B98A3E;
  --positive:    #2E7D5B;
  --positive-soft: #E4F1EA;
  --warn:        #B5722A;
  --warn-soft:   #F5EADC;
  --danger:      #B3261E;
  --radius:      12px;
  --shadow:      0 1px 2px rgba(34,26,22,.04), 0 8px 24px rgba(34,26,22,.06);

  --font-display: Georgia, "Noto Serif", "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #1A1514;
    --surface:     #221C1B;
    --panel:       #221C1B;
    --ink:         #F2EBE7;
    --ink-2:       #A99FA0;
    --line:        #322A28;
    --accent:      #F0566A;
    --accent-ink:  #1A1514;
    --accent-soft: #2E1A1D;
    --secondary:   #2A2321;
    --gold:        #D8B06A;
    --positive:    #5BB58A;
    --positive-soft: #1E2B24;
    --warn:        #D69A52;
    --warn-soft:   #2E2418;
    --danger:      #E5645A;
    --shadow:      0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0; color: var(--ink); }
h1 { font-size: 22px; letter-spacing: .1px; }
h2 { font-size: 20px; }
h3 { font-size: 14px; color: var(--ink-2); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

button { font-family: inherit; }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Banner (ошибки соединения) ---------- */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: var(--warn-soft); color: var(--warn);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px; font-size: 13px; text-align: center;
}

/* ---------- Login ---------- */
.screen-login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 340px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex; flex-direction: column; gap: 14px;
  text-align: center;
}
.brand-mark { color: var(--gold); display: flex; justify-content: center; margin-bottom: 4px; }
.brand-mark.small { margin: 0; }
.login-card h1 { font-size: 26px; }
.login-card .sub { margin: -8px 0 8px; color: var(--ink-2); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 13px; color: var(--ink-2); }
.field input, .field textarea {
  font: inherit; font-size: 15px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px;
}
.field textarea { resize: vertical; font-family: var(--font-mono); font-size: 13px; line-height: 1.5; }
.field input:focus, .field textarea:focus { border-color: var(--gold); }

.err { color: var(--danger); font-size: 13px; margin: 0; }
.err::before { content: "⚠ "; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: var(--font-ui); font-weight: 600; font-size: 14px;
  padding: 10px 16px; border-radius: 8px;
  transition: transform .15s ease-out, background .15s ease-out, box-shadow .15s ease-out;
}
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { box-shadow: 0 4px 14px rgba(214,31,55,.28); }
.btn-secondary { background: var(--secondary); color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--gold); }
.btn-positive { background: var(--positive-soft); color: var(--positive); border: 1px solid var(--positive); }
.btn-positive:hover { filter: brightness(0.97); }
.btn-ghost { background: transparent; color: var(--ink-2); border: 1px solid transparent; }
.btn-ghost:hover { color: var(--ink); background: var(--secondary); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--accent-soft); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- Main / topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { flex: 1; font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; }

.content { padding: 24px; max-width: 1100px; margin: 0 auto; }

/* ---------- Table ---------- */
.table-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
thead th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-2); font-weight: 700;
  padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
th.col-dot { width: 28px; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.user-row { cursor: pointer; transition: background .15s ease-out; }
tbody tr.user-row:hover { background: var(--secondary); }
tbody tr.empty-row td { color: var(--ink-2); text-align: center; padding: 28px 16px; cursor: default; }
tbody tr.empty-row:hover { background: transparent; }

.name-cell { font-weight: 600; }
.bytes-cell { font-family: var(--font-mono); font-size: 13px; }
.bytes-cell.nd, .lastseen-cell.nd { color: var(--ink-2); font-style: italic; font-family: var(--font-ui); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dot.online { background: var(--positive); box-shadow: 0 0 0 3px var(--positive-soft); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--secondary); color: var(--ink-2);
}
.badge.active { background: var(--positive-soft); color: var(--positive); }
.badge.revoked { background: var(--accent-soft); color: var(--danger); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }

/* ---------- Dialogs ---------- */
dialog.dlg {
  border: none; border-radius: var(--radius); padding: 0;
  background: var(--panel); color: var(--ink);
  box-shadow: 0 20px 60px rgba(34,26,22,.25);
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
}
dialog.dlg-wide { width: min(640px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: rgba(34,26,22,.45); backdrop-filter: blur(1px); }
.dlg-body { padding: 28px; overflow-y: auto; max-height: calc(100vh - 48px); position: relative; }
.dlg-body h2 { margin-bottom: 16px; padding-right: 24px; }
.dlg-close {
  position: absolute; top: 18px; right: 18px; width: 30px; height: 30px;
  border-radius: 50%; border: none; background: var(--secondary); color: var(--ink-2);
  font-size: 18px; line-height: 1; cursor: pointer;
}
.dlg-close:hover { background: var(--line); color: var(--ink); }
.dlg-step { display: flex; flex-direction: column; gap: 14px; }
.hint { font-size: 13px; color: var(--ink-2); margin: 0; }

.code-display {
  font-family: var(--font-mono); font-size: 32px; font-weight: 700;
  letter-spacing: .12em; text-align: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 10px; padding: 16px 8px;
  font-variant-numeric: tabular-nums;
}

.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; padding-right: 24px; }
.card-section { margin-bottom: 24px; }
.card-section:last-of-type { margin-bottom: 0; }
.card-grid { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: start; }
.card-grid .grow { min-width: 0; }

.bind-row { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; font-size: 14px; color: var(--ink); }
.btn-link { background: none; border: none; color: var(--gold); cursor: pointer; padding: 0; font: inherit; }
.phone-section { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.phone-section h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink); }
.shared-note { color: var(--danger); font-size: 13px; }

.qr-img { display: block; width: 140px; height: 140px; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 8px; }

.copy-row { display: flex; gap: 8px; }
.copy-row input {
  flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; color: var(--ink);
}

#codeBlock { display: flex; flex-direction: column; gap: 12px; }
#codeMissing { padding: 12px 0; }
#phoneKeyBox { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }

.phone-key summary {
  cursor: pointer; font-size: 13px; color: var(--ink-2);
  list-style-position: inside; user-select: none;
}
.phone-key summary:hover { color: var(--ink); }
.phone-key[open] summary { margin-bottom: 14px; }

.chart-wrap { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 8px; }
#chart { display: block; width: 100%; height: 160px; }
.empty-note { margin: 0; text-align: center; color: var(--ink-2); font-style: italic; font-size: 13px; padding: 56px 0; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink); color: var(--bg); font-family: var(--font-mono);
  font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap;
  transform: translate(-50%, -100%); margin-top: -8px; opacity: 0; transition: opacity .12s ease-out;
}
.chart-tooltip.show { opacity: 1; }

.sessions-list { display: flex; flex-direction: column; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.session-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 12px; font-size: 13px; font-family: var(--font-mono);
  border-bottom: 1px solid var(--line);
}
.session-row:last-child { border-bottom: none; }
.session-row .open { color: var(--positive); font-family: var(--font-ui); font-weight: 600; }
.sessions-empty { padding: 20px 12px; text-align: center; color: var(--ink-2); font-style: italic; font-size: 13px; }

.card-actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 20px; border-top: 1px solid var(--line); }
.card-actions .btn { flex: 1; min-width: 140px; }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar h1 { font-size: 16px; order: 3; flex-basis: 100%; }
  .content { padding: 14px; }
  .card-grid { grid-template-columns: 1fr; }
  .qr-img { width: 120px; height: 120px; }
}
