/* ProxyKite panel — hand-written, no build step. Accent comes from --accent (branding). */
:root {
  --accent: #4f46e5;
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e3e6eb;
  --text: #16181d; --text-2: #4a505c; --muted: #7a8190;
  --ok: #15803d; --ok-bg: #e7f6ec; --warn: #a16207; --warn-bg: #fdf4dc;
  --bad: #b91c1c; --bad-bg: #fde8e8; --info-bg: #eef0fe;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
    --text: #e8eaef; --text-2: #b4bac6; --muted: #8a91a0;
    --ok: #4ade80; --ok-bg: #12301f; --warn: #facc15; --warn-bg: #33290b;
    --bad: #f87171; --bad-bg: #3a1616; --info-bg: #1e2140;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
  --text: #e8eaef; --text-2: #b4bac6; --muted: #8a91a0;
  --ok: #4ade80; --ok-bg: #12301f; --warn: #facc15; --warn-bg: #33290b;
  --bad: #f87171; --bad-bg: #3a1616; --info-bg: #1e2140;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; color: var(--text); }
.brand img { max-height: 28px; max-width: 120px; }
.brand .dot { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 10px 6px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .main { padding: 16px; }
  .menu-btn { display: inline-flex; }
}

/* cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 18px 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.plain::before { display: none; }

/* forms */
label { display: block; font-weight: 500; margin-bottom: 4px; color: var(--text-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=color] { width: 48px; height: 36px; border: 1px solid var(--border); border-radius: 8px; background: none; padding: 2px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; margin-bottom: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.err { color: var(--bad); font-size: 12px; margin-top: 4px; }
.ok-text { color: var(--ok); } .bad-text { color: var(--bad); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; 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 { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
form.inline { display: inline; }

/* alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--info-bg); color: var(--text); border-color: var(--border); }
.alert.warn { background: var(--warn-bg); color: var(--text); border-color: var(--warn); } /* G3 identity banners */
.dev-badge { font-weight: 500; }
.secret-box { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.secret-box code { flex: 1; background: var(--surface); padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border); overflow-wrap: anywhere; }

/* copy fields */
.copy { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); max-width: 100%; }
.copy code { flex: 1; padding: 7px 10px; overflow-x: auto; white-space: nowrap; }
.copy button { border: 0; border-left: 1px solid var(--border); background: var(--surface); color: var(--text-2); padding: 0 12px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; }
.copy button:hover { color: var(--accent); }
.copy + .copy { margin-top: 6px; }

/* details as light-weight panels */
details.panel { border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; margin-top: 10px; background: var(--surface); }
details.panel > summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
details.panel[open] { padding-bottom: 12px; }

/* tabs (range switch) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg a { padding: 4px 10px; color: var(--text-2); font-size: 12.5px; }
.seg a.on { background: var(--accent); color: #fff; }
.seg a:hover { text-decoration: none; }

/* chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { fill: color-mix(in srgb, var(--accent) 75%, #000); }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }

/* bulk bar */
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.bulkbar select { width: auto; }

/* auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { justify-content: center; padding-bottom: 8px; }

.sms { border-bottom: 1px solid var(--border); padding: 10px 0; }
.sms:last-child { border-bottom: 0; }
.pager { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; }
.theme-toggle { margin-top: 18px; }

/* fixes after visual check */
.btn.menu-btn { display: none; }
@media (max-width: 860px) { .btn.menu-btn { display: inline-flex; margin-bottom: 8px; } }
td .copy { max-width: 280px; }
td .copy code { text-overflow: ellipsis; overflow: hidden; }
td.proxy-cell { min-width: 150px; }
td.proxy-cell strong { white-space: nowrap; }
.grid { margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) a:not(.btn) { color: color-mix(in srgb, var(--accent) 60%, #fff); }
}
:root[data-theme="dark"] a:not(.btn) { color: color-mix(in srgb, var(--accent) 60%, #fff); }

/* Inline edits on the proxies table */
.inline-edit { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inline-edit input[type=text] { width: 100%; max-width: 200px; min-width: 110px; padding: 5px 8px; font-weight: 600; }
.inline-edit select { width: auto; min-width: 120px; padding: 5px 8px; }
.inline-state:empty { display: none; }
.inline-state.ok { color: var(--ok); }
.inline-state.err { color: var(--bad); margin-top: 0; }
.js .nojs { display: none; }

/* F1/F2: flags (<x-flag>) and ISP badges (<x-isp-badge>) */
.flag-wrap { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; }
.flag { width: 20px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px var(--border); object-fit: cover; flex: none; }
.flag-emoji { font-size: 15px; line-height: 1; }
.isp-badge { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; max-width: 100%; }
.isp-badge .isp-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.isp-logo { width: 16px; height: 16px; border-radius: 3px; flex: none; background: #fff; }
.isp-ini { width: 18px; height: 18px; border-radius: 4px; flex: none; display: inline-grid; place-items: center; font-size: 9.5px; font-weight: 700; letter-spacing: -.02em; color: #fff; background: hsl(var(--isp-hue, 230) 55% 45%); }

/* F3: URL-addressable page tabs (?tab=x / #x). Without JS every panel shows, stacked, each with its own heading. */
.ptabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: thin; }
.ptabs a { padding: 9px 11px; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.ptabs a:hover { text-decoration: none; color: var(--text); }
.ptabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.js .ptab-panel:not(.on) { display: none; }
.ptab-panel > .ptab-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 0 10px; }
.js .ptab-panel > .ptab-title { display: none; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.danger-zone h2 { color: var(--bad); }
@media (max-width: 700px) { .kv { grid-template-columns: 110px 1fr; } .ptabs a { padding: 8px 10px; } }

/* Proxies table: whole row opens the proxy page (F4) */
tr[data-href] { cursor: pointer; }
tr[data-href]:hover > td { background: var(--surface-2); }

/* Proxies table (W2b 2026-10-10): fits 1280 px; exit IP folds into the name cell < 1180 px; cards < 700 px. */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ptable th, .ptable td { padding: 9px 8px; }
.ptable th:first-child, .ptable td:first-child { padding-left: 14px; }
.ptable .col-check { width: 1%; }
.ptable td.proxy-cell { min-width: 0; max-width: 230px; }
.ptable .proxy-cell .inline-edit input[type=text] { max-width: 190px; min-width: 0; }
.ptable .cell-meta { overflow-wrap: anywhere; }
.ptable .show-narrow { display: none; }
.ptable .col-status { max-width: 128px; }
.ptable .col-status .badge { white-space: normal; border-radius: 8px; }
.ptable .ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.ptable .col-exit { white-space: nowrap; max-width: 160px; }
.ptable .col-exit .isp-badge { max-width: 150px; }
.ptable td .copy { max-width: 200px; }
.ptable .col-rotate .inline-edit select { min-width: 0; width: 124px; }
.ptable .col-actions { width: 1%; text-align: right; }
@media (max-width: 1180px) {
  .ptable .col-exit { display: none; }
  .ptable .show-narrow { display: block; }
  .ptable td .copy { max-width: 165px; }
}
/* cards wherever the table would not fit: phones/tablets, and narrow desktops while the sidebar is shown */
@media (max-width: 840px), (min-width: 861px) and (max-width: 1099px) {
  .ptable thead { display: none; }
  .ptable, .ptable tbody { display: block; }
  .ptable tr { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .ptable tr:last-child { border-bottom: 0; }
  .ptable td { display: block; padding: 0; border: 0; max-width: none; }
  .ptable td:first-child { padding-left: 0; }
  .ptable .col-check { grid-row: 1; grid-column: 1; }
  .ptable td.proxy-cell { grid-row: 1; grid-column: 2; max-width: none; }
  .ptable .col-status { grid-row: 1; grid-column: 3; text-align: right; }
  .ptable .col-proxy, .ptable .col-rotate, .ptable .col-actions { grid-column: 1 / -1; }
  .ptable tr:not(:has(.col-check)) td.proxy-cell { grid-column: 1 / 3; }
  .ptable td .copy { max-width: none; }
  .ptable .ellip { max-width: none; }
  .ptable td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 4px 0 2px; }
  .ptable .col-actions { text-align: left; width: auto; }
  .ptable .col-rotate .inline-edit select { width: 100%; max-width: 220px; }
}

/* F10/F11: usage bars on the Limits tab */
.limit-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.limit-row:last-of-type { border-bottom: 0; }
.meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; box-shadow: inset 0 0 0 1px var(--border); }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

/* Admin → Tunnels table fits 1280 px: tighter cells, truncated e-mail, actions in a drop-down (2026-10-10) */
table.tunnels th, table.tunnels td { padding: 8px 8px; }
table.tunnels .ellip { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.tunnels td.ports { max-width: 120px; overflow-wrap: anywhere; }
table.tunnels td.col-act { width: 1%; }
details.actmenu { position: relative; display: inline-block; }
details.actmenu > summary { list-style: none; }
details.actmenu > summary::-webkit-details-marker { display: none; }
details.actmenu > summary::after { content: "▾"; font-size: 10px; }
details.actmenu .actmenu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 8px; min-width: 190px; }
details.actmenu .actmenu-list .row { flex-direction: column; align-items: stretch; }
details.actmenu .actmenu-list .btn { width: 100%; }
.card.flush:has(table.tunnels), .card.flush:has(table.tunnels) > .table-wrap { overflow: visible; } /* the drop-down must not be clipped */
table.tunnels td.rip { max-width: 170px; }
table.tunnels td.rip .mono { word-break: break-all; }
.btn[hidden] { display: none; } /* G2 traffic tab "Load more" */
/* Proxies table: icon buttons (rotate / network mode / web UI), sent with fetch() by app.js (2026-10-10) */
.icon { width: 1.15em; height: 1.15em; flex: none; }
.btn.icon-btn { padding: 5px 7px; }
.icon-actions { display: inline-flex; gap: 4px; align-items: center; }
.icon-btn.busy .icon { animation: hyp-spin 1s linear infinite; }
@keyframes hyp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.busy .icon { animation: none; } .icon-btn.busy { opacity: .6; } }
details.iconmenu > summary::after { content: none; }
details.iconmenu .actmenu-list { position: fixed; right: auto; top: auto; min-width: 170px; display: flex; flex-direction: column; gap: 4px; }
.ptable .col-actions .inline-state { margin-top: 3px; white-space: normal; max-width: 220px; margin-left: auto; }
@media (max-width: 700px) { .ptable .col-actions .inline-state { margin-left: 0; } }
.ptable [data-ip].flash { background: var(--ok-bg); color: var(--ok); border-radius: 4px; transition: background .3s; }
/* Admin area (2026-10-11): separate layout, tinted sidebar so admins always know where they are. */
.admin-area .side { background: color-mix(in srgb, var(--bad, #b91c1c) 5%, var(--surface)); }
.admin-pill { font-size: 10px; padding: 1px 6px; margin-left: 4px; vertical-align: middle; }
