:root {
  color-scheme: dark;
  --bg: #0c0f12;
  --panel: #151a1f;
  --panel-2: #1b2228;
  --deep: #10161c;
  --line: #2b343d;
  --text: #eef3f7;
  --muted: #9fadb8;
  --green: #2fd17c;
  --yellow: #f5ba3d;
  --red: #ff5b62;
  --blue: #5bb8ff;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }

.shell { width: min(1312px, calc(100vw - 64px)); margin: 0 auto; padding: 30px 0 64px; }
.topbar, .brand-lockup, .status-bar, .status-main, .metric-line, .section-head, .card-head, .button-row, .inline-form, .client-actions { display: flex; align-items: center; }
.topbar { min-height: 64px; justify-content: space-between; margin-bottom: 22px; }
.brand-lockup { gap: 14px; min-width: 0; }
.site-logo { display: grid; place-items: center; width: 52px; height: 52px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 8px; background: #1b2b32; font-size: 20px; font-weight: 900; }
h1 { font-size: 27px; line-height: 1.15; }
.eyebrow { margin-top: 5px; color: var(--blue); font-size: 11px; font-weight: 800; text-transform: uppercase; }

.icon-button, .copy-button, .primary-button, .test-presets button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); cursor: pointer; font-weight: 800; }
.icon-button { width: 48px; }
.copy-button, .primary-button, .test-presets button { padding: 0 14px; }
.primary-button { border-color: rgba(91,184,255,.55); background: var(--blue); color: #06131b; }
.refresh-icon { width: 16px; height: 16px; border: 2px solid var(--text); border-left-color: transparent; border-radius: 50%; }

.status-bar { min-height: 68px; justify-content: space-between; gap: 24px; padding: 0 20px; margin-bottom: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--deep); }
.status-main { gap: 10px; min-width: 0; }
.status-main strong { white-space: nowrap; }
.status-main > span:last-child { color: var(--muted); font-size: 13px; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(47,209,124,.08); }
.metric-line { justify-content: flex-end; gap: 22px; color: var(--muted); font-size: 12px; }
.metric-line b { color: #bcc7d0; margin-right: 5px; }

.view-tabs { display: flex; gap: 4px; margin-bottom: 24px; }
.view-tabs a { display: inline-flex; align-items: center; justify-content: center; min-width: 92px; height: 40px; border-radius: 7px; color: var(--muted); font-size: 13px; font-weight: 800; }
.view-tabs a.active { background: rgba(91,184,255,.16); color: var(--text); box-shadow: inset 0 0 0 1px rgba(91,184,255,.45); }
.nav-icon { display: none; }
.page-view[hidden] { display: none; }

.section-head { justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.section-head h2 { font-size: 22px; }
.section-head p, .card-head p { margin-top: 6px; color: var(--muted); font-size: 13px; }
.section-count, .advanced-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.client-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 28px; }
.client-card { position: relative; min-width: 0; min-height: 236px; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.client-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue); }
.client-card.green::before { background: #6bd6a3; }
.client-card.yellow::before { background: var(--yellow); }
.client-card h3 { font-size: 19px; }
.client-card p { margin-top: 10px; color: var(--muted); font-size: 13px; }
.client-card code { display: block; margin-top: 30px; color: #dce8f2; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.client-actions { gap: 10px; margin-top: 24px; }
.client-actions .primary-button { min-width: 190px; }
.client-card.green .primary-button { border-color: #6bd6a3; background: #6bd6a3; }
.client-card.yellow .primary-button { border-color: var(--yellow); background: var(--yellow); }

.tools-section { margin-top: 42px; }
.tool-grid, .test-layout, .advanced-content { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px; }
.tool-card, .group, .advanced-panel { border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.tool-card { padding: 20px; }
.tool-card label { display: block; margin-bottom: 12px; }
.inline-form { gap: 10px; }
.inline-form input { flex: 1; min-width: 0; }
.mini-result { min-height: 0; max-height: 48px; overflow: hidden; margin-top: 8px; color: var(--muted); font-size: 12px; }

.advanced-panel { margin-top: 20px; background: var(--panel); }
.advanced-panel summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 70px; padding: 14px 20px; cursor: pointer; list-style: none; }
.advanced-panel summary::-webkit-details-marker { display: none; }
.advanced-panel summary small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 400; }
.advanced-content { padding: 22px; border-top: 1px solid var(--line); }
.card-head { justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.subscription-grid, .import-list { display: grid; gap: 10px; }
.subscription-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
.subscription-card, .import-item, .rule-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.subscription-card h3, .rule-card h3 { margin-bottom: 8px; }
.url-line, .rule-line, .result-code { display: block; width: 100%; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 6px; background: var(--deep); color: #dce8f2; padding: 8px; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.meta-row, .muted, .empty-state { color: var(--muted); }
.meta-row { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.import-item b { display: block; margin-bottom: 5px; }

label { color: var(--text); font-size: 13px; font-weight: 800; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--deep); color: var(--text); font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; outline: none; }
input { min-height: 40px; padding: 0 12px; }
textarea { min-height: 180px; resize: vertical; padding: 10px; }
input:focus, textarea:focus { border-color: rgba(91,184,255,.68); box-shadow: 0 0 0 3px rgba(91,184,255,.12); }
.group { padding: 20px; }
.rule-toolbar { display: grid; grid-template-columns: 120px minmax(0,1fr); gap: 12px; align-items: center; margin-bottom: 16px; }
.rule-columns { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; }
.rule-list { display: grid; gap: 8px; max-height: 680px; overflow: auto; padding-right: 4px; }
.rule-list .rule-line { cursor: pointer; }
.test-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.result-panel { min-height: 220px; }
.route-badge { display: inline-flex; align-items: center; min-height: 32px; border-radius: 999px; padding: 0 12px; font-size: 13px; font-weight: 900; }
.route-badge.direct { background: rgba(47,209,124,.16); color: #a7f3c9; }
.route-badge.proxy { background: rgba(91,184,255,.16); color: #d9f0ff; }
.route-badge.reject { background: rgba(255,91,98,.15); color: #ffb4b8; }
.result-stack { display: grid; gap: 12px; }
.button-row { gap: 8px; }
.token-row { display: grid; grid-template-columns: 120px minmax(0,1fr); gap: 10px; align-items: center; margin-bottom: 14px; }
.message { grid-column: 2; min-height: 20px; color: var(--muted); }
.message.ok { color: var(--green); }
.message.error { color: var(--red); }
.editor-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 20; max-width: min(360px,calc(100vw - 36px)); border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); padding: 12px 14px; opacity: 0; transform: translateY(8px); transition: 160ms ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1000px) {
  .client-grid { gap: 14px; }
  .client-actions { align-items: stretch; flex-direction: column; }
  .client-actions .primary-button { min-width: 0; }
  .rule-columns { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  body { padding-bottom: 78px; }
  .shell { width: calc(100vw - 40px); padding: 20px 0 28px; }
  .topbar { min-height: 56px; margin-bottom: 16px; }
  .site-logo { width: 48px; height: 48px; }
  h1 { font-size: 22px; white-space: nowrap; }
  .icon-button { display: none; }
  .status-bar { min-height: 56px; padding: 0 15px; margin-bottom: 16px; }
  .status-main { width: 100%; justify-content: space-between; }
  .status-main strong { margin-right: auto; }
  .metric-line { display: none; }
  .view-tabs { position: fixed; inset: auto 0 0; z-index: 10; display: grid; grid-template-columns: repeat(4,1fr); gap: 0; height: 72px; margin: 0; padding: 7px 8px; border-top: 1px solid var(--line); background: rgba(12,15,18,.97); backdrop-filter: blur(12px); }
  .view-tabs a { min-width: 0; height: 58px; flex-direction: column; gap: 2px; font-size: 12px; }
  .nav-icon { display: block; height: 18px; font-size: 16px; line-height: 1; }
  .section-head { align-items: flex-end; margin-bottom: 16px; }
  .section-head h2 { font-size: 20px; }
  .section-head p { display: none; }
  .client-grid, .tool-grid, .test-layout, .advanced-content, .subscription-grid, .editor-grid, .token-row, .rule-toolbar { grid-template-columns: 1fr; }
  .client-grid { gap: 12px; }
  .client-card { min-height: 0; padding: 18px; }
  .client-card code { margin-top: 16px; }
  .client-actions { flex-direction: row; align-items: center; justify-content: flex-end; margin-top: 14px; }
  .client-actions .primary-button { min-width: 114px; }
  .client-actions .copy-button { flex: 1; }
  .tools-section { margin-top: 28px; }
  .tool-grid { gap: 10px; }
  .tool-card { padding: 15px; }
  .tool-card .inline-form .primary-button { flex: 0 0 78px; }
  .advanced-panel summary { min-height: 64px; padding: 12px 15px; }
  .advanced-panel summary small { display: none; }
  .advanced-count { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .advanced-content { padding: 14px; }
  .card-head { align-items: stretch; flex-direction: column; }
  .button-row { display: grid; grid-template-columns: 1fr 1fr; }
  .message { grid-column: 1; }
}
