:root {
  color-scheme: dark;
  --bg: #0d1118;
  --sidebar: #151b25;
  --surface: #171e29;
  --surface-raised: #202a38;
  --line: #2c3848;
  --line-strong: #3a4b60;
  --text: #eef3f8;
  --muted: #94a2b4;
  --accent: #67b7ff;
  --accent-strong: #3c8ee5;
  --green: #45d59b;
  --yellow: #f2c66d;
  --danger: #f17d86;
  --shadow: 0 16px 36px rgba(0, 0, 0, .22);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar { padding: 28px 18px 20px; background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 36px; }
.brand-mark { width: 34px; height: 34px; border: 1px solid #4d9fe0; color: var(--accent); display: grid; place-items: center; font-weight: 800; letter-spacing: 0; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; letter-spacing: .02em; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.nav-list { display: grid; gap: 6px; }
.nav-item { color: var(--muted); display: flex; gap: 10px; align-items: center; padding: 10px 12px; text-decoration: none; border-left: 2px solid transparent; }
.nav-item:hover, .nav-item.active { color: var(--text); background: rgba(103, 183, 255, .1); border-left-color: var(--accent); }
.nav-icon { width: 18px; color: var(--accent); text-align: center; font-size: 18px; }
.sidebar-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; padding: 12px 10px 0; border-top: 1px solid var(--line); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(69, 213, 155, .12); }

.main-content { width: min(1480px, 100%); padding: 34px 42px 60px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; gap: 28px; align-items: flex-start; margin-bottom: 28px; }
.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: .13em; margin: 0 0 6px; font-weight: 700; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 29px; line-height: 1.2; }
h2 { font-size: 18px; }
.muted { color: var(--muted); margin: 8px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; padding-top: 10px; }
.secure-state { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-right: 8px; }

