/* HTunnel shared UI — single small hand-rolled stylesheet, no build chain. */
:root {
  --bg: #0f1420; --panel: #171e2e; --panel-2: #1d2638; --border: #2a3550;
  --text: #dbe4f5; --muted: #8494b3; --accent: #4f8cff; --accent-2: #2f6ae0;
  --ok: #2fbf71; --warn: #e0a52f; --err: #e05252; --info: #4f8cff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; }
.muted { color: var(--muted); }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 18px; font-weight: 700; padding: 4px 10px 16px; }
.brand .ver { color: var(--muted); font-size: 11px; font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { color: var(--text); padding: 8px 10px; border-radius: 8px; }
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--accent-2); color: #fff; }
.nav-section { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .08em; }
.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); }
.user-chip { margin-bottom: 6px; font-weight: 600; }
.inline-form { display: inline; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.link-btn:hover { text-decoration: underline; }

.main { flex: 1; padding: 24px 28px; max-width: 1200px; }
body[data-nav="requests"] .main { max-width: none; min-width: 0; }
.page-header h1 { margin: 0 0 18px; font-size: 22px; }
/* mobile drawer controls: desktop-hidden */
.nav-toggle, .nav-burger, .nav-backdrop { display: none; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--panel-2); }
.alert-info { border-color: var(--info); }
.alert-success { border-color: var(--ok); }
.alert-error { border-color: var(--err); color: #f3c1c1; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel h3 { font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

table.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; background: var(--panel-2); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--panel-2); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--border); }
.badge-ok { color: var(--ok); border-color: var(--ok); }
.badge-warn { color: var(--warn); border-color: var(--warn); }
.badge-err { color: var(--err); border-color: var(--err); }
.badge-info { color: var(--info); border-color: var(--info); }
.badge-muted { color: var(--muted); }

