:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-soft: #f0f3ef;
  --ink: #17201b;
  --muted: #647068;
  --line: #dfe4df;
  --line-strong: #cbd3cc;
  --accent: #16774a;
  --accent-dark: #0f5f3a;
  --accent-soft: #e8f4ed;
  --danger: #b42318;
  --danger-soft: #fef0ee;
  --warning: #7a5212;
  --warning-soft: #fff7e6;
  --shadow: 0 18px 50px rgba(28, 45, 35, 0.12);
  --radius: 12px;
  --radius-small: 8px;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
code, pre { font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; }

.topbar {
  height: 68px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
}

.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 720; text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: white; background: var(--accent); font-size: 15px; font-weight: 800; }
.brand-product { color: var(--muted); font-size: 13px; font-weight: 500; padding-left: 9px; border-left: 1px solid var(--line-strong); }
.topnav { display: flex; align-items: center; gap: 20px; font-size: 14px; }
.topnav a, .back-link { text-decoration: none; color: var(--muted); }
.topnav a:hover, .back-link:hover { color: var(--ink); }
.topnav form { margin: 0; }
.nav-button { padding: 0; border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.nav-button:hover { color: var(--ink); }

.page-shell, .settings-shell { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 48px 0 72px; }
.settings-shell { width: min(700px, calc(100% - 48px)); }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; margin-bottom: 30px; }
.compact-heading { display: block; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 9px; font-size: clamp(32px, 4vw, 46px); line-height: 1.05; letter-spacing: -.04em; }
h2 { font-size: 20px; letter-spacing: -.02em; }
.page-heading p:last-child, .login-copy p:last-child { margin-bottom: 0; color: var(--muted); line-height: 1.65; }
.heading-actions { display: flex; gap: 10px; flex: none; }

