:root {
  --bg: #161b22;
  --panel: #1b2027;
  --panel-hi: #21262d;
  --line: #2a3036;
  --line-control: #484f58;
  --text: #c9d1d9;
  --muted: #8b949e;
  --accent: #3bc9db;
  --accent-bg: #15aabf;
  --accent-ink: #102328;
  --green: #38d9a9;
  --amber: #ffc078;
  --red: #ff8787;
  --radius: 8px;
  --header-height: 64px;
  font-family: Montserrat, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  scroll-padding-block-start: calc(var(--header-height) + env(safe-area-inset-top) + 8px);
}

h1, h2, h3 { font-family: inherit; font-weight: 600; letter-spacing: normal; line-height: 1.45; }
.panel h2, .admin-page > h2 { font-size: 18px; }
.row { gap: 8px; }
.mono { font-family: "IBM Plex Mono", Consolas, monospace; }
.icon { display: inline-block; }

.topbar {
  position: sticky;
  z-index: 4;
  top: 0;
  display: flex;
  align-items: center;
  min-height: calc(var(--header-height) + env(safe-area-inset-top));
  padding-block-start: env(safe-area-inset-top);
  padding-inline: 20px;
  gap: 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-control);
}
.brand { gap: 10px; font-size: 20px; font-weight: 750; letter-spacing: -.035em; color: #f0f6fc; white-space: nowrap; }
.brand img { width: 34px; height: 34px; border: 1px solid var(--line-control); border-radius: 8px; }
.topbar .brand { padding-right: 20px; border-right: 1px solid var(--line-control); }
.topbar nav { display: flex; align-self: stretch; gap: 4px; min-width: 0; }
.topbar details { position: relative; display: flex; }
.topbar summary { list-style: none; cursor: pointer; }
.topbar summary::-webkit-details-marker { display: none; }
.top-link {
  position: relative;
  display: flex;
  height: 100%;
  min-height: 63px;
  align-items: center;
  gap: 8px;
  padding-inline: 11px;
  white-space: nowrap;
  color: #b1bac7;
  font-weight: 500;
}
.top-link > .icon { width: 17px; height: 17px; }
.top-link .down { display: inline-flex; color: var(--muted); }
.top-link .down svg { width: 13px; height: 13px; transform: rotate(90deg); }
.top-link:hover, details[open] > .top-link { background: var(--panel); text-decoration: none; color: var(--text); }
.top-link[aria-current="page"], .top-link.is-active { color: var(--text); font-weight: 650; }
.top-link[aria-current="page"]::after, .top-link.is-active::after {
  content: "";
  position: absolute;
  inset: auto 8px 0;
  height: 2px;
  background: var(--accent-bg);
  border-radius: 2px 2px 0 0;
}
.nav-popover {
  position: absolute;
  inset: calc(100% + 4px) auto auto 0;
  min-width: max(100%, 190px);
  width: max-content;
  padding: 4px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 6px 16px #0b10165c;
}
.nav-link { display: flex; align-items: center; gap: 9px; min-height: 35px; padding: 6px 10px; border-radius: 5px; color: var(--text); }
.nav-link:hover { background: var(--panel-hi); text-decoration: none; }
.nav-link[aria-current="page"] { background: #15aabf21; color: var(--accent); }
.nav-link .icon { width: 17px; height: 17px; }
#identity { margin-inline-start: auto; flex: none; gap: 12px; }
.account { display: flex; align-items: center; gap: 8px; font-size: 12px; line-height: 1.25; }
.account > .icon { width: 17px; height: 17px; color: var(--muted); }
.account small { display: block; margin-top: 3px; font-size: 11px; }
.mobile-menu { display: none !important; }

.admin-page { width: min(calc(100% - 32px), 80%); margin-inline: auto; padding-block: 16px 44px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.admin-title { min-height: 78px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-title h1, .section-heading h2 { font-size: 18px; }
.admin-title p { color: var(--muted); margin-block-start: 2px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.section-heading > .row { gap: 16px; }
.overview-title { min-height: 36px; padding: 0; background: none; border: 0; }
.overview-title .icon-well { display: none; }
.overview-title + .kpis { margin-block-start: -8px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kpi { min-height: 78px; display: flex; align-items: center; gap: 16px; }
.icon-well, .login-icon {
  --well-color: var(--accent);
  --well-rgb: 21 170 191;
  width: 44px;
  height: 44px;
  display: grid;
  flex: none;
  place-items: center;
  color: var(--well-color);
  border: 1px solid rgb(var(--well-rgb) / .27);
  border-radius: var(--radius);
  background: rgb(var(--well-rgb) / .12);
}
.icon-well .icon, .login-icon .icon { width: 22px; height: 22px; }
.kpi .icon-well { border-radius: 16px; }
.kpi-copy { min-width: 0; }
.icon-well.blue { --well-color: #74c0fc; --well-rgb: 34 139 230; }
.icon-well.teal { --well-color: var(--green); --well-rgb: 18 184 134; }
.icon-well.lime { --well-color: #8ce99a; --well-rgb: 64 192 87; }
.icon-well.amber { --well-color: var(--amber); --well-rgb: 253 126 20; }
.kpi strong { display: block; font: 700 21px/1.25 "IBM Plex Mono", Consolas, monospace; }
.kpi .label { display: block; color: var(--muted); font-size: 14px; }
.chart-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart { display: grid; gap: 16px; }
.chart .section-heading { padding-block-end: 12px; border-bottom: 1px solid var(--line); }
.chart .icon-well { width: 36px; height: 36px; }
.chart .icon-well .icon { width: 19px; height: 19px; }
.chart-body { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.chart-day { display: grid; align-items: end; justify-items: center; grid-template-rows: minmax(22px, auto) 115px auto; min-width: 0; gap: 5px; text-align: center; }
.chart-day span, .chart-day small { font: 12px/1.25 "IBM Plex Mono", Consolas, monospace; color: var(--muted); max-width: 100%; overflow-wrap: anywhere; }
.chart-day .bar { width: min(100%, 34px); min-height: 2px; height: var(--height); border-radius: 4px 4px 1px 1px; background: linear-gradient(180deg, #22b8cf, #0e5968); }
.chart.alt .bar { background: linear-gradient(180deg, #20c997, #145745); }

.table-panel { padding: 0; overflow: hidden; container: records / inline-size; }
.table-scroll { overflow-x: auto; scrollbar-color: var(--line-control) var(--panel); }
table { border-collapse: collapse; width: 100%; text-align: start; }
th, td { text-align: start; padding: 10px 16px; vertical-align: middle; }
th { height: 44px; font-size: 13px; font-weight: 700; white-space: nowrap; }
td { height: 50px; border-top: 1px solid var(--line-control); background: var(--bg); max-width: 380px; overflow-wrap: anywhere; }
td small { display: block; color: var(--muted); }
td .btn { white-space: nowrap; }
td .row { gap: 5px; }
td a:not(.btn) { color: var(--text); }
td a:not(.btn):hover { color: var(--accent); }
tbody tr:hover td { background: var(--panel-hi); }
.compact { white-space: nowrap; }
.table-empty { display: grid; min-height: 74px; place-items: center; padding: 16px; color: var(--muted); text-align: center; }
.record-label, .row-action-label { display: none; }
.pagination { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 8px; }
.toolbar { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; padding: 12px 16px; }
.toolbar label { flex: 1 1 156px; max-width: 300px; }
.toolbar label:has(select) { max-width: 230px; }
.admin-title:has(+ .toolbar), .admin-title:has(+ .table-panel), .table-heading { border-radius: 8px 8px 0 0; }
.admin-title + .toolbar { margin-top: -17px; border-radius: 0; border-top-color: var(--line-control); }
.admin-title + .table-panel, .toolbar + .table-panel, .table-heading + .table-panel { margin-top: -17px; border-radius: 0 0 8px 8px; }
.admin-title + .table-panel, .table-heading + .table-panel { border-top-color: var(--line-control); }
.table-heading { min-height: 66px; }
.table-heading .icon-well { height: 36px; width: 36px; }
.table-heading .icon-well .icon { width: 19px; height: 19px; }
.user-name { display: flex; align-items: center; gap: 9px; }
.user-dot { color: #65707c; }
.user-dot.good { color: #20c997; }
.user-dot.bad { color: #fa5252; }
.user-dot.warn { color: #ffa94d; }

.btn, .icon-button { min-height: 36px; padding: 6px 13px; gap: 7px; font-size: 13px; border-radius: var(--radius); border-color: var(--line-control); background: var(--panel-hi); }
.btn:hover, .icon-button:hover { background: #2b323b; border-color: #57616d; }
.btn.outline, .icon-button { background: #ffffff06; border-color: #ffffff25; }
.btn.outline:hover, .icon-button:hover { background: #ffffff10; }
.btn.primary { background: #12b8861b; border-color: #12b8864a; color: var(--green); }
.btn.primary:hover { background: #12b88632; border-color: #12b8867a; }
.btn.danger { background: #fa525213; border-color: #fa525241; }
.btn.danger:hover { background: #fa525228; border-color: #fa525269; }
.btn.small { min-height: 30px; padding-inline: 9px; font-size: 12px; }
.btn.icon-button, .icon-button { width: 42px; min-height: 42px; padding: 0; }
.btn.icon-button.small { width: 32px; min-height: 32px; }
.btn.cyan, .topbar .logout { color: var(--accent); border-color: #15aabf4d; background: #15aabf12; }
.btn.cyan:hover, .topbar .logout:hover { background: #15aabf26; }
.topbar .logout { border-radius: 16px; }
.icon-button .icon { width: 19px; height: 19px; }
.badge { min-height: 23px; padding: 2px 8px; border-radius: 7px; border: 1px solid #ffffff21; background: #ffffff07; color: #adb5bd; font-size: 11px; font-weight: 750; overflow-wrap: normal; }
.badge .dot { width: 6px; height: 6px; }
.badge.good { background: #12b8861b; border-color: #12b88645; }
.badge.warn { background: #fd7e201a; border-color: #fd7e2048; }
.badge.bad { background: #fa525217; border-color: #fa52524d; }
.badge.violet { color: var(--accent); background: #15aabf19; border-color: #15aabf4a; }
.field { color: var(--text); font-size: 13px; font-weight: 550; gap: 5px; }
.field input, .field textarea, .field select { min-height: 36px; padding: 7px 10px; border-radius: var(--radius); border-color: var(--line-control); background: var(--bg); font-size: 14px; font-weight: 400; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.field input:focus, .field textarea:focus, .field select:focus { outline: 1px solid var(--accent-bg); outline-offset: 0; border-color: var(--accent-bg); }
.field textarea { min-height: 90px; }
.check { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; padding: 7px 10px; border-radius: 7px; background: var(--panel-hi); cursor: pointer; }
.check input { appearance: none; display: grid; order: 1; flex: none; align-items: center; width: 40px; height: 22px; margin: 0; border: 1px solid var(--line-control); border-radius: 20px; background: #30363d; cursor: pointer; }
.check input::after { content: ""; width: 14px; height: 14px; margin-inline-start: 3px; border-radius: 50%; background: #f0f6fc; }
.check input:checked { border-color: #12b886; background: #087f5b; }
.check input:checked::after { transform: translateX(18px); }

.pairs { display: grid; gap: 0; margin: 0; }
.pairs div { display: grid; align-items: center; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding-block: 9px; }
.pairs div + div { border-top: 1px solid var(--line); }
.pairs dt { color: var(--muted); }
.pairs dd { margin: 0; overflow-wrap: anywhere; text-align: end; }
.forms-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 16px; }
.settings-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.forms-grid > .panel > .section-heading { border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.forms-grid > .panel { align-content: start; }
.action-list { display: flex; flex-wrap: wrap; gap: 8px; }
.config-input { min-height: 290px !important; font-family: "IBM Plex Mono", Consolas, monospace !important; }
.expired-form { grid-column: 1 / -1; }
.expired-form .config-input { min-height: 230px !important; }
.chat-log { display: grid; align-content: start; gap: 10px; max-height: 490px; overflow: auto; padding: 2px; }
.bubble { padding: 10px 13px; background: var(--panel-hi); max-width: min(86%, 650px); width: max-content; border-radius: var(--radius); border: 1px solid var(--line); }
.bubble.support { margin-inline-start: auto; background: #15aabf17; border-color: #15aabf36; }
.bubble small { display: block; margin-block-end: 5px; }
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 18px; }
.login-card { width: min(100%, 440px); padding: 24px; }
.login-card h1 { font-size: 20px; }
.login-card code { color: var(--accent); }
dialog { border-radius: var(--radius); border-color: var(--line-control); box-shadow: 0 16px 54px #01040966; }
dialog::backdrop { background: #0d1117a6; }
.dialog-body { padding: 16px; }
.dialog-body > .row:first-child { margin: -16px -16px 0; padding: 10px 16px; border-bottom: 1px solid var(--line-control); }
.dialog-body > .row .icon-button { min-height: 32px; width: 32px; }
.toast { background: var(--panel-hi); border-color: #15aabf65; border-radius: var(--radius); box-shadow: 0 5px 24px #01040966; }

@media (max-width: 1500px) { .admin-page { width: min(calc(100% - 32px), max(80%, 1200px)); } }
@media (max-width: 1040px) {
  .topbar { gap: 10px; padding-inline: 12px; }
  .topbar .brand { padding-inline-end: 12px; }
  .top-link { padding-inline: 7px; }
  .account { display: none; }
}
@media (max-width: 940px) {
  .mobile-menu { display: inline-flex !important; }
  .topbar .brand { padding-inline-end: 0; border: 0; }
  .topbar nav { display: none; }
  .topbar nav.open { display: block; position: absolute; inset: calc(100% + 1px) 0 auto; max-height: calc(100dvh - 65px); overflow: auto; padding: 8px 12px; border-bottom: 1px solid var(--line-control); background: var(--panel); box-shadow: 0 10px 25px #01040980; }
  .topbar details { display: block; }
  .top-link { min-height: 42px; border-radius: 6px; }
  .top-link[aria-current="page"]::after, .top-link.is-active::after { inset: 8px auto 8px 0; width: 2px; height: auto; }
  .nav-popover { position: static; width: auto; margin-inline-start: 10px; border: 0; border-left: 1px solid var(--line-control); border-radius: 0; box-shadow: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
}
@container records (max-width: 740px) {
  .table-scroll { overflow: visible; background: var(--bg); }
  table, tbody { display: block; }
  thead { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  tbody { padding: 10px; }
  tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 10px 16px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  tbody tr + tr { margin-block-start: 10px; }
  tbody td, tbody tr:hover td {
    display: block;
    height: auto;
    max-width: none;
    padding: 0;
    border: 0;
    background: none;
  }
  .record-lead, .record-wide, .record-status, .record-actions { grid-column: 1 / -1; }
  .record-lead .record-value { font-weight: 650; }
  .record-lead small { font-weight: 450; }
  .record-lead .record-label, .record-actions .record-label { display: none; }
  .record-label { display: block; margin-block-end: 3px; color: var(--muted); font-size: 12px; font-weight: 550; }
  .record-value { min-width: 0; overflow-wrap: anywhere; }
  .record-value .compact { white-space: normal; }
  .record-value .badge { width: fit-content; }
  .record-actions { display: flex; justify-content: flex-end; padding-block-start: 2px; }
  .record-actions .row { justify-content: flex-end; gap: 8px; }
  .record-actions .btn { min-height: 44px; white-space: normal; }
  .record-actions .btn.icon-button.small { width: auto; padding-inline: 12px; }
  .row-action-label { display: inline; }
  .record-actions .btn:has(.row-action-label) .icon { order: 1; }
  .user-name { align-items: flex-start; }
  .user-name .dot { margin-block-start: 7px; }
  tr:has(.user-name) > .record-status .record-label { display: none; }
}
@container records (344px <= width <= 740px) {
  tbody tr:has(.user-name) { grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr); }
  tr:has(.user-name) > .record-lead { grid-column: auto; }
  tr:has(.user-name) > .record-status { grid-column: auto; justify-self: end; }
}

@media (max-width: 680px) {
  :root { --header-height: 60px; --space: 14px; }
  .admin-page { width: auto; margin-left: max(12px, env(safe-area-inset-left)); margin-right: max(12px, env(safe-area-inset-right)); padding-block: 12px calc(32px + env(safe-area-inset-bottom)); gap: 14px; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar nav.open { max-height: calc(100dvh - var(--header-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .top-link, .nav-link { min-height: 44px; white-space: normal; }
  .admin-title { min-height: 0; gap: 10px; }
  .admin-title .row, .section-heading .row { gap: 10px; }
  .admin-title .row > div { min-width: 0; }
  .admin-title > .row:first-child, .section-heading > .row { flex: 1 1 140px; }
  .admin-title h1, .section-heading h2, .dialog-body h2 { overflow-wrap: break-word; }
  .admin-title .icon-well, .section-heading .icon-well { width: 36px; height: 36px; }
  .admin-title .icon-well .icon, .section-heading .icon-well .icon { width: 19px; height: 19px; }
  .overview-title + .kpis { margin-block-start: -4px; }
  .chart-columns, .forms-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi { align-items: flex-start; padding: 12px; gap: 8px; min-height: 72px; }
  .kpi .icon-well { width: 34px; height: 34px; border-radius: 11px; }
  .kpi .icon { width: 18px; height: 18px; }
  .kpi .label { font-size: 12px; }
  .kpi strong { margin-block-start: 2px; font-size: 16px; }
  .chart-body { gap: 3px; }
  .chart-day span, .chart-day small { font-size: 11px; overflow-wrap: normal; }
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 12px; }
  .toolbar label, .toolbar label:has(select) { max-width: none; }
  .toolbar label:has([name="q"]) { grid-column: 1 / -1; }
  .toolbar .btn { min-width: 0; }
  .admin-title + .toolbar, .admin-title + .table-panel, .toolbar + .table-panel, .table-heading + .table-panel { margin-block-start: -15px; }
  .field input, .field select, .field textarea { min-height: 44px; font-size: 16px; }
  .field input[type="date"] { display: block; max-width: 100%; }
  .btn, .btn.small, .btn.icon-button, .btn.icon-button.small, .icon-button, .dialog-body > .row .icon-button { min-height: 44px; }
  .btn.icon-button, .btn.icon-button.small, .icon-button, .dialog-body > .row .icon-button { width: 44px; }
  .check { min-height: 44px; }
  .action-list { gap: 8px; }
  .pagination { justify-content: center; }
  .config-input { min-height: 190px !important; }
  .chat-log { max-height: min(54dvh, 440px); }
  .bubble { max-width: 94%; }
  dialog { width: min(100% - 24px, 520px); max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .dialog-body > .row:first-child { position: sticky; z-index: 1; top: 0; background: var(--panel); }
  .dialog-body > .row:first-child > h2 { min-width: 0; }
  dialog:focus-within { scroll-padding-block-start: 68px; }
}
@media (max-width: 420px) {
  .kpi { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .kpi .icon-well { width: 30px; height: 30px; border-radius: 9px; }
  .kpi .label { min-height: 2.9em; }
  .pairs dt { overflow-wrap: break-word; }
  .toolbar:not(:has([name="q"])) { grid-template-columns: minmax(0, 1fr); }
  .toolbar:not(:has([name="q"])) .btn { justify-self: start; }
}

:dir(rtl) .check input:checked::after { transform: translateX(-18px); }
