:root {
  --bg: #090d0b;
  --panel: rgba(18, 24, 21, .92);
  --panel-2: rgba(23, 31, 27, .86);
  --panel-3: #1d2722;
  --line: rgba(255,255,255,.08);
  --line-strong: rgba(255,255,255,.14);
  --text: #f4f7f5;
  --muted: #8b9991;
  --muted-2: #66746d;
  --lime: #b8f54a;
  --lime-soft: rgba(184,245,74,.13);
  --cyan: #67e8c5;
  --danger: #ff7a88;
  --shadow: 0 28px 80px rgba(0,0,0,.42);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background:
  radial-gradient(circle at 12% -8%, rgba(105, 231, 190, .08), transparent 34%),
  radial-gradient(circle at 96% 30%, rgba(184, 245, 74, .055), transparent 26%),
  var(--bg); overflow-x: hidden; }
button, input, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.ambient { position: fixed; width: 420px; height: 420px; border-radius: 50%; filter: blur(100px); opacity: .11; pointer-events: none; }
.ambient-one { background: var(--cyan); left: -260px; top: 14%; }
.ambient-two { background: var(--lime); right: -300px; bottom: -100px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px; }
.login-card { width: min(500px, 100%); padding: 48px; border: 1px solid var(--line-strong); border-radius: 28px; background: linear-gradient(145deg, rgba(28,38,33,.96), rgba(13,18,15,.98)); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.login-card::before { content: ""; position: absolute; inset: 0; background: linear-gradient(120deg, transparent 52%, rgba(184,245,74,.05)); pointer-events: none; }
.login-wordmark { color: var(--text); font-size: 22px; font-weight: 850; letter-spacing: -.05em; }
.language-toggle { min-width: 38px; height: 31px; padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: rgba(255,255,255,.035); cursor: pointer; font-size: 10px; font-weight: 800; }
.language-toggle:hover { color: var(--lime); border-color: rgba(184,245,74,.3); background: var(--lime-soft); }
.login-language { position: absolute; top: 24px; right: 24px; z-index: 1; }
.eyebrow { margin: 24px 0 10px; color: var(--lime); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.login-card h1 { margin: 0; font-size: clamp(36px, 7vw, 56px); line-height: .98; letter-spacing: -.055em; }
.login-copy { color: var(--muted); line-height: 1.65; margin: 22px 0 30px; max-width: 420px; }
.login-form { display: grid; gap: 16px; position: relative; }
.login-form label, .field { display: grid; gap: 8px; }
.login-form label > span, .field > span { color: #bdc7c1; font-size: 12px; font-weight: 700; }
input, textarea { width: 100%; color: var(--text); background: rgba(6,10,8,.64); border: 1px solid var(--line-strong); border-radius: 11px; padding: 12px 13px; outline: 0; transition: border .2s, box-shadow .2s, background .2s; }
input:focus, textarea:focus { border-color: rgba(184,245,74,.58); box-shadow: 0 0 0 3px rgba(184,245,74,.09); background: rgba(7,12,9,.9); }
textarea { resize: vertical; }
.form-error { min-height: 18px; color: var(--danger); font-size: 12px; margin: 0; }
.secure-note { margin: 24px 0 0; color: var(--muted-2); font-size: 11px; text-align: center; }
.secure-note span { color: var(--lime); margin-right: 5px; }

.button { border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 750; font-size: 12px; transition: transform .15s, border .15s, background .15s, opacity .15s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.button.primary { color: #12170f; background: var(--lime); box-shadow: 0 8px 22px rgba(184,245,74,.12); }
.button.secondary { background: #25312b; border-color: var(--line-strong); }
.button.ghost { color: #b8c3bd; background: transparent; border-color: var(--line); }
.button.wide { width: 100%; padding: 13px 18px; }
.button.compact { padding: 8px 11px; font-size: 11px; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.035); cursor: pointer; font-size: 17px; }
.icon-button:hover { border-color: var(--line-strong); background: rgba(255,255,255,.07); }
.icon-button.danger:hover { color: var(--danger); border-color: rgba(255,122,136,.35); }

.app-shell { min-height: 100vh; }
.topbar { height: 70px; padding: 0 20px; border-bottom: 1px solid var(--line); background: rgba(9,13,11,.88); backdrop-filter: blur(18px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand > div:last-child { display: grid; }
.brand strong { font-size: 18px; letter-spacing: -.04em; }
.brand span { color: var(--muted); font-size: 10px; }
.topbar-center { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; }
.topbar-center strong { color: var(--text); }
.profile-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.save-state { color: var(--muted-2); font-size: 11px; margin-right: 6px; }
.save-state.dirty { color: #f4cf77; }

.workspace { height: calc(100vh - 70px); display: grid; grid-template-columns: 264px minmax(500px, 1fr) 350px; }
.sidebar, .preview-panel { background: rgba(12,17,14,.72); }
.sidebar { border-right: 1px solid var(--line); padding: 22px 16px 16px; display: flex; flex-direction: column; min-height: 0; }
.sidebar-heading, .preview-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.sidebar-heading .eyebrow, .preview-heading .eyebrow { margin-top: 0; }
.sidebar h2, .preview-panel h2 { margin: 0; font-size: 18px; letter-spacing: -.025em; }
.count-pill { min-width: 25px; height: 25px; display: grid; place-items: center; border-radius: 999px; background: var(--lime-soft); color: var(--lime); font-size: 10px; font-weight: 800; }
.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 20px 0 14px; }
.host-tree { overflow-y: auto; padding-right: 3px; flex: 1; }
.tree-empty { color: var(--muted-2); text-align: center; padding: 46px 18px; }
.tree-empty > span { display: block; font-size: 32px; color: rgba(184,245,74,.45); margin-bottom: 10px; }
.tree-empty strong { color: var(--muted); font-size: 12px; }
.tree-empty p { font-size: 11px; line-height: 1.5; }
.tree-node { margin: 2px 0; }
.tree-item { width: 100%; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 10px; padding: 8px 9px; color: #aab6af; background: transparent; cursor: pointer; text-align: left; }
.tree-item:hover { background: rgba(255,255,255,.035); }
.tree-item.selected { color: var(--text); background: var(--lime-soft); border-color: rgba(184,245,74,.17); }
.tree-icon { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 7px; background: rgba(255,255,255,.055); color: var(--muted); font-size: 11px; }
.tree-item.selected .tree-icon { background: rgba(184,245,74,.15); color: var(--lime); }
.tree-copy { overflow: hidden; }
.tree-copy strong, .tree-copy span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tree-copy strong { font-size: 11px; }
.tree-copy span { color: var(--muted-2); font-size: 9px; margin-top: 2px; }
.tree-alias { color: var(--lime); font-size: 9px; }
.tree-children { margin-left: 14px; padding-left: 8px; border-left: 1px solid var(--line); }
.sidebar-lower { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.sidebar-link { display: grid; grid-template-columns: 22px 1fr auto; gap: 7px; align-items: center; padding: 9px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; text-align: left; font-size: 11px; }
.sidebar-link:hover { color: var(--text); background: rgba(255,255,255,.035); }
.sidebar-link strong { color: var(--muted-2); font-size: 10px; }

.editor-panel { overflow-y: auto; padding: 34px clamp(24px, 4vw, 58px) 80px; }
.empty-editor { min-height: 75%; display: grid; justify-items: center; align-content: center; text-align: center; }
.empty-orbit { width: 76px; height: 76px; display: grid; place-items: center; border: 1px solid rgba(184,245,74,.18); border-radius: 50%; box-shadow: 0 0 0 16px rgba(184,245,74,.025), 0 0 0 32px rgba(184,245,74,.015); color: var(--lime); font-size: 30px; }
.empty-editor h2 { font-size: 30px; margin: 0; letter-spacing: -.045em; }
.empty-editor > p:not(.eyebrow) { color: var(--muted); max-width: 380px; line-height: 1.6; margin: 10px 0 22px; }
.editor-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 28px; }
.breadcrumb { display: flex; gap: 8px; color: var(--muted-2); font-size: 10px; margin-bottom: 8px; }
.breadcrumb b { color: #3e4a44; }
.editor-heading h1 { font-size: 31px; letter-spacing: -.045em; margin: 0; }
.editor-heading p { color: var(--muted); margin: 7px 0 0; font-size: 12px; }
.node-actions { display: flex; gap: 5px; }
.editor-form { display: grid; gap: 14px; }
.form-section { border: 1px solid var(--line); background: var(--panel); border-radius: 16px; padding: 21px; box-shadow: 0 12px 30px rgba(0,0,0,.08); }
.section-title { display: grid; grid-template-columns: 29px 1fr auto; gap: 11px; align-items: start; margin-bottom: 18px; }
.section-title > span { width: 27px; height: 27px; border: 1px solid var(--line-strong); border-radius: 8px; display: grid; place-items: center; color: var(--lime); font-size: 9px; font-weight: 800; }
.section-title h3 { font-size: 14px; margin: 0 0 3px; }
.section-title p { color: var(--muted-2); font-size: 10px; margin: 0; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.field.span-2 { grid-column: span 2; }
.field b { color: var(--lime); }
.field small { color: var(--muted-2); font-size: 9px; }
code { color: var(--lime); font-family: "SFMono-Regular", Consolas, monospace; }
.secret-field > div { display: flex; position: relative; }
.secret-field input { padding-right: 55px; }
.secret-field button { position: absolute; right: 7px; top: 7px; border: 0; border-radius: 7px; padding: 5px 7px; color: var(--muted); background: rgba(255,255,255,.06); cursor: pointer; font-size: 9px; }
.nested-list { display: grid; gap: 9px; }
.nested-empty { color: var(--muted-2); border: 1px dashed var(--line-strong); border-radius: 11px; padding: 16px; text-align: center; font-size: 10px; }
.nested-card { border: 1px solid var(--line); border-radius: 11px; background: rgba(7,11,9,.42); padding: 13px; }
.nested-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: var(--muted); font-size: 10px; font-weight: 750; }
.nested-card-head button { color: var(--danger); border: 0; background: transparent; cursor: pointer; }
.nested-fields { display: grid; grid-template-columns: 1.2fr 1fr 80px; gap: 8px; }
.nested-fields.callback { grid-template-columns: 1fr 110px; }
.nested-fields input { padding: 9px 10px; font-size: 11px; }
.group-actions { display: flex; gap: 8px; }

.preview-panel { border-left: 1px solid var(--line); padding: 23px 18px; overflow-y: auto; }
.validation-badge { padding: 5px 8px; border-radius: 999px; font-size: 9px; font-weight: 800; }
.validation-badge.valid { color: var(--lime); background: var(--lime-soft); }
.validation-badge.invalid { color: var(--danger); background: rgba(255,122,136,.11); }
.validation-badge.waiting { color: var(--muted); background: rgba(255,255,255,.05); }
.preview-actions { display: flex; align-items: center; gap: 7px; }
.preview-secret-toggle { padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: transparent; cursor: pointer; font-size: 9px; font-weight: 750; }
.preview-secret-toggle:hover { color: var(--lime); border-color: rgba(184,245,74,.28); background: var(--lime-soft); }
#yamlPreview { margin: 18px 0 0; min-height: 430px; max-height: calc(100vh - 310px); overflow: auto; border: 1px solid var(--line); border-radius: 13px; background: #070b09; padding: 16px; color: #b9c7bf; font: 10.5px/1.65 "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.validation-message { min-height: 36px; padding: 10px 2px; color: var(--muted-2); font-size: 10px; line-height: 1.5; }
.validation-message.error { color: var(--danger); }
.preview-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); padding-top: 14px; }
.preview-stats div { display: grid; text-align: center; gap: 3px; border-right: 1px solid var(--line); }
.preview-stats div:last-child { border: 0; }
.preview-stats strong { font-size: 16px; }
.preview-stats span { color: var(--muted-2); font-size: 9px; }

.modal { width: min(500px, calc(100% - 30px)); border: 1px solid var(--line-strong); border-radius: 20px; padding: 0; color: var(--text); background: #151d19; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(2,5,3,.76); backdrop-filter: blur(5px); }
.modal > form { padding: 28px; position: relative; }
.modal .eyebrow { margin-top: 0; }
.modal h2 { margin: 0 0 8px; font-size: 25px; letter-spacing: -.04em; }
.modal p { color: var(--muted); font-size: 11px; line-height: 1.6; }
.modal-close { position: absolute; right: 17px; top: 15px; border: 0; color: var(--muted); background: transparent; font-size: 23px; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-field-grid { margin-top: 20px; }
.modal-field-grid + .form-error { margin-top: 10px; }
.wide-modal { width: min(660px, calc(100% - 30px)); }
.import-drop-zone { margin-top: 20px; min-height: 154px; display: grid; place-items: center; align-content: center; gap: 6px; border: 1px dashed var(--line-strong); border-radius: 15px; color: var(--muted); background: rgba(7,11,9,.38); cursor: pointer; text-align: center; transition: border .2s, background .2s; }
.import-drop-zone:hover, .import-drop-zone.dragging { border-color: rgba(184,245,74,.55); background: var(--lime-soft); }
.import-drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.import-drop-zone .import-icon { color: var(--lime); font-size: 28px; line-height: 1; }
.import-drop-zone strong { color: var(--text); font-size: 12px; }
.import-drop-zone small { color: var(--muted-2); font-size: 10px; }
.import-drop-zone code { max-width: calc(100% - 28px); margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.import-mode { display: grid; gap: 8px; margin: 18px 0 0; padding: 0; border: 0; }
.import-mode legend { margin-bottom: 8px; color: #bdc7c1; font-size: 11px; font-weight: 750; }
.import-mode > label { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; cursor: pointer; }
.import-mode > label:has(input:checked) { border-color: rgba(184,245,74,.28); background: var(--lime-soft); }
.import-mode input { width: auto; margin: 2px 0 0; accent-color: var(--lime); }
.import-mode span { display: grid; gap: 3px; }
.import-mode strong { font-size: 11px; }
.import-mode small { color: var(--muted-2); font-size: 9px; line-height: 1.45; }
.create-device { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin: 20px 0 14px; }
.token-reveal { padding: 13px; border: 1px solid rgba(184,245,74,.2); border-radius: 12px; background: var(--lime-soft); display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-bottom: 13px; }
.token-reveal span { grid-column: span 2; color: #c8d3cd; font-size: 10px; }
.token-reveal code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.device-list, .history-list { display: grid; gap: 7px; max-height: 360px; overflow-y: auto; }
.device-item, .history-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: rgba(255,255,255,.025); }
.device-item strong, .history-item strong { display: block; font-size: 11px; }
.device-item span, .history-item span { color: var(--muted-2); font-size: 9px; }
.device-item.revoked { opacity: .5; }
.device-item button { border: 0; background: transparent; color: var(--danger); font-size: 10px; cursor: pointer; }
.history-version { color: var(--lime); font: 800 11px "SFMono-Regular", Consolas, monospace; }
.history-actions { display: flex; align-items: center; gap: 10px; }
.history-actions button { border: 0; padding: 5px 7px; border-radius: 7px; color: var(--muted); background: rgba(255,255,255,.05); cursor: pointer; font-size: 9px; }
.history-actions button:hover { color: var(--lime); background: var(--lime-soft); }
.list-empty { padding: 30px; text-align: center; color: var(--muted-2); font-size: 11px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: 360px; padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 11px; color: var(--text); background: #202a25; box-shadow: var(--shadow); font-size: 11px; transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: rgba(255,122,136,.35); color: #ffd3d8; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 240px 1fr; }
  .preview-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  #yamlPreview { min-height: 260px; max-height: 420px; }
  .workspace { height: auto; min-height: calc(100vh - 70px); }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; }
  .topbar-center, .save-state { display: none; }
  .workspace { display: block; }
  .sidebar { min-height: 360px; border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-panel { padding: 28px 18px 60px; }
  .field-grid, .nested-fields, .nested-fields.callback { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .preview-panel { padding-bottom: 50px; }
  .topbar-actions .button.secondary { display: none; }
}
