:root {
  color-scheme: dark;
  --bg: #0d1016;
  --surface: #151a23;
  --surface-2: #1c2330;
  --line: #303949;
  --line-soft: #242c39;
  --text: #f5f7fa;
  --muted: #a3aebf;
  --accent: #ff994f;
  --accent-2: #ffb37b;
  --danger: #ff4f64;
  --success: #3ddc97;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.shell { min-height: 100vh; }

.topbar { height: 72px; padding: 0 32px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; background: rgba(11,13,16,.9); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 720; letter-spacing: -.03em; font-size: 19px; }
.brand-mark { width: 30px; height: 30px; display: grid; align-content: center; gap: 4px; padding: 6px 5px; border: 1px solid #3a2b20; border-radius: 9px; background: #1e1510; }
.brand-mark i { display: block; height: 2px; border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(2) { width: 70%; }
.connection-pill { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; }
.connection-pill span { width: 7px; height: 7px; border-radius: 50%; background: #656d78; }
.connection-pill.connected span { background: var(--success); box-shadow: 0 0 10px #3ddc9780; }
.connection-pill.connected strong { color: #bcefd8; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.user-pill { min-height: 38px; display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 5px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: #d6dbe1; cursor: pointer; }
.user-pill > span { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; background: #2c1b0f; color: var(--accent); font-size: 12px; font-weight: 850; }
.user-pill strong { font-size: 12px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-pill:hover { background: var(--surface-2); }

.connect-view { min-height: calc(100vh - 72px); display: grid; grid-template-columns: minmax(0, 1fr) minmax(420px, .95fr); align-items: center; max-width: 1260px; margin: 0 auto; padding: 48px 64px 80px; gap: 80px; }
.connect-card { max-width: 530px; }
.eyebrow { margin: 0 0 13px; color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 800; }
h1 { font-size: clamp(48px, 6vw, 82px); line-height: .96; letter-spacing: -.065em; margin: 0; font-weight: 760; }
.intro { max-width: 500px; color: var(--muted); line-height: 1.65; margin: 28px 0 32px; }
.connect-form label, .form-grid label { display: grid; gap: 9px; color: #cdd2d8; font-weight: 650; font-size: 14px; }
.connect-form { display: grid; gap: 12px; }
.token-row { display: flex; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; transition: border-color .2s, box-shadow .2s; }
.token-row:focus-within { border-color: #ff7a1a99; box-shadow: 0 0 0 3px #ff7a1a18; }
input, select, textarea { color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 13px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: #ff7a1a99; box-shadow: 0 0 0 3px #ff7a1a18; }
.token-row input { border: 0; box-shadow: none !important; flex: 1; border-radius: 0; background: transparent; }
.icon-button, .small-icon-button { display: grid; place-items: center; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.icon-button { width: 48px; }
.icon-button:hover, .small-icon-button:hover { color: var(--text); }
.primary-button, .secondary-button, .danger-button, .disconnect-button { border: 0; border-radius: 10px; min-height: 44px; padding: 0 17px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 9px; font-weight: 750; transition: transform .15s, background .15s, opacity .15s; }
.primary-button { background: var(--accent); color: #1c0d02; }
.primary-button:hover { background: var(--accent-2); transform: translateY(-1px); }
.primary-button:disabled, .secondary-button:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.connect-form > .primary-button { width: 100%; margin-top: 4px; }
.secondary-button { background: var(--surface-2); border: 1px solid var(--line); color: #d8dce1; }
.secondary-button:hover { background: #20262e; }
.danger-button { background: var(--danger); color: #21050b; }
.spinner { display: none; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.form-error { min-height: 20px; margin: 9px 0 0; color: #ff8796; font-size: 13px; }
details { margin-top: 28px; color: var(--muted); font-size: 13px; line-height: 1.55; }
summary { cursor: pointer; color: #c7cbd0; }

.connect-visual { min-height: 520px; position: relative; display: grid; place-items: center; }
.orb { width: 330px; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 38% 32%, #ffad70, #f46e16 36%, #76300f 68%, transparent 70%); filter: blur(.2px); box-shadow: 0 0 110px #ff6b001f; opacity: .78; }
.connect-visual::before { content: ""; position: absolute; inset: 8%; background-image: linear-gradient(#ffffff08 1px, transparent 1px), linear-gradient(90deg, #ffffff08 1px, transparent 1px); background-size: 32px 32px; mask-image: radial-gradient(circle, #000, transparent 72%); }
.record-card { position: absolute; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; min-width: 230px; padding: 15px 17px; background: #11151ae8; border: 1px solid #343b44; border-radius: 12px; box-shadow: 0 22px 70px #0008; backdrop-filter: blur(12px); }
.record-card span { grid-row: 1 / 3; align-self: center; background: #40210c; color: #ff9b4e; border: 1px solid #6f3510; border-radius: 7px; padding: 7px 8px; font-size: 12px; font-weight: 850; }
.record-card b { font-size: 14px; }
.record-card code { color: var(--muted); font-size: 12px; }
.record-card-a { top: 16%; left: 2%; transform: rotate(-4deg); }
.record-card-b { right: 0; top: 43%; transform: rotate(3deg); }
.record-card-c { left: 9%; bottom: 10%; transform: rotate(-1.5deg); }

.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 72px); }
.sidebar { border-right: 1px solid var(--line-soft); padding: 26px 18px 20px; display: flex; flex-direction: column; min-width: 0; }
.sidebar-heading { padding: 0 9px 14px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: 11px; font-weight: 800; }
.small-icon-button { width: 30px; height: 30px; border-radius: 8px; }
.zone-list { display: grid; gap: 4px; overflow-y: auto; }
.zone-button { width: 100%; text-align: left; padding: 11px 12px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: #afb6bf; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zone-button:hover { background: #14181d; color: #fff; }
.zone-button.active { background: #1e1712; border-color: #422818; color: #ffd1ad; }
.disconnect-button { margin-top: auto; background: transparent; border: 1px solid var(--line); color: var(--muted); justify-content: flex-start; }
.disconnect-button:hover { color: var(--text); background: var(--surface); }
.content { padding: 36px clamp(24px, 4vw, 58px); min-width: 0; }
.content-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 30px; }
.breadcrumb { color: var(--muted); letter-spacing: .12em; font-size: 11px; font-weight: 750; margin: 0 0 8px; }
.breadcrumb span { color: var(--success); }
.content h2 { margin: 0; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.04em; }
.compact { min-height: 42px; }
.compact svg { width: 17px; }
.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) 170px auto; gap: 10px; margin-bottom: 14px; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 13px; top: 12px; width: 18px; color: var(--muted); }
.search-field input { width: 100%; padding-left: 41px; }
.select-wrap select { width: 100%; height: 100%; }
.table-card { min-height: 360px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); position: relative; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 13px 16px; text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .09em; background: #0f1216; border-bottom: 1px solid var(--line); }
td { padding: 15px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #151a20; }
.type-badge { display: inline-flex; min-width: 48px; justify-content: center; padding: 5px 7px; border-radius: 6px; background: #242a32; color: #cdd3db; font-size: 11px; font-weight: 850; }
.record-name { font-weight: 680; max-width: 260px; word-break: break-word; }
.record-content { color: #aeb5be; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-width: 360px; word-break: break-all; }
.muted-cell { color: var(--muted); }
.proxy-on, .proxy-off { display: inline-flex; align-items: center; gap: 7px; }
.proxy-on::before, .proxy-off::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.proxy-on { color: #ffc39a; }.proxy-on::before { background: var(--accent); }
.proxy-off { color: var(--muted); }.proxy-off::before { background: #59616b; }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.row-action { border: 0; border-radius: 7px; background: transparent; color: var(--muted); width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; }
.row-action:hover { background: #252b33; color: var(--text); }
.row-action.danger:hover { color: #ff8796; background: #291419; }
.row-action svg { width: 17px; }
.empty-state, .loading-state { min-height: 360px; display: grid; place-items: center; align-content: center; text-align: center; padding: 40px; }
.empty-state h3 { margin: 15px 0 5px; }
.empty-state p, .loading-state p { color: var(--muted); margin: 0; }
.empty-icon { width: 58px; height: 58px; border: 1px solid #49301e; background: #20160f; color: var(--accent); border-radius: 16px; display: grid; place-items: center; font-size: 12px; font-weight: 850; letter-spacing: .05em; }
.loading-state .spinner { display: block; margin-bottom: 13px; color: var(--accent); }
.record-count { margin: 12px 2px 0; color: var(--muted); font-size: 12px; }

.modal { color: var(--text); width: min(620px, calc(100% - 28px)); border: 1px solid #343b44; border-radius: 18px; background: #11151a; padding: 0; box-shadow: 0 30px 100px #000c; }
.modal::backdrop { background: #050607d9; backdrop-filter: blur(4px); }
.modal form { padding: 25px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.modal-header h2 { margin: 0; font-size: 25px; letter-spacing: -.03em; }
.close-button { width: 38px; height: 38px; border-radius: 9px; background: var(--surface-2); }
.form-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 18px; }
.form-grid .full { grid-column: 1 / -1; }
textarea { resize: vertical; }
.switch-row { display: flex !important; flex-direction: row; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.switch-row span { display: grid; gap: 2px; }
.switch-row small { color: var(--muted); font-weight: 450; font-size: 11px; }
input[role="switch"] { appearance: none; width: 38px; height: 22px; border-radius: 999px; padding: 2px; background: #333a43; position: relative; cursor: pointer; border: 0; }
input[role="switch"]::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
input[role="switch"]:checked { background: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(16px); }
.optional { color: var(--muted); font-weight: 450; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
.delete-modal { width: min(440px, calc(100% - 28px)); text-align: center; }
.delete-modal h2 { margin: 15px 0 8px; }
.delete-modal p { color: var(--muted); line-height: 1.55; }
.danger-icon { margin: 0 auto; width: 54px; height: 54px; display: grid; place-items: center; color: #ff8796; background: #291419; border: 1px solid #51202a; border-radius: 15px; }
.delete-modal .modal-actions { justify-content: center; }
.toast-region { position: fixed; right: 22px; bottom: 22px; display: grid; gap: 10px; z-index: 20; }
.toast { min-width: 270px; max-width: 390px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 10px; background: #171c22; box-shadow: 0 15px 50px #0008; animation: toast-in .2s ease-out; }
.toast.success { border-color: #275c46; }.toast.error { border-color: #6b2833; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 75% 15%, #4d210d 0, transparent 25%), radial-gradient(circle at 25% 85%, #25170e 0, transparent 30%), var(--bg); }
.login-card { width: min(520px, 100%); padding: clamp(28px, 6vw, 56px); border: 1px solid var(--line); border-radius: 22px; background: #11151af2; box-shadow: 0 30px 100px #0009; }
.login-brand { margin-bottom: 58px; }
.login-card h1 { font-size: clamp(48px, 9vw, 70px); }
.login-card .intro { margin-bottom: 28px; }
.login-button { width: 100%; text-decoration: none; }
.login-note { color: #666f7a; font-size: 12px; line-height: 1.5; text-align: center; margin: 18px 0 0; }
.login-error { color: #ff8796; font-size: 13px; text-align: center; margin: 15px 0 0; }

.topbar { background: #11151d; padding-inline: clamp(18px, 4vw, 56px); }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; }
.connect-view { min-height: calc(100svh - 72px); display: flex; justify-content: center; padding: 44px 20px; background: radial-gradient(ellipse at 50% 0%, #ff994f0d, transparent 65%); }
.connect-card { width: 100%; max-width: 540px; padding: clamp(24px, 5vw, 42px); border: 1px solid var(--line); border-top: 2px solid #ff994f80; border-radius: 22px; background: var(--surface); box-shadow: 0 24px 80px #0003; }
.connect-card h1 { font-size: clamp(34px, 5vw, 48px); line-height: 1.1; letter-spacing: -.045em; }
.connect-card h1 span { color: var(--muted); }
.connect-card .intro { margin: 18px 0 28px; line-height: 1.6; }
.connect-form { gap: 10px; }
.connect-form input { width: 100%; min-height: 50px; background: var(--bg); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.connect-form label:not(:first-child) { margin-top: 8px; }
.token-row { background: var(--bg); }
.token-row input { width: 0; }
.token-row .icon-button { flex-shrink: 0; }
.connect-form .primary-button { min-height: 50px; margin-top: 10px; }
.form-error:empty { display: none; }
.storage-note { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 16px 0 0; }
.connect-card details { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 20px; font-size: 14px; }
.workspace { max-width: 1680px; margin-inline: auto; }
.sidebar { background: #10151d; padding-top: 28px; gap: 12px; }
.sidebar-heading { font-size: 12px; }
.zone-button { min-height: 46px; font-size: 14px; }
.zone-button.active { background: #ff994f0e; border-color: #ff994f35; box-shadow: inset 3px 0 var(--accent); }
.disconnect-button { font-size: 13px; min-height: 44px; margin-bottom: 8px; }
.content { padding-top: 40px; }
.content h2 { overflow-wrap: anywhere; }
.table-card { box-shadow: 0 16px 48px #0002; border-radius: 16px; }
th { font-size: 12px; background: #11161f; padding-block: 17px; }
td { padding-block: 19px; }
tbody tr:hover { background: #1b2230; }
.type-badge { border: 1px solid #ff994f30; background: #ff994f0b; color: #ffc396; font-size: 12px; }
.record-content { font-size: 14px; color: #b6c2d2; }
.row-action { width: 42px; height: 42px; border: 1px solid var(--line); background: #11161f; }
.record-count { font-size: 13px; }
.modal { background: var(--surface); max-height: calc(100svh - 32px); }
.modal input, .modal textarea, .modal select { background: var(--bg); }
.modal-actions { padding-top: 20px; border-top: 1px solid var(--line); }
.login-page { background: radial-gradient(ellipse at 50% 0%, #ff994f12, transparent 65%), var(--bg); }
.login-card { background: var(--surface); border-top: 2px solid #ff994f80; }
.login-brand { margin-bottom: 36px; }
.login-card h1 { font-size: clamp(38px, 7vw, 54px); line-height: 1.1; letter-spacing: -.045em; }
.login-note { color: var(--muted); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

@media (max-width: 900px) {
  .connect-view { grid-template-columns: 1fr; padding: 50px 28px; }
  .connect-visual { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 18px; display: block; }
  .sidebar-heading { display: none; }
  .zone-list { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .zone-button { width: auto; flex: 0 0 auto; }
  .disconnect-button { margin-top: 10px; min-height: 38px; }
}

@media (max-width: 650px) {
  .topbar { height: 64px; padding: 0 18px; }
  .connection-pill strong { display: none; }
  .user-pill strong { display: none; }
  .connect-view { min-height: calc(100vh - 64px); padding: 45px 20px; }
  h1 { font-size: 50px; }
  .content { padding: 25px 16px; }
  .content-header { align-items: flex-start; }
  .compact { width: 44px; padding: 0; }
  .compact span { display: none; }
  .toolbar { grid-template-columns: 1fr 130px; }
  .toolbar .secondary-button { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .modal form { padding: 20px; }
  th:nth-child(4), td:nth-child(4), th:nth-child(5), td:nth-child(5) { display: none; }
}

@media (max-width: 650px) {
  .connect-view { padding: 24px 14px; align-items: flex-start; min-height: calc(100svh - 64px); }
  .connect-card { padding: 26px 20px; border-radius: 18px; }
  .content-header { flex-wrap: wrap; gap: 18px; }
  .compact { width: auto; padding: 0 14px; }
  .compact span { display: inline; }
  .toolbar { grid-template-columns: minmax(0, 1fr) 120px; }
  .toolbar input, .toolbar select { font-size: 16px; }
  .table-card { min-height: 0; border: 0; background: transparent; box-shadow: none; overflow: visible; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; }
  tbody tr { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
  tbody td { display: block; padding: 0; border: 0; min-width: 0; }
  tbody td:nth-child(1) { grid-column: 1; grid-row: 1; align-self: center; }
  tbody td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; max-width: none; font-size: 16px; }
  tbody td:nth-child(3) { grid-column: 1 / -1; grid-row: 3; max-width: none; padding: 12px; background: var(--bg); border-radius: 8px; }
  tbody td:nth-child(4) { display: block; grid-column: 1; grid-row: 4; font-size: 13px; }
  tbody td:nth-child(4)::before { content: 'TTL · '; }
  tbody td:nth-child(5) { display: block; grid-column: 2; grid-row: 4; font-size: 13px; text-align: right; }
  tbody td:nth-child(5)::before { content: 'Proxy · '; color: var(--muted); }
  tbody td:nth-child(6) { grid-column: 2; grid-row: 1; }
  .row-action { width: 44px; height: 44px; }
  .zone-button { min-height: 44px; }
  .sidebar { padding-inline: 16px; }
  .empty-state { border: 1px dashed var(--line); border-radius: 16px; min-height: 270px; padding: 24px; }
  .toast-region { left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