.button { border: 1px solid transparent; border-radius: 6px; color: var(--text); min-height: 38px; padding: 0 14px; transition: border-color .16s, background .16s, transform .16s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button-primary { background: var(--accent-strong); border-color: var(--accent-strong); }
.button-primary:hover:not(:disabled) { background: #4d9dea; }
.button-secondary { background: var(--surface-raised); border-color: var(--line-strong); }
.button-secondary:hover:not(:disabled), .button-ghost:hover:not(:disabled) { border-color: var(--accent); }
.button-ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.button-danger { color: var(--danger); background: transparent; border-color: rgba(241, 125, 134, .35); }
.button-danger:hover:not(:disabled) { background: rgba(241, 125, 134, .1); }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { min-height: 128px; padding: 18px 20px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.metric-primary { border-top: 2px solid var(--accent); }
.metric-label { color: var(--muted); font-size: 13px; }
.metric-value { font-size: 30px; font-weight: 750; line-height: 1.1; margin: 14px 0 15px; }
.metric-value small { font-size: 13px; color: var(--muted); margin-left: 5px; font-weight: 500; }
.metric-footer { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.positive { color: var(--green); }
.warning { color: var(--yellow); }

.workspace-grid { display: grid; grid-template-columns: minmax(330px, .86fr) minmax(460px, 1.4fr); gap: 18px; align-items: start; }
.panel { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.library-panel, .editor-panel { padding: 22px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.result-count, .badge { color: var(--muted); font-size: 12px; border: 1px solid var(--line); padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.badge { color: var(--green); border-color: rgba(69, 213, 155, .35); }
.search-box { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0 12px; margin-bottom: 14px; }
.search-box span { color: var(--muted); font-size: 21px; }
.search-box input { width: 100%; height: 40px; color: var(--text); border: 0; outline: 0; background: transparent; }
.yaml-list { display: grid; gap: 8px; max-height: 700px; overflow: auto; padding-right: 2px; }
.yaml-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px 12px; border: 1px solid var(--line); background: var(--bg); padding: 14px; cursor: pointer; transition: border-color .16s, background .16s; }
.yaml-item:hover, .yaml-item.selected { border-color: var(--accent); background: #182635; }
.yaml-item-title { display: flex; gap: 8px; align-items: center; min-width: 0; }
.yaml-item-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.direct-link { margin-left: auto; color: var(--accent); font-size: 12px; white-space: nowrap; text-decoration: none; }
.direct-link:hover { text-decoration: underline; }
.copy-link { color: var(--accent); font-size: 12px; white-space: nowrap; }
.file-name { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { color: var(--green); font-size: 11px; border: 1px solid rgba(69, 213, 155, .32); padding: 2px 6px; border-radius: 999px; white-space: nowrap; }
.status-pill.off { color: var(--muted); border-color: var(--line); }
.yaml-item-meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.usage-mini { height: 5px; flex: 1; background: #2b3441; overflow: hidden; }
.usage-mini span { display: block; height: 100%; background: var(--accent); }
.expiry { white-space: nowrap; }
.expiry.warning { color: var(--yellow); }
.expiry.danger { color: var(--danger); }
.yaml-item-actions { grid-column: 1 / -1; display: flex; gap: 14px; }
.yaml-item-actions .copy-link { min-height: 28px; padding: 0 9px; margin-left: auto; }
.link-button { padding: 0; border: 0; background: transparent; color: var(--accent); font-size: 12px; }
.link-button:hover { text-decoration: underline; }

.form-stack { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, textarea { color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 10px 11px; outline: 0; }
input { height: 42px; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 360px; resize: vertical; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.form-row-bottom { align-items: end; }
.switch-label { display: flex; align-items: center; gap: 10px; min-height: 42px; }
.switch-label > span:first-child { margin-right: auto; }
.switch-label em { color: var(--green); font-style: normal; font-size: 12px; }
.switch { position: relative; width: 42px; height: 24px; display: inline-block; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { display: block; width: 42px; height: 24px; border-radius: 20px; background: #303b49; transition: background .16s; }
.switch i::after { content: ''; display: block; width: 18px; height: 18px; margin: 3px; border-radius: 50%; background: #dce7f1; transition: transform .16s; }
.switch input:checked + i { background: var(--accent-strong); }
.switch input:checked + i::after { transform: translateX(18px); }
.quick-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 11px 0 2px; border-top: 1px solid var(--line); }
.quick-actions > span { color: var(--muted); font-size: 12px; margin-right: 3px; }
.quick-actions .button { min-height: 30px; padding: 0 9px; font-size: 12px; }
.yaml-label textarea { min-height: 370px; }
.editor-footer { position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; gap: 9px; border-top: 1px solid var(--line); padding: 15px 0 2px; background: var(--surface); }
.editor-hint { flex: 1; color: var(--muted); font-size: 12px; }
.subscription-link { color: var(--accent); font-size: 12px; white-space: nowrap; }
.empty-state { min-height: 220px; display: grid; place-items: center; align-content: center; gap: 7px; color: var(--muted); text-align: center; }
.empty-state[hidden] { display: none; }
.empty-state strong { color: var(--text); }
.empty-icon { color: var(--accent); font-size: 30px; line-height: 1; }
.empty-state .button { margin-top: 8px; }
.toast { position: fixed; right: 24px; bottom: 24px; padding: 11px 15px; color: var(--text); background: var(--surface-raised); border: 1px solid var(--accent); border-radius: 6px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-color: var(--danger); }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { padding: 14px 18px; display: flex; flex-direction: row; align-items: center; gap: 18px; }
  .brand { padding: 0; }
  .nav-list { display: flex; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main-content { padding: 28px 24px 48px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .yaml-list { max-height: 360px; }
}

@media (max-width: 700px) {
  .main-content { padding: 22px 14px 40px; }
  .topbar { display: grid; gap: 14px; }
  .topbar-actions { padding: 0; flex-wrap: wrap; }
  .secure-state { width: 100%; margin: 0; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 112px; padding: 15px; }
  .metric-value { font-size: 25px; margin: 11px 0; }
  .form-row { grid-template-columns: 1fr; }
  .library-panel, .editor-panel { padding: 16px; }
  .editor-footer { flex-wrap: wrap; }
  .editor-hint { flex-basis: 100%; order: -1; }
  .sidebar { overflow: auto; }
  .brand span { display: none; }
}