form.form { display: flex; flex-direction: column; gap: 12px; max-width: 560px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { margin: 0; color: var(--text); }

.btn { display: inline-block; background: var(--accent-2); color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .65; }
[data-submit-button]:disabled { cursor: wait; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: #8c2f2f; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pagination { display: flex; gap: 6px; margin: 14px 0; }
.page-btn { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.page-btn.current { background: var(--accent-2); color: #fff; }
.page-btn.disabled { color: var(--muted); }

.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }
.filter-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: end; }
.filter-bar .field { min-width: 140px; }
.request-filter-bar { display: grid; grid-template-columns: minmax(110px, .7fr) minmax(120px, .8fr)
  minmax(140px, 1fr) minmax(180px, 1.35fr) minmax(120px, .8fr) auto; align-items: end; }
.request-filter-bar .field { min-width: 0; }
.request-filter-submit .btn { white-space: nowrap; }
.kv { display: grid; grid-template-columns: 220px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.token-reveal { background: var(--panel-2); border: 1px solid var(--warn); border-radius: 8px; padding: 12px; word-break: break-all; }

.auth-layout { max-width: 400px; margin: 10vh auto; padding: 0 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.auth-card h1 { margin: 0 0 18px; font-size: 20px; }

.copy-block { position: relative; }
.copy-block pre { padding-top: 38px; }
.copy-block .copy-btn { position: absolute; top: 8px; left: 8px; }
.copy-block .copy-actions { position: absolute; top: 8px; left: 8px; display: flex; gap: 6px; }
.copy-block .copy-actions .copy-btn { position: static; }

.table .btn { white-space: nowrap; }
.table td.actions-col, .table th.actions-col { white-space: nowrap; width: 1%; }

/* Request history keeps operational columns stable and moves secondary data to the detail dialog. */
.request-table-wrap { min-width: 0; }
.request-table { table-layout: fixed; }
.request-table .request-width-time { width: 166px; }
.request-table .request-width-ip { width: 150px; }
.request-table .request-width-host { width: 220px; }
.request-table .request-width-path { width: auto; }
.request-table .request-width-status { width: 84px; }
.request-table .request-width-duration { width: 82px; }
.request-table .request-width-traffic { width: 104px; }
.request-table .request-width-action { width: 64px; }
.request-table th, .request-table td { vertical-align: middle; }
.request-table td { overflow: hidden; }
.request-nowrap { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  vertical-align: bottom; white-space: nowrap; }
.request-mobile-label { display: none; }
.request-path-link { display: block; min-width: 0; max-width: 100%; overflow: hidden;
  color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.request-path-link:hover { color: var(--accent); }
.request-status-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.request-risk-badge { padding-left: 6px; padding-right: 6px; }
.request-row-risk td:first-child { box-shadow: inset 3px 0 var(--err); }

body.modal-open { overflow: hidden; }
.request-detail-dialog:not([open]) { display: none; }
.request-detail-dialog { width: min(960px, calc(100vw - 32px)); max-width: none;
  height: min(860px, calc(100dvh - 32px)); max-height: none; margin: auto; padding: 0;
  overflow: hidden; color: var(--text); background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 24px 80px rgba(4, 8, 18, .58); font: inherit; }
.request-detail-dialog::backdrop { background: rgba(5, 9, 18, .76); }
.request-detail-dialog-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.request-detail-dialog-header { display: flex; flex: none; align-items: center; justify-content: space-between;
  gap: 18px; padding: 14px 18px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.request-detail-dialog-heading { min-width: 0; }
.request-detail-dialog-heading h2 { margin: 0; font-size: 16px; }
.request-detail-dialog-heading p { max-width: 68ch; margin: 2px 0 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.request-detail-dialog-body { flex: 1; min-height: 0; padding: 18px; overflow: auto;
  overscroll-behavior: contain; }
.request-detail-dialog-body [data-request-detail-content] > :last-child { margin-bottom: 0; }
.request-detail-page-actions { margin-bottom: 12px; }
.request-dialog-state { display: grid; align-content: start; gap: 10px; min-height: 220px; padding: 24px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.request-dialog-state p { margin: 0; }
.request-dialog-state .btn { justify-self: start; margin-top: 4px; }
.request-dialog-skeleton { display: block; width: 72%; height: 12px; border-radius: 6px; background: var(--border); }
.request-dialog-skeleton-wide { width: 92%; margin-top: 8px; }
.request-dialog-skeleton-short { width: 48%; }

@media (max-width: 1280px) {
  .request-filter-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .request-filter-submit .btn { width: 100%; }
}

@media (max-width: 1100px) {
  .request-table-wrap { overflow: visible; }
  table.request-table, .request-table tbody, .request-table tr, .request-table td { display: block; width: 100%; }
  .request-table { background: transparent; border: 0; overflow: visible; }
  .request-table colgroup, .request-table thead { display: none; }
  .request-table tbody { display: grid; gap: 10px; }
  .request-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px 14px;
    padding: 12px 14px; overflow: hidden; background: var(--panel); border: 1px solid var(--border);
    border-radius: 10px; }
  .request-table tr:hover { background: var(--panel-2); }
  .request-table tr:hover td { background: transparent; }
  .request-table td { padding: 0; background: transparent; border: 0; }
  .request-table .request-col-time { grid-column: 1; grid-row: 1; }
  .request-table .request-col-status { grid-column: 2; grid-row: 1 / span 2; justify-self: end; }
  .request-table .request-col-ip { grid-column: 1; grid-row: 2; }
  .request-table .request-col-host { grid-column: 1 / -1; grid-row: 3; }
  .request-table .request-col-path { grid-column: 1 / -1; grid-row: 4; padding: 4px 0; }
  .request-table .request-col-duration { grid-column: 1; grid-row: 5; }
  .request-table .request-col-traffic { grid-column: 1; grid-row: 6; }
  .request-table .request-col-action { grid-column: 2; grid-row: 5 / span 2; align-self: end; }
  .request-mobile-label { display: inline; margin-right: 7px; color: var(--muted);
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 11.5px; }
  .request-status-stack { flex-direction: row; justify-content: flex-end; }
  .request-row-risk td:first-child { box-shadow: none; }
  .request-row-risk { box-shadow: inset 3px 0 var(--err); }
}

@media (max-width: 860px) {
  /* off-canvas drawer navigation (checkbox hack, no layout JS) */
  .layout { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    width: 250px; height: 100dvh; overflow-y: auto;
    transform: translateX(-105%); transition: transform .18s ease;
    box-shadow: 0 0 24px rgba(0,0,0,.5); }
  #nav-toggle:checked ~ .layout .sidebar { transform: none; }
  #nav-toggle:checked ~ .layout .nav-backdrop { display: block; position: fixed;
    inset: 0; z-index: 30; background: rgba(0,0,0,.5); }
  .nav-burger { display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--panel); color: var(--text); font-size: 18px; cursor: pointer;
    user-select: none; flex: none; }
  .page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
    position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 8px 0; }
  .page-header h1 { margin: 0; font-size: 19px; }
  .main { padding: 10px 14px 20px; max-width: none; }
  .panel { padding: 14px; }
  /* wide tables scroll horizontally instead of crushing the layout */
  table.table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table th, .table td { padding: 8px 9px; }
  table.request-table { overflow: visible; }
  .request-table td { padding: 0; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 8px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .stat-value { font-size: 20px; }
  .filter-bar .field { flex: 1 1 160px; }
  .btn-sm { padding: 6px 12px; }
  .tab-nav { overflow-x: auto; white-space: nowrap; }
  .gen-grid { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 auto; text-align: center; }
}

@media (max-width: 680px) {
  .request-filter-bar { grid-template-columns: 1fr; }
  .request-detail-dialog { width: calc(100vw - 16px); height: calc(100dvh - 16px); border-radius: 10px; }
  .request-detail-dialog-header { align-items: flex-start; padding: 12px; }
  .request-detail-dialog-heading p { max-width: 52vw; }
  .request-detail-dialog-body { padding: 12px; }
  .request-detail-dialog-body .panel { padding: 12px; }
}

/* pure-CSS tabs (radio hack, no JS) */
.tabs > input.tab-radio { position: absolute; opacity: 0; pointer-events: none; }
.tab-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-nav label { padding: 8px 16px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600; user-select: none; }
.tab-nav label:hover { color: var(--text); }
.tabs .tab-panel { display: none; }
#tab-download:checked ~ .tab-nav label[for="tab-download"],
#tab-config:checked ~ .tab-nav label[for="tab-config"],
#tab-generator:checked ~ .tab-nav label[for="tab-generator"] { color: var(--accent); border-bottom-color: var(--accent); }
#tab-download:checked ~ .tab-panel[data-panel="download"],
#tab-config:checked ~ .tab-panel[data-panel="config"],
#tab-generator:checked ~ .tab-panel[data-panel="generator"] { display: block; }
.kv-table td:first-child { white-space: nowrap; }
.gen-intro { max-width: 760px; margin-bottom: 18px; }
.gen-intro p { margin: 0 0 6px; }
.config-gen-form { max-width: 920px; }
.gen-section { border-top: 1px solid var(--border); padding: 18px 0 6px; }
.gen-section > h3, .gen-section-heading h3 { margin: 0 0 4px; font-size: 15px; }
.gen-section-help { color: var(--muted); margin: 0; max-width: 760px; }
.gen-section-heading { display: flex; justify-content: space-between; align-items: start; gap: 18px; margin-bottom: 12px; }
.gen-section-heading .btn { flex: none; white-space: nowrap; }
.gen-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field-help { color: var(--muted); font-size: 11.5px; line-height: 1.45; margin: 5px 0 0; }
.required-mark { color: #f3c1c1; font-size: 11px; margin-left: 4px; }
.gen-rows { display: grid; gap: 10px; }
.gen-route-row { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.gen-row-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.gen-row-heading strong { font-size: 12.5px; }
.gen-remove-row { color: #f1a4a4; font-size: 12px; }
.input-suffix { display: flex; align-items: stretch; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.input-suffix input[type=text] { min-width: 90px; border: 0; border-radius: 0; }
.input-suffix span { display: inline-flex; align-items: center; flex: none; padding: 0 10px; border-left: 1px solid var(--border); color: var(--text); background: var(--panel); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.input-suffix:focus-within { outline: 2px solid var(--accent-2); border-color: var(--accent); }
.input-suffix input:focus { outline: none; }
.gen-option { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-top: 10px; }
.gen-option-risk { border-color: #5c4531; }
.gen-check { display: flex; gap: 9px; align-items: flex-start; color: var(--text); margin: 0; cursor: pointer; }
.gen-check input { margin-top: 3px; flex: none; }
.gen-check span { display: grid; gap: 2px; }
.gen-check strong { color: var(--text); font-size: 12.5px; }
.gen-check small { color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.gen-option-detail { margin: 12px 0 0 24px; max-width: 480px; }
.gen-option-detail.is-disabled { opacity: .5; }
.gen-submit { display: flex; align-items: center; gap: 14px; padding-top: 18px; }
.gen-submit p { margin: 0; font-size: 11.5px; }

@media (max-width: 680px) {
  .gen-grid { grid-template-columns: 1fr; }
  .gen-section-heading { align-items: stretch; flex-direction: column; gap: 10px; }
  .gen-section-heading .btn { width: 100%; text-align: center; }
  .gen-route-row { padding: 11px; }
  .input-suffix { flex-direction: column; }
  .input-suffix span { min-height: 34px; border-left: 0; border-top: 1px solid var(--border); }
  .gen-submit { align-items: stretch; flex-direction: column; }
  .gen-submit .btn { width: 100%; }
  .gen-option-detail { margin-left: 0; }
}
