/* Telvo CP — one stylesheet, no build step. */
:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface-2: #F9FAFC;
  --border: #E1E6EE;
  --border-strong: #C9D1DD;
  --text: #243348;
  --muted: #5B6B80;
  --accent: #009BD7;
  --accent-ink: #0077A8;        /* accent dark enough for text on white */
  --accent-soft: #E6F5FB;
  --orange: #FA862D;
  --orange-ink: #B35400;
  --orange-soft: #FFF1E6;
  --ok: #1E8E5A;    --ok-soft: #E7F6EE;
  --warn: #A86500;  --warn-soft: #FFF5DD;
  --bad: #C9372C;   --bad-soft: #FDECEA;
  --idle: #6B7889;  --idle-soft: #EEF1F5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(36, 51, 72, .05);
  --focus: 0 0 0 3px rgba(0, 155, 215, .35);
  --sidebar-w: 240px;
  --topbar-h: 60px;
  font-family: "Noto Sans Georgian", "Noto Sans", "Segoe UI", system-ui, -apple-system, "DejaVu Sans", sans-serif;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.seg label:focus-within span { box-shadow: var(--focus); }
html, body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
.ic { width: 18px; height: 18px; flex: none; vertical-align: middle; }
.ic-sm { width: 14px; height: 14px; }
.ic-lg { width: 22px; height: 22px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); }
.skip-link:focus { left: 8px; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.nowrap { white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar .brand { display: flex; align-items: center; height: var(--topbar-h); padding: 0 20px; border-bottom: 1px solid var(--border); }
.sidebar .brand img { height: 30px; width: auto; display: block; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 14px;
}
.nav a .ic { color: var(--muted); }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav a[aria-current="page"] .ic { color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 12px 20px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.topbar > * { flex-shrink: 0; }
.topbar > .workspace { flex-shrink: 1; }
.workspace { display: flex; flex-direction: column; min-width: 0; }
.workspace .ws-label { font-size: 11px; color: var(--muted); }
.workspace .ws-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.env-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--orange-soft); color: var(--orange-ink); border: 1px solid #F8C9A2; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button, .seg a { border: 0; background: var(--surface); color: var(--muted); padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; }
.seg [aria-pressed="true"], .seg [aria-current="true"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 4px 8px; font: inherit; color: var(--text); cursor: pointer; }
.user-btn:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(36,51,72,.12); padding: 6px; display: none; }
.dropdown[data-open="true"] { display: block; }
.dropdown .dd-head { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown a, .dropdown button { display: flex; width: 100%; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: left; text-decoration: none; }
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); }

.impersonation {
  display: flex; align-items: center; gap: 12px; padding: 8px 24px;
  background: var(--orange-soft); border-bottom: 1px solid #F8C9A2; color: var(--orange-ink); font-weight: 600;
}
.impersonation form { margin-left: auto; }

.content { padding: 24px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head .titles p { color: var(--muted); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { flex: 1; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stat { padding: 16px 18px; }
.stat .stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.stat .stat-value { font-size: 28px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .stat-value small { font-size: 16px; color: var(--muted); font-weight: 500; }
.stat .stat-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat .stat-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); }
.stat .stat-icon.orange { background: var(--orange-soft); color: var(--orange-ink); }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #008BC2; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { background: #B02E24; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; padding: 0; height: 32px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .field .label { font-weight: 500; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  height: 36px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
textarea.input { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.field-error { display: flex; align-items: center; gap: 5px; color: var(--bad); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 6px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.filters .field { min-width: 140px; flex: 0 1 auto; }
.filters .field.grow { flex: 1; min-width: 200px; }
.search { position: relative; }
.search .ic { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search .input { padding-left: 34px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #FAFBFD; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.actions-col, .table td.actions-col { position: sticky; right: 0; background: inherit; text-align: right; }
.table td.actions-col { background: var(--surface); }
.table tbody tr:hover td.actions-col { background: #FAFBFD; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

/* ---------- Status / badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.busy { background: var(--orange-soft); color: var(--orange-ink); }
.badge.off { background: var(--idle-soft); color: var(--idle); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--accent-soft); color: var(--accent-ink); }
/* shape cue beside colour: ok = filled dot, busy = ring, off = dash */
.badge.busy .dot { background: transparent; border: 2px solid currentColor; width: 9px; height: 9px; }
.badge.off .dot { border-radius: 1px; height: 2px; width: 9px; }
.dir { display: inline-flex; align-items: center; gap: 6px; }
.dir.in .ic { color: var(--accent-ink); }
.dir.out .ic { color: var(--ok); }
.dir.internal .ic { color: var(--muted); }

/* ---------- Alerts / empty ---------- */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 14px; }
.alert.success { background: var(--ok-soft); border-color: #B9E3CC; color: #14613D; }
.alert.error { background: var(--bad-soft); border-color: #F3C0BB; color: #8E2219; }
.alert.info { background: var(--accent-soft); border-color: #B3E1F3; color: #00597E; }
.alert.warn { background: var(--warn-soft); border-color: #F1D69A; color: #7A4A00; }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .ic { width: 32px; height: 32px; color: var(--border-strong); margin-bottom: 8px; }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- Dialog / drawer ---------- */
dialog.modal { border: 0; padding: 0; border-radius: var(--radius); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 20px 50px rgba(36,51,72,.25); color: var(--text); }
dialog.modal::backdrop { background: rgba(36, 51, 72, .4); }
dialog.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(520px, 100vw); border-radius: 0; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); padding: 32px; }
.auth-card .brand { display: flex; justify-content: center; margin-bottom: 24px; }
.auth-card .brand img { height: 40px; }
.auth-card h1 { font-size: 20px; text-align: center; margin-bottom: 6px; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 22px; }
.auth-card .stack { gap: 14px; }
.auth-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; font-size: 13px; }

/* ---------- Permission matrix ---------- */
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }

/* ---------- Charts (inline SVG) ---------- */
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Audio row player ---------- */
.player { display: inline-flex; align-items: center; gap: 8px; min-width: 230px; }
.player .pbar { flex: 1; height: 6px; background: var(--border); border-radius: 999px; position: relative; cursor: pointer; min-width: 80px; }
.player .pbar span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 999px; width: 0; }
.player .ptime { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 72px; }
.player .btn-play { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--accent); background: var(--surface); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; padding: 0; }
.player .btn-play[aria-pressed="true"] { background: var(--accent); color: #fff; }
.player .btn-play .ic { width: 14px; height: 14px; }
.no-rec { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Responsive ---------- */
.scrim { display: none; }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .shell[data-nav-open="true"] .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .shell[data-nav-open="true"] .scrim { display: block; position: fixed; inset: 0; background: rgba(36,51,72,.35); z-index: 40; }
  .topbar { padding: 0 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar .hide-sm { display: none; }
  .content { padding: 16px; }
  .impersonation { padding: 8px 16px; flex-wrap: wrap; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .filters .field { flex: 1 1 140px; }
  .topbar { gap: 8px; }
  .topbar .spacer { display: none; }
  .workspace { flex: 1; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .env-badge span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
