:root {
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, monospace;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow: 0 18px 60px rgb(0 0 0 / 18%);
  --accent: #7c6cf2;
  --accent-strong: #6654e8;
  --danger: #dc5f6d;
  --success: #3ca77a;
}

html[data-theme="dark"] {
  --bg: #0d0e12;
  --surface: #14161c;
  --surface-raised: #1b1e26;
  --surface-hover: #222631;
  --text: #f4f5f8;
  --text-muted: #9ca3b5;
  --border: #292d38;
  --sidebar: #101116;
  --input: #111319;
}

html[data-theme="light"] {
  --bg: #f5f5f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-hover: #f0effa;
  --text: #1e2028;
  --text-muted: #686f80;
  --border: #dfe1e8;
  --sidebar: #ffffff;
  --input: #fafafe;
  --shadow: 0 18px 60px rgb(34 31 64 / 10%);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-sans); }
body { min-height: 100vh; margin: 0; background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 780px; font-size: clamp(2.3rem, 5vw, 4.7rem); line-height: .98; letter-spacing: -.055em; }
h2 { font-size: 1.45rem; letter-spacing: -.025em; }
h3 { margin-bottom: var(--space-2); }
p { line-height: 1.65; }
.muted, small { color: var(--text-muted); }
.eyebrow { color: var(--text-muted); font-size: .73rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark { display: block; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 10px; object-fit: cover; }
.public-header { display: flex; min-height: 72px; align-items: center; justify-content: space-between; padding: 0 clamp(20px, 5vw, 72px); border-bottom: 1px solid var(--border); }
.public-header nav { display: flex; align-items: center; gap: var(--space-5); }
.public-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: clamp(56px, 9vw, 120px) 0; }
.hero { display: grid; grid-template-columns: 1.35fr .65fr; gap: clamp(40px, 8vw, 100px); align-items: center; }
.hero > div > p { max-width: 680px; color: var(--text-muted); font-size: 1.12rem; }