.button { min-height: 42px; padding: 9px 17px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: var(--radius-small); font-weight: 650; font-size: 14px; line-height: 1; text-decoration: none; cursor: pointer; transition: background-color .15s ease, border-color .15s ease, transform .15s ease; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .5; }
.button-primary { background: var(--accent); color: white; }
.button-primary:hover:not(:disabled) { background: var(--accent-dark); }
.button-secondary { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.button-secondary:hover { background: var(--surface-soft); }
.button-quiet { min-height: 34px; padding: 6px 9px; background: transparent; color: var(--muted); }
.button-quiet:hover { background: var(--surface-soft); color: var(--ink); }
.button-small { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.button-full { width: 100%; }

.security-banner { margin: -16px 0 32px; padding: 17px 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid #ecdcae; border-radius: var(--radius); background: var(--warning-soft); }
.security-banner strong { font-size: 14px; }
.security-banner p { margin: 4px 0 0; color: #6f6045; font-size: 13px; line-height: 1.5; }
.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.summary-strip > div { min-height: 92px; padding: 20px 22px; display: flex; align-items: baseline; gap: 8px; border-right: 1px solid var(--line); }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip span { margin-right: auto; color: var(--muted); font-size: 13px; }
.summary-strip strong { font-size: 24px; letter-spacing: -.03em; }
.summary-strip small { color: var(--muted); font-size: 12px; }
.summary-strip .status-text { font-size: 16px; }
.status-ready { color: var(--accent); }
.status-offline { color: var(--danger); }

.config-section { margin-top: 44px; }
.section-heading { margin-bottom: 14px; display: flex; align-items: baseline; justify-content: space-between; }
.section-heading h2 { margin: 0; }
.section-heading span { color: var(--muted); font-size: 12px; }
.config-table { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.config-row { min-height: 77px; padding: 13px 18px; display: grid; grid-template-columns: minmax(230px, 1.5fr) minmax(155px, .8fr) minmax(170px, 1fr) minmax(260px, auto); align-items: center; gap: 18px; border-top: 1px solid var(--line); }
.config-table-head { min-height: 43px; padding-top: 9px; padding-bottom: 9px; border-top: 0; background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 650; }
.config-row:nth-child(2) { border-top: 0; }
.config-name { min-width: 0; display: flex; align-items: center; gap: 12px; }
.config-name > div { min-width: 0; }
.config-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.config-name small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.file-mark { width: 36px; height: 36px; display: grid; place-items: center; flex: none; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-family: Consolas, monospace; font-size: 12px; font-weight: 800; }
.config-row time { color: #48534c; font-size: 13px; }
.tunnel-address { min-width: 0; }
.tunnel-address code, .tunnel-address small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tunnel-address code { color: #37433b; font-size: 12px; }
.tunnel-address small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.align-right { text-align: right; }
.row-actions { position: relative; display: flex; justify-content: flex-end; align-items: center; gap: 1px; }
.more-button { width: 34px; height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 750; }
.more-button:hover { background: var(--surface-soft); color: var(--ink); }
.row-menu { position: absolute; z-index: 5; top: 38px; right: 0; width: 130px; padding: 6px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: 0 10px 30px rgba(25,40,31,.14); }
.row-menu button { width: 100%; padding: 9px 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; font-size: 13px; }
.row-menu button:hover { background: var(--surface-soft); }
.row-menu .danger-text { color: var(--danger); }

.empty-state { padding: 70px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); text-align: center; }
.empty-icon { width: 52px; height: 52px; margin: 0 auto 20px; display: grid; place-items: center; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-family: Consolas, monospace; font-weight: 800; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { margin-bottom: 22px; color: var(--muted); }

.dialog { width: min(520px, calc(100% - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); }
.dialog::backdrop { background: rgba(21, 31, 25, .5); backdrop-filter: blur(2px); }
.dialog-frame { padding: 26px; display: flex; flex-direction: column; gap: 11px; }
.dialog-wide { width: 100%; }
.dialog:has(.dialog-wide), .dialog:has(.dialog-code) { width: min(720px, calc(100% - 32px)); }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.dialog-heading h2 { margin-bottom: 0; font-size: 24px; }
.dialog-lead { margin: 0 0 5px; color: var(--muted); line-height: 1.55; font-size: 14px; }
.close-button { width: 34px; height: 34px; flex: none; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.close-button:hover { background: var(--surface-soft); color: var(--ink); }
.dialog label, .stack-form > label { margin-top: 3px; font-size: 13px; font-weight: 650; }
input, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-small); outline: none; background: var(--surface); color: var(--ink); }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(22,119,74,.12); }
textarea { resize: vertical; line-height: 1.5; font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
.check-row { display: flex; align-items: flex-start; gap: 10px; font-weight: 400 !important; line-height: 1.55; }
.check-row input { width: 16px; height: 16px; margin: 3px 0 0; flex: none; accent-color: var(--accent); }
.check-row a { color: var(--accent); }
.dialog-note, .secret-warning { padding: 11px 12px; border-radius: 8px; background: var(--surface-soft); color: var(--muted); font-size: 12px; line-height: 1.5; }
.secret-warning { background: var(--warning-soft); color: var(--warning); }
.dialog-actions { margin-top: 9px; display: flex; justify-content: flex-end; gap: 9px; }
.dialog-code pre { max-height: 52vh; margin: 2px 0 0; padding: 17px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; background: #101712; color: #d8e7dc; font-size: 12px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }

.login-shell { min-height: 100vh; padding: 32px; display: grid; place-items: center; background: var(--bg); }
.login-panel { width: min(420px, 100%); padding: 38px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 18px 60px rgba(30,48,37,.08); }
.brand-login { margin-bottom: 54px; }
.login-copy h1 { margin-bottom: 9px; font-size: 38px; }
.login-copy { margin-bottom: 28px; }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
.password-field { position: relative; }
.password-field input { padding-right: 60px; }
.icon-text-button { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); padding: 5px 7px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; }
.icon-text-button:hover { color: var(--ink); background: var(--surface-soft); }
.login-footnote { margin: 19px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; text-align: center; }
.login-footnote code { color: var(--ink); }
.notice { margin: 0 0 18px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-size: 13px; line-height: 1.5; }
.notice-error { border-color: #f0b7b1; color: var(--danger); background: var(--danger-soft); }
.notice-success { border-color: #b7ddc8; color: var(--accent); background: var(--accent-soft); }
.notice-warning { border-color: #ecdcae; color: var(--warning); background: var(--warning-soft); }
.settings-panel { padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.field-help { margin: -3px 0 4px; color: var(--muted); font-size: 12px; }
.form-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 10px; }

.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { max-width: min(380px, calc(100vw - 40px)); padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); box-shadow: 0 10px 30px rgba(23,36,28,.15); color: var(--ink); font-size: 13px; animation: toast-in .18s ease-out; }
.toast-error { border-color: #efb8b3; color: var(--danger); background: #fff8f7; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  .config-table-head { display: none; }
  .config-table { border: 0; background: transparent; }
  .config-row { margin-bottom: 10px; padding: 16px; grid-template-columns: 1fr auto; gap: 14px; border: 1px solid var(--line) !important; border-radius: var(--radius); background: var(--surface); }
  .config-name { grid-column: 1; }
  .config-row time { grid-column: 1; }
  .tunnel-address { display: none; }
  .row-actions { grid-column: 2; grid-row: 1 / span 2; flex-wrap: wrap; max-width: 165px; }
}

@media (max-width: 680px) {
  .topbar { height: 62px; padding: 0 18px; }
  .brand-product, .topnav a { display: none; }
  .page-shell, .settings-shell { width: calc(100% - 32px); padding: 32px 0 56px; }
  .page-heading { display: block; }
  .heading-actions { margin-top: 22px; }
  .heading-actions .button { flex: 1; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .summary-strip > div { min-height: 78px; padding: 16px; }
  .summary-strip > div:nth-child(2) { border-right: 0; }
  .summary-strip > div:last-child { display: none; }
  .summary-strip strong { font-size: 20px; }
  .security-banner { align-items: flex-start; flex-direction: column; }
  .config-section { margin-top: 34px; }
  .config-row { grid-template-columns: 1fr; }
  .config-name, .config-row time, .row-actions { grid-column: 1; grid-row: auto; }
  .row-actions { max-width: none; justify-content: flex-start; }
  .row-actions .more-button { margin-left: auto; }
  .login-shell { padding: 16px; }
  .login-panel { padding: 28px 24px; }
  .brand-login { margin-bottom: 42px; }
  .dialog-frame { padding: 21px; }
  .dialog-actions .button { flex: 1; }
  .settings-panel { padding: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
