:root {
    --bg: #0f1216; --panel: #171c22; --panel2: #1e252d; --line: #2a333d;
    --fg: #e6edf3; --muted: #8b98a5; --accent: #3b82f6; --danger: #ef4444;
    --on: #22c55e; --off: #64748b;
}
* { box-sizing: border-box; }
body {
    margin: 0; background: var(--bg); color: var(--fg);
    font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
.wrap { max-width: 980px; margin: 0 auto; padding: 20px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .5px; }
.topbar nav { display: flex; align-items: center; gap: 12px; }

.flash { max-width: 980px; margin: 12px auto 0; padding: 10px 14px; border-radius: 8px;
    background: #14351f; color: #b7f7c8; border: 1px solid #1f6b3a; }
.flash.err { background: #3a1518; color: #ffc9ce; border-color: #7a2630; }

.btn {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
    background: var(--panel2); color: var(--fg); border: 1px solid var(--line);
    border-radius: 8px; padding: 7px 12px; font-size: 13px; text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: #ffb4ba; border-color: #5a2a30; }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; }
.inline { display: inline; margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
input, button { font: inherit; }
input {
    background: var(--panel); color: var(--fg); border: 1px solid var(--line);
    border-radius: 8px; padding: 8px 10px;
}
input:focus { outline: none; border-color: var(--accent); }

.meta { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 16px; color: var(--muted); }
.meta b { color: var(--fg); }
.add-client { margin-bottom: 20px; }
.add-client input[name=name] { flex: 1; min-width: 220px; }

.client { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: 14px 16px; margin-bottom: 16px; }
.client.disabled { opacity: .55; }
.client-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.client-head h2 { font-size: 16px; margin: 0; }
.addr { background: var(--panel2); padding: 2px 8px; border-radius: 6px; color: #a5d6ff; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--on); box-shadow: 0 0 8px var(--on); }
.dot.off { background: var(--off); }

table.svc { width: 100%; border-collapse: collapse; margin: 12px 0; }
.svc th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
    border-bottom: 1px solid var(--line); padding: 4px 8px; }
.svc td { padding: 6px 8px; border-bottom: 1px solid var(--panel2); }
.svc tr.svc-off { opacity: .5; }
.svc code { color: #a5d6ff; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.pub { white-space: nowrap; }
.pub code { margin-right: 6px; }
.linkbtns { display: inline-flex; gap: 4px; }
.linkbtns .btn.sm { padding: 1px 7px; }
.btn.copied { border-color: var(--on); color: var(--on); }
.add-svc input[name=name] { min-width: 160px; }
.add-svc input[name=internal_port] { width: 120px; }

.login-card { max-width: 360px; margin: 60px auto; background: var(--panel);
    border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login-card h1 { margin-top: 0; }
.login-card label { display: block; margin: 12px 0; }
.login-card input { width: 100%; margin-top: 4px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }

.empty { text-align: center; padding: 40px; }

.badge { font-size: 11px; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--line); }
.badge.acl-whitelist { color: #b7f7c8; border-color: #1f6b3a; }
.badge.acl-blacklist { color: #ffc9ce; border-color: #7a2630; }

.toolbar { margin-bottom: 18px; }
.client-head .arrow { white-space: nowrap; }

/* Live per-rule throughput indicator */
.rate { font-size: 12px; white-space: nowrap; margin-right: 10px; font-variant-numeric: tabular-nums; }
.rate.on { color: var(--on); }
.rate.idle { color: var(--muted); }

/* Clickable rule row + icon actions */
.proxy-row { cursor: pointer; transition: border-color .12s ease, background .12s ease; }
/* Line 1 (name/addr/controls) stays intact — controls never wrap; the target
   (arrow) ellipsizes if space is tight. Traffic figures live on line 2 and may
   wrap there on their own if very narrow. */
.proxy-row .client-head { flex-wrap: nowrap; }
/* Fields size to their content and only ellipsize when the row actually runs
   out of room; the trailing spacer soaks up any slack instead of padding the
   columns. Name is capped so a long name can't crowd out the addr/target. */
.proxy-row h2 { flex: 0 1 auto; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proxy-row .addr { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proxy-row .arrow { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.proxy-row .row-actions { flex: none; }
.pp-metrics { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
    margin-top: 6px; padding-left: 20px; }
/* Reserve a fixed slot for the live rate so the totals line up as a column. */
.pp-metrics .rate { margin-right: 0; flex: 0 0 auto; min-width: 210px; }
.pp-metrics .status { font-size: 12px; }
.proxy-row:hover { border-color: var(--accent); background: #1b222b; }
.row-actions { display: inline-flex; gap: 2px; opacity: .5; transition: opacity .12s ease; }
.proxy-row:hover .row-actions { opacity: 1; }
.icon-btn {
    background: transparent; border: 1px solid transparent; color: var(--muted);
    padding: 6px; border-radius: 8px; cursor: pointer; display: inline-flex; line-height: 0;
}
.icon-btn:hover { color: var(--fg); background: var(--panel2); border-color: var(--line); }
.icon-btn.on { color: var(--on); }
.icon-btn.danger:hover { color: var(--danger); border-color: #5a2a30; }
.ic { width: 16px; height: 16px; fill: none; stroke: currentColor;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Add/edit rule modal form — dark, matches the app theme */
.modal-box.form-box {
    background: var(--panel); color: var(--fg);
    border: 1px solid var(--line); border-radius: 14px;
    text-align: left; width: min(560px, 94vw); padding: 22px 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.form-box h3 { margin: 0 0 18px; font-size: 17px; color: var(--fg); }
.pform { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.pform label {
    display: flex; flex-direction: column; gap: 6px;
    font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.pform .col-full { grid-column: 1 / -1; }
.pform input, .pform select, .pform textarea {
    width: 100%; text-transform: none; letter-spacing: normal;
    font-size: 14px; padding: 9px 11px;
    background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px;
}
.pform input:focus, .pform select:focus, .pform textarea:focus { outline: none; border-color: var(--accent); }
.pform select option { background: var(--panel); color: var(--fg); }
.pform textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.pform .hint { color: var(--accent); text-transform: none; letter-spacing: normal; font-weight: 500; }
.pform-actions {
    grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px;
    margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--line);
}

/* Traffic stats modal */
.modal-box.stats-box {
    background: var(--panel); color: var(--fg); border: 1px solid var(--line);
    border-radius: 14px; text-align: left; width: min(720px, 95vw); padding: 20px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.stats-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.stats-head h3 { margin: 0; font-size: 16px; }
.tabs { display: inline-flex; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.tab { background: transparent; color: var(--muted); border: 0; border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; }
.tab.active { background: var(--accent); color: #fff; }
.stats-legend { display: flex; gap: 16px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stats-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.stats-legend .sw.in { background: var(--accent); }
.stats-legend .sw.out { background: #2dd4bf; }
.stats-chart { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 10px 4px; }
.stats-chart .pad { padding: 40px; text-align: center; }
.chart-svg { display: block; width: 100%; height: 170px; }
.chart-svg .axis { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-svg .bar-in { fill: var(--accent); }
.chart-svg .bar-out { fill: #2dd4bf; }
.chart-y { position: absolute; top: 8px; right: 12px; font-size: 11px; }
.chart-x { display: flex; justify-content: space-between; font-size: 11px; margin-top: 4px; }
.stats-subh { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.stats-top { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.top-row { display: grid; grid-template-columns: 24px 150px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.top-rank { color: var(--muted); text-align: right; font-size: 11px; }
.top-ip { color: #a5d6ff; }
.top-bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.top-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.top-bytes { color: var(--fg); white-space: nowrap; font-variant-numeric: tabular-nums; }

.settings-form { max-width: 360px; }
.settings-form label { display: block; margin: 10px 0; }
.settings-form input { width: 100%; margin-top: 4px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-box { background: #fff; color: #111; border-radius: 12px; padding: 20px;
    text-align: center; max-width: 90vw; }
.modal-box h3 { margin: 0 0 12px; }
.modal-box svg { width: 260px; height: 260px; }
.modal-box .muted { color: #666; }

.cfg-box { text-align: left; width: min(560px, 92vw); }
.cfg-text {
    text-align: left; background: #0f1216; color: #e6edf3;
    border: 1px solid #2a333d; border-radius: 8px; padding: 12px;
    font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: pre; overflow: auto; max-height: 45vh; margin: 0 0 12px;
    user-select: all;
}
.cfg-actions { display: flex; gap: 8px; justify-content: flex-end; }


/* Profile identity and deletion stay separate from the action row. */
.client-head.profile-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; }
.profile-info { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; min-width: 0; }
.profile-info h2 { overflow-wrap: anywhere; min-width: 0; }
.profile-info label { white-space: nowrap; }
.profile-delete { justify-self: end; }
.profile-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.profile-head > .status { text-align: right; }