.panel { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.preview { padding: var(--space-6); transform: rotate(1deg); }
.preview h2 { margin: var(--space-4) 0 var(--space-5); }
.status { display: inline-block; padding: 6px 10px; border-radius: 999px; color: #b9f1d8; background: rgb(60 167 122 / 18%); font-size: .76rem; font-weight: 700; }
html[data-theme="light"] .status { color: #247151; }
.preview-note { padding: var(--space-4) 0; border-top: 1px solid var(--border); }
.preview-note p { margin: 4px 0 0; color: var(--text-muted); font-size: .9rem; }
.community-hero { align-items: start; }
.community-hero h1 { margin-top: var(--space-4); }
.access-note { margin: var(--space-4) 0 0; font-size: .82rem !important; }
.community-card { transform: none; }
.community-section { margin-top: clamp(72px, 10vw, 128px); }
.community-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.community-feature { min-height: 230px; padding: var(--space-5); box-shadow: none; }
.community-feature p { color: var(--text-muted); }
.feature-index { display: block; margin-bottom: var(--space-7); color: var(--accent); font-family: var(--font-mono); font-size: .8rem; }
.community-invite { display: flex; align-items: center; justify-content: space-between; gap: var(--space-6); margin-top: var(--space-7); padding: clamp(24px, 5vw, 48px); }
.community-invite h2 { max-width: 620px; margin: var(--space-3) 0; font-size: clamp(1.7rem, 4vw, 2.7rem); }
.community-invite p { max-width: 680px; margin-bottom: 0; color: var(--text-muted); }
.community-invite .button-row { flex: 0 0 auto; }

.button-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 9px; padding: 0 18px; border: 1px solid var(--accent); border-radius: var(--radius-sm); color: white; background: var(--accent); cursor: pointer; font-weight: 700; }
.button:hover { background: var(--accent-strong); }
.button.secondary { color: var(--text); border-color: var(--border); background: var(--surface); }
.button.compact { min-height: 36px; padding: 0 13px; }
.button.telegram { width: 100%; background: #2aabee; border-color: #2aabee; }
.button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.button:disabled { cursor: wait; opacity: .65; }

.auth-grid { display: grid; grid-template-columns: 1fr minmax(320px, 480px); gap: clamp(40px, 9vw, 120px); align-items: start; }
.auth-grid h1 { font-size: clamp(2.4rem, 5vw, 4rem); }
.auth-card { padding: clamp(24px, 5vw, 40px); }
.form-stack { display: grid; gap: var(--space-4); }
label { display: grid; gap: 7px; color: var(--text-muted); font-size: .85rem; font-weight: 650; }
input, textarea, select { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; color: var(--text); background: var(--input); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(124 108 242 / 16%); }
textarea { resize: vertical; line-height: 1.6; }
.divider { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-5) 0; color: var(--text-muted); font-size: .8rem; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }

.app-layout { display: grid; min-height: 100vh; grid-template-columns: 260px 1fr; }
.sidebar { position: sticky; top: 0; display: flex; height: 100vh; flex-direction: column; gap: var(--space-6); padding: var(--space-5); border-right: 1px solid var(--border); background: var(--sidebar); }
.main-nav { display: grid; gap: 6px; }
.main-nav a, .nav-button { display: flex; width: 100%; align-items: center; gap: 11px; min-height: 42px; padding: 0 12px; border: 0; border-radius: var(--radius-sm); background: transparent; cursor: pointer; }
.main-nav a:hover, .nav-button:hover { background: var(--surface-hover); }
.workspace-list { display: grid; gap: 6px; overflow-y: auto; }
.workspace-list a { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.workspace-list a:hover { background: var(--surface-hover); }
.workspace-list small { display: block; margin-top: 2px; font-size: .68rem; text-transform: uppercase; }
.workspace-mark { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised); font-weight: 750; }
.workspace-mark.large { width: 48px; height: 48px; font-size: 1.1rem; }
.sidebar-footer { display: grid; gap: 4px; margin-top: auto; }
.sidebar-footer form { margin: 0; }
.app-main { min-width: 0; }
.topbar { display: flex; min-height: 92px; align-items: center; justify-content: space-between; padding: 0 clamp(24px, 5vw, 64px); border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 3px 0 0; font-size: 1.45rem; letter-spacing: -.03em; }
.user-chip { padding: 9px 12px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); background: var(--surface); font-size: .84rem; }
.page-shell { width: min(1120px, calc(100% - 48px)); margin: 0 auto; padding: var(--space-7) 0 80px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: var(--space-5); }
.section-heading h2 { margin: 5px 0 0; }
.workspace-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); }
.workspace-card { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-5); box-shadow: none; }
.workspace-card:hover, .note-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.workspace-card h2, .workspace-card p { margin: 0; }
.workspace-card p { margin-top: 4px; color: var(--text-muted); font-size: .85rem; }
.create-panel { margin: var(--space-5) 0; padding: var(--space-5); box-shadow: none; }
.create-panel summary { display: flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 720; }
.create-panel[open] summary { margin-bottom: var(--space-5); }
.inline-form { display: flex; gap: var(--space-3); }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-4); }
.note-card { min-height: 180px; padding: var(--space-5); box-shadow: none; transition: .18s ease; }
.note-card p { color: var(--text-muted); }
.note-card small { display: block; margin-top: auto; }
.empty { grid-column: 1 / -1; padding: var(--space-6); text-align: center; box-shadow: none; }
.note-editor { width: min(820px, 100%); margin: 0 auto; padding: clamp(24px, 5vw, 56px); }
.title-input { padding: 0 0 var(--space-4); border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent; font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 760; letter-spacing: -.05em; }
.document-input { min-height: 56vh; padding: 0; border: 0; background: transparent; font-family: var(--font-mono); font-size: .95rem; }
.title-input:focus, .document-input:focus { box-shadow: none; }
.flash { margin-bottom: var(--space-4); padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.flash.error { border-color: var(--danger); }
.flash.success { border-color: var(--success); }
.admin-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--space-6); }
.admin-nav a { padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.admin-nav a:hover { border-color: var(--accent); }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); }
.metric-card { display: grid; gap: var(--space-3); padding: var(--space-5); box-shadow: none; }
.metric-card strong { font-size: 2rem; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); }
.plan-card { display: grid; gap: var(--space-4); padding: var(--space-5); box-shadow: none; }
.plan-card h2, .plan-card p { margin: 0; }
.plan-card p { color: var(--text-muted); }
.plan-card strong { font-size: 1.65rem; }
.plan-card form { margin-top: auto; }
.server-choice { margin: 0; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); }
.server-choice legend { padding: 0 var(--space-2); font-weight: 700; }
.server-choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-3); }
.server-choice-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--input); }
.server-choice-item input, .checkbox-row input { width: auto; flex: 0 0 auto; }
.server-choice-item span { display: grid; gap: 2px; color: var(--text); }
.server-choice-item small { font-weight: 400; }
.checkbox-row { display: flex; align-items: center; gap: var(--space-3); }
.subscription-connect-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-4); }
.subscription-connect-list .create-panel { margin: var(--space-5) 0 0; }
.connections-list { display: grid; gap: var(--space-5); }
.connection-card { display: grid; gap: var(--space-5); padding: clamp(20px, 4vw, 32px); box-shadow: none; }
.connection-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-5); }
.connection-heading h2 { margin: var(--space-2) 0 4px; }
.connection-heading p { margin: 0; }
.connection-renewal { display: grid; justify-items: end; gap: var(--space-3); text-align: right; }
.connection-renewal form { margin: 0; }
.connection-server, .connection-pending { display: grid; gap: var(--space-4); padding-top: var(--space-5); border-top: 1px solid var(--border); }
.connection-server h3, .connection-server p, .connection-pending h3, .connection-pending p { margin: 0; }
.connection-warning { margin: 0; }
.renewal-history { padding-top: var(--space-4); border-top: 1px solid var(--border); }
.renewal-history summary { cursor: pointer; font-weight: 700; }
.renewal-history .table-wrap { margin-top: var(--space-3); }
.connections-footer { display: flex; justify-content: center; margin-top: var(--space-7); }
.balance-chip { flex: 0 0 auto; padding: 9px 12px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); background: var(--surface); font-size: .84rem; }
.spaced { margin-top: var(--space-7); }
.server-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-4); }
.server-card { display: grid; gap: var(--space-4); padding: var(--space-5); box-shadow: none; }
.server-card h2, .server-card p { margin: 0; }
.server-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.server-card-heading h3 { margin: var(--space-2) 0 0; }
.ping-value { flex: 0 0 auto; font-family: var(--font-mono); color: var(--accent); }
.dashboard-server-card { color: inherit; }
.dashboard-server-card:hover { border-color: var(--accent); }
.server-meta { display: flex; gap: var(--space-3); color: var(--text-muted); font-size: .85rem; }
.copy-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); }
.server-health-card { display: grid; width: 100%; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-3); align-items: center; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); color: inherit; background: var(--surface-raised); cursor: pointer; text-align: left; }
.server-health-card strong { display: block; color: #62c979; font-weight: 740; overflow-wrap: anywhere; }
.server-health-card small { display: block; margin-top: 3px; }
.health-icon { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 999px; color: #fff; font-size: .82rem; font-weight: 800; }
.health-icon.online { background: #48bf65; }
.health-icon.offline { background: var(--danger); }
.health-arrow { color: #62c979; font-size: 1.7rem; line-height: 1; }
.server-stats-dialog { width: min(430px, calc(100vw - 28px)); max-height: min(820px, calc(100vh - 28px)); padding: 0; border: 1px solid var(--border); border-radius: 0 var(--radius-lg) var(--radius-lg) 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.server-stats-dialog::backdrop { background: rgb(0 0 0 / 68%); }
.server-stats-modal { display: grid; max-height: inherit; }
.server-stats-modal header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-5); border-bottom: 1px solid var(--border); background: var(--surface); }
.server-stats-modal h2 { margin: 0; }
.dialog-close { display: grid; width: 36px; height: 36px; place-items: center; border: 0; border-radius: 999px; background: var(--surface-hover); cursor: pointer; font-size: 1.7rem; line-height: 1; }
.server-stats-body { display: grid; gap: var(--space-4); padding: var(--space-5); overflow-y: auto; }
.stats-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-3); align-items: center; padding: var(--space-4); border-radius: var(--radius-md); background: var(--surface-raised); }
.stats-row.success strong { color: #62c979; }
.stats-row.muted-row { color: var(--text-muted); }
.stats-row small { display: block; margin-top: 4px; }
.user-stats-chart { display: grid; gap: var(--space-3); }
.user-stats-chart > div { display: flex; justify-content: space-between; gap: var(--space-3); align-items: end; }
.user-stats-chart strong { color: var(--text-muted); font-size: .85rem; }
.area-chart { width: 100%; height: 190px; padding: var(--space-3); border-radius: var(--radius-md); background: var(--surface-raised); overflow: visible; }
.area-chart polygon { opacity: .72; }
.area-chart polyline { fill: none; stroke-width: 1.8; vector-effect: non-scaling-stroke; }
.area-chart.blue polygon { fill: #1d6fab; }
.area-chart.blue polyline { stroke: #2d8ad8; }
.area-chart.orange polygon { fill: #bd7227; }
.area-chart.orange polyline { stroke: #e0933e; }
.area-chart.green polygon { fill: #2f9065; }
.area-chart.green polyline { stroke: #50c58d; }
.chart-empty.compact { min-height: 160px; border-radius: var(--radius-md); background: var(--surface-raised); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.stats-grid > div { padding: var(--space-4); border-radius: var(--radius-md); background: var(--surface-raised); }
.stats-grid strong { display: block; margin-top: var(--space-2); font-size: 1.05rem; }
.classic-link-list { display: grid; gap: var(--space-3); margin-top: var(--space-3); }
.classic-links-unavailable { margin: 0; font-size: .85rem; }
.monitoring-list { display: grid; gap: var(--space-7); }
.monitoring-server { display: grid; gap: var(--space-4); }
.monitoring-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); padding: var(--space-5); box-shadow: none; }
.monitoring-header h2 { margin: var(--space-2) 0; }
.monitoring-header p { margin: 0; }
.monitoring-actions { display: flex; align-items: center; gap: var(--space-4); }
.monitoring-actions form { margin: 0; }
.monitoring-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); }
.monitoring-value strong { overflow-wrap: anywhere; font-size: 1.45rem; }
.monitoring-charts { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr); gap: var(--space-4); }
.chart-card { min-height: 300px; padding: var(--space-5); box-shadow: none; }
.chart-card h3 { margin-top: var(--space-2); }
.chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.chart-heading strong { color: var(--accent); font-family: var(--font-mono); font-size: 1.5rem; }
.line-chart { width: 100%; height: 190px; margin-top: var(--space-4); overflow: visible; }
.line-chart polyline { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.line-chart .chart-grid { fill: none; stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-axis { display: flex; justify-content: space-between; color: var(--text-muted); font-size: .72rem; }
.chart-empty { display: grid; min-height: 190px; place-items: center; color: var(--text-muted); text-align: center; }
.usage-meter { display: grid; gap: var(--space-2); margin-top: var(--space-5); }
.usage-meter > div:first-child { display: flex; justify-content: space-between; gap: var(--space-3); font-size: .82rem; }
.usage-meter span { color: var(--text-muted); }
.meter-track { height: 10px; overflow: hidden; border-radius: 999px; background: var(--surface-hover); }
.meter-track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.monitoring-inbounds { box-shadow: none; }
.monitoring-table-title { padding: var(--space-5) var(--space-5) 0; }
.monitoring-table-title h3 { margin-top: var(--space-2); }
.monitoring-raw { padding: var(--space-5); box-shadow: none; }
.monitoring-raw summary { cursor: pointer; font-weight: 700; }
.monitoring-raw pre { max-height: 420px; margin: var(--space-4) 0 0; overflow: auto; color: var(--text-muted); font: .78rem/1.6 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-search { max-width: 620px; margin-bottom: var(--space-4); }
.table-wrap { max-width: 100%; overflow-x: clip; box-shadow: none; }
table { width: 100%; table-layout: fixed; border-collapse: collapse; }
th, td { min-width: 0; padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; overflow-wrap: anywhere; word-break: normal; }
th { color: var(--text-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
td small { display: block; margin-top: 3px; color: var(--text-muted); }
tbody tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.table-actions form, td form { margin: 0; }
td .button.compact { min-height: 32px; padding: 0 10px; white-space: normal; }

@media (max-width: 820px) {
  .hero, .auth-grid { grid-template-columns: 1fr; }
  .preview { transform: none; }
  .community-grid { grid-template-columns: 1fr; }
  .community-feature { min-height: 0; }
  .feature-index { margin-bottom: var(--space-5); }
  .community-invite { align-items: flex-start; flex-direction: column; }
  .monitoring-charts { grid-template-columns: 1fr; }
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .workspace-list, .main-nav { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .sidebar-footer { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .public-header { padding: 0 18px; }
  .public-header nav > a:first-child { display: none; }
  .public-shell { width: min(100% - 28px, 1180px); padding-top: 42px; }
  .page-shell { width: min(100% - 28px, 1120px); padding-top: 28px; }
  .topbar { padding: 0 16px; }
  .user-chip { display: none; }
  .inline-form { flex-direction: column; }
  .copy-field { grid-template-columns: 1fr; }
  .connection-heading { flex-direction: column; }
  .connection-renewal { justify-items: start; text-align: left; }
  .server-stats-dialog { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }
  .server-stats-body { padding: var(--space-4); }
  .stats-grid { grid-template-columns: 1fr; }
  .section-heading .balance-chip { display: none; }
  .monitoring-header, .monitoring-actions { align-items: flex-start; flex-direction: column; }
  .notes-grid { grid-template-columns: 1fr; }
  table { font-size: .82rem; }
  th, td { padding: 9px 7px; }
  th { font-size: .66rem; letter-spacing: .04em; }
}
