:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #10b981;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text-main); font-size: 14px; line-height: 1.5; }

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-xs { font-size: 12px; }
.fw-bold { font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

.ok-text { color: var(--success); }
.bad-text { color: var(--danger); }
.inline-link { color: var(--primary); text-decoration: none; word-break: break-all; }
.inline-link:hover { color: var(--primary-hover); text-decoration: underline; }
.ssh-tunnel-copy { display: inline-flex; max-width: 100%; }
.ssh-tunnel-copy.is-copyable { color: var(--primary); cursor: copy; font-weight: 600; }
.ssh-tunnel-copy.is-copyable:hover { color: var(--primary-hover); text-decoration: underline; }

/* Login Shell */
.login-shell { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.05); backdrop-filter: blur(4px); z-index: 50; }
.login-card { background: var(--surface); padding: 32px; border-radius: var(--radius-lg); box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); width: 100%; max-width: 360px; }
.login-card h2 { font-size: 24px; margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-muted); margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.form-group input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: var(--primary); }
.status-text { margin-top: 12px; color: var(--danger); font-size: 13px; text-align: center; }
.captcha-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.captcha-question { margin-top: 6px; color: var(--text-muted); font-size: 12px; }
.login-attempts { margin: -4px 0 14px; color: var(--text-muted); font-size: 12px; line-height: 1.45; }

/* Buttons */
button { font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; border: none; border-radius: var(--radius-sm); transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; }
.btn-primary { background: var(--primary); color: white; padding: 8px 16px; width: 100%; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 6px 12px; }
.btn-ghost:hover { background: var(--border); color: var(--text-main); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-danger { background: var(--danger); color: white; padding: 6px 12px; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); padding: 6px 12px; }
.btn-outline:hover { border-color: var(--text-muted); background: #f8fafc; }
.btn-danger-outline { color: var(--danger); border-color: #fca5a5; }
.btn-danger-outline:hover { background: #fee2e2; border-color: var(--danger); }

/* App Shell */
.shell { max-width: 1400px; margin: 0 auto; padding: 24px; }
.app-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 20px; font-weight: 600; margin: 0; }
.version-badge { background: var(--border); padding: 2px 8px; border-radius: 12px; font-size: 12px; color: var(--text-muted); }
.header-right { display: flex; gap: 8px; }

.security-banner { background: #fffbeb; border: 1px solid #fcd34d; color: #b45309; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 24px; font-weight: 500; font-size: 13px; }
.modal-shell { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(15, 23, 42, 0.32); z-index: 80; padding: 16px; }
.modal-card { width: min(100%, 420px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18); }
.modal-header { padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; margin: 0; }
.modal-body { padding: 16px 18px; }
.modal-actions { padding: 0 18px 18px; display: flex; justify-content: flex-end; gap: 10px; }

.dashboard-grid { display: flex; flex-direction: column; gap: 20px; }

/* Panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.panel-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: #f8fafc; }
.panel-header h3 { font-size: 14px; font-weight: 600; margin: 0; color: var(--text-main); }

/* Server SSH */
.ssh-summary-wrap { padding: 12px 16px 8px; }
.compact-stats { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 14px; width: 100%; overflow-x: auto; }
.compact-stats-merged { min-width: 0; }
.stat-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-item span { font-size: 12px; color: var(--text-muted); }
.stat-item strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-actions { display: grid; grid-template-columns: repeat(6, minmax(96px, 1fr)); gap: 8px; padding: 0 16px 16px; }
.server-actions button { width: 100%; min-height: 34px; }
.openclash-api-summary { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: #fafcff; min-height: 320px; }
.openclash-api-summary-side { align-self: stretch; }
.api-summary-row { display: grid; grid-template-columns: 1fr; gap: 14px; align-items: start; }
.api-summary-block { display: grid; gap: 6px; min-width: 0; }
.api-label { color: var(--text-muted); font-size: 12px; }
.api-summary-block strong { font-size: 14px; line-height: 1.4; word-break: break-word; }
.api-chip-row { display: flex; flex-wrap: wrap; gap: 6px; max-height: 116px; overflow-y: auto; }
.api-summary-meta { display: flex; gap: 12px; flex-wrap: wrap; color: var(--text-muted); font-size: 12px; }
.api-chip { display: inline-flex; align-items: center; min-height: 24px; max-width: 100%; padding: 2px 8px; border-radius: 999px; background: #e0f2fe; color: #075985; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted-chip { background: #f1f5f9; color: var(--text-muted); }
.security-log-list { display: grid; gap: 8px; padding: 12px 16px; max-height: 420px; overflow-y: auto; }
.security-log-item { display: grid; grid-template-columns: 172px 132px 1fr; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 12px; }
.security-log-item:last-child { border-bottom: none; }
.security-log-item strong { color: var(--text-main); font-weight: 600; white-space: nowrap; }
.security-log-item span { color: var(--text-muted); word-break: break-all; }
.empty-log { color: var(--text-muted); font-size: 12px; padding: 4px 0; }

/* Table */
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { padding: 10px 16px; font-size: 12px; font-weight: 500; color: var(--text-muted); border-bottom: 1px solid var(--border); background: #f8fafc; white-space: nowrap; }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr { cursor: pointer; transition: background 0.1s; }
.data-table tr:hover { background: #f1f5f9; }
.data-table tr.selected { background: #e0f2fe; }

.status-badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--border); color: var(--text-muted); }
.status-online { background: #dcfce7; color: #065f46; }
.status-offline { background: #fee2e2; color: #991b1b; }

/* Bottom Section */
.bottom-section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }

/* Main Config Area */
.config-form { padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 420px; }
.config-layout { display: grid; grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.6fr); gap: 16px; align-items: stretch; flex: 1; min-height: 0; }
.config-side-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; min-width: 0; min-height: 0; }
.config-editor-panel { display: grid; gap: 12px; min-width: 0; min-height: 0; }
.form-row { display: flex; gap: 12px; }
.form-row input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; outline: none; transition: border-color 0.2s; }
.form-row input:focus { border-color: var(--primary); }
.form-row input[readonly] { background: #f8fafc; color: var(--text-muted); cursor: not-allowed; }
.yaml-editor-wrap { display: grid; grid-template-columns: 48px minmax(0, 1fr); min-height: 320px; height: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.yaml-line-numbers { height: 100%; padding: 12px 8px; background: #f8fafc; color: var(--text-muted); border-right: 1px solid var(--border); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 13px; line-height: 1.5; text-align: right; overflow: hidden; user-select: none; }
#yaml-editor { width: 100%; height: 100%; min-height: 320px; padding: 12px; border: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 13px; line-height: 1.5; resize: vertical; outline: none; transition: border-color 0.2s; }
.yaml-editor-wrap:focus-within { border-color: var(--primary); }
.form-actions { display: flex; align-items: center; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.console-output { background: #0f172a; color: #e2e8f0; padding: 16px; margin: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; height: 240px; overflow-y: auto; white-space: pre-wrap; line-height: 1.4; border-top: 1px solid #1e293b; }

@media (max-width: 900px) {
  .server-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .config-layout { grid-template-columns: 1fr; }
  .config-form { min-height: 0; }
  .yaml-editor-wrap,
  #yaml-editor { height: auto; min-height: 320px; }
  .shell { padding: 16px; }
  .form-row { flex-direction: column; }
}
