:root {
  --bg: #F6F5F1;
  --ink: #16181D;
  --ink-2: #3A3E47;
  --muted: #5B5F68;
  --line: #E2DFD6;
  --line-2: #EFEDE6;
  --border: #D6D2C6;
  --input: #C9C4B6;
  --surface: #FFFFFF;
  --head: #FBFAF7;
  --dark: #16181D;
  --dark-2: #2A2D35;
  --dark-text: #B8BCC6;
  --accent: #0F766E;
  --accent-hover: #115E59;
  --accent-soft: #0F766E1A;
  --accent-ink: #0B4F4A;
  --folder: #B45309;
  --danger: #9A3412;
  --warn-bg: #FDF6EA;
  --warn-line: #E8C48F;
  --warn-ink: #7C3A06;
  --sans: 'IBM Plex Sans Thai', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--sans); background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.grow { flex-grow: 1; }
.icon { display: inline-flex; }
.icon svg { width: 16px; height: 16px; }

#app { height: 100%; display: flex; flex-direction: column; }
#page { flex-grow: 1; display: flex; min-height: 0; }

/* header */
.top { height: 60px; flex-shrink: 0; padding: 0 24px; display: flex; align-items: center; gap: 24px; background: var(--dark); color: var(--bg); }
.logo { font-size: 17px; font-weight: 600; display: flex; gap: 10px; }
.logo .dollar { color: #5EEAD4; }
.top nav { display: flex; gap: 4px; margin-left: 24px; }
.top nav a { padding: 8px 14px; border-radius: 6px; color: var(--dark-text); text-decoration: none; }
.top nav a[aria-current] { background: var(--dark-2); color: var(--bg); }
.top nav a:hover { color: var(--bg); }
.search { display: flex; align-items: center; gap: 8px; width: 320px; height: 36px; padding: 0 12px; border-radius: 6px; background: var(--dark-2); color: var(--dark-text); }
.search input { flex-grow: 1; min-width: 0; border: 0; background: transparent; color: var(--bg); outline: none; }
.avatar { width: 32px; height: 32px; border-radius: 16px; border: 0; background: var(--accent); color: var(--bg); font-size: 13px; font-weight: 600; }

/* buttons & inputs */
.btn { height: 40px; padding: 0 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); display: inline-flex; align-items: center; gap: 8px; font-weight: 500; text-decoration: none; color: var(--ink); }
.btn.primary { border: 0; background: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.lg { height: 44px; }
.icon-btn { width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.solid { background: var(--accent); color: #fff; }
.icon-btn.outline { border: 1px solid var(--input); background: var(--surface); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.field input, .field select { height: 44px; padding: 0 12px; border: 1px solid var(--input); border-radius: 8px; background: var(--surface); }
.field .hint { font-size: 12px; font-weight: 400; color: var(--muted); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* collections */
.aside { width: 280px; flex-shrink: 0; padding: 20px 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.aside-head { display: flex; align-items: center; justify-content: space-between; }
.label { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); }
.small-add { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.tree { display: flex; flex-direction: column; gap: 2px; }
.node { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; border-radius: 6px; background: transparent; text-align: left; color: var(--ink-2); }
.node:hover { background: var(--line-2); }
.node.parent { font-weight: 600; color: var(--ink); }
.node.leaf { font-family: var(--mono); font-size: 13px; }
.node.sel { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.node .chev { width: 16px; height: 16px; display: inline-flex; color: var(--muted); }
.node .folder-icon { color: var(--folder); }
.new-folder { height: 44px; border: 1px dashed #B9B4A6; border-radius: 8px; background: transparent; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--ink-2); }

.main { flex-grow: 1; min-width: 0; padding: 28px 36px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs b { color: var(--ink); font-weight: 400; }
h1 { margin: 0; font-size: 28px; font-weight: 600; }
h1.mono { font-size: 30px; letter-spacing: -0.01em; }
.actions { display: flex; gap: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { padding: 10px 16px; border: 0; border-bottom: 2px solid transparent; background: transparent; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }

.table { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.row { display: grid; grid-template-columns: 260px minmax(0, 1fr) minmax(0, 1fr) 150px 112px; gap: 16px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line-2); }
.row.head { padding: 10px 20px; background: var(--head); border-bottom-color: var(--line); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--muted); }
.row.editing { background: var(--accent-soft); }
.row .name { font-family: var(--mono); font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.row .value { font-family: var(--mono); font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.row .updated { font-size: 13px; color: var(--muted); }
.row .btns { display: flex; gap: 4px; justify-content: flex-end; }
.row input { height: 36px; min-width: 0; padding: 0 10px; border: 1px solid var(--input); border-radius: 6px; background: var(--surface); font-size: 13px; }
.row input.mono { font-family: var(--mono); }
.row input:first-child { border-color: var(--accent); font-weight: 600; }
.status { font-size: 13px; color: var(--accent-ink); font-weight: 500; }
.table-foot { padding: 12px 20px; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* dialogs */
dialog { width: 520px; max-width: calc(100vw - 32px); padding: 28px; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); }
dialog.wide { width: 860px; margin-top: 5vh; } /* top-anchored: preview height changes must not move the inputs */
dialog::backdrop { background: rgba(22, 24, 29, 0.72); }
dialog form, .dialog-body { display: flex; flex-direction: column; gap: 20px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 20px; font-weight: 600; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; }
.chips { display: flex; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 999px; background: #E6F2F0; color: var(--accent-ink); font-family: var(--mono); font-size: 13px; }
fieldset { margin: 0; padding: 0; border: 0; }
legend { font-weight: 500; margin-bottom: 8px; padding: 0; }
.formats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.k8s-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.k8s-fields[hidden] { display: none; }
.format { padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.format:has(input:checked) { border: 2px solid var(--accent); background: var(--accent-soft); padding: 13px 15px; }
.format input { margin-top: 4px; accent-color: var(--accent); }
.format div { display: flex; flex-direction: column; gap: 4px; }
.format .fmt-name { font-family: var(--mono); font-size: 15px; font-weight: 600; }
.format .fmt-example { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.format .fmt-note { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.check input { accent-color: var(--accent); }
pre.code { margin: 0; padding: 16px 18px; border-radius: 10px; background: var(--dark); color: #E8E6E0; font-family: var(--mono); font-size: 13px; line-height: 1.75; white-space: pre; overflow: auto; max-height: 320px; }
pre.code .c { color: #8A8F9B; }
pre.preview { min-height: 240px; }
pre.code .k { color: #5EEAD4; }
pre.code .s { color: #FCD34D; }
pre.light { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
pre.light .c { color: var(--muted); }

/* api users */
.split { flex-grow: 1; padding: 32px 40px; display: flex; gap: 32px; min-height: 0; overflow-y: auto; }
.split > .main { padding: 0; overflow: visible; }
.side { width: 440px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; }
.card { padding: 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); display: flex; flex-direction: column; gap: 16px; }
.card h2 { margin: 0; font-size: 18px; font-weight: 600; }
.env-checks { display: flex; gap: 16px; }
.users .row { grid-template-columns: 1.1fr 1.3fr 1.4fr 110px 110px 48px; padding: 14px 20px; }
.row .sub { display: block; font-size: 12px; color: var(--muted); font-family: var(--sans); font-weight: 400; }
.users .row .scope { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.secret { padding: 20px 24px; border: 1px solid var(--warn-line); border-radius: 12px; background: var(--warn-bg); display: flex; flex-direction: column; gap: 12px; }
.secret-head { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--warn-ink); }
.secret-field { display: flex; flex-direction: column; gap: 4px; }
.secret-field > div { display: flex; align-items: center; gap: 8px; }
.secret code { flex-grow: 1; padding: 10px 12px; border-radius: 6px; background: var(--surface); border: 1px solid #E8DCC6; font-family: var(--mono); font-size: 13px; word-break: break-all; }
.secret .icon-btn { width: 40px; height: 40px; border: 1px solid #E8DCC6; background: var(--surface); color: var(--ink); }

/* users & audit */
.members .row { grid-template-columns: 180px 100px minmax(0, 1fr) 150px 112px; }
.audit .row { grid-template-columns: 170px 160px 200px minmax(0, 1fr); }
.role { padding: 2px 10px; border-radius: 999px; font-family: var(--mono); font-size: 12px; background: var(--line-2); color: var(--ink-2); }
.role.admin { background: #E6F2F0; color: var(--accent-ink); }
.badge { margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--line-2); color: var(--muted); font-family: var(--sans); font-size: 11px; font-weight: 500; }
.grants-box { display: flex; flex-direction: column; gap: 10px; }
.grants-box[hidden] { display: none; }
.grants-box .btn { align-self: flex-start; }
.grants { display: flex; flex-direction: column; gap: 8px; }
.grant { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.grant select { height: 36px; padding: 0 8px; border: 1px solid var(--input); border-radius: 6px; background: var(--surface); }
.grant .env-checks { gap: 12px; flex-wrap: wrap; }
.grant .icon-btn { justify-self: end; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* api docs */
.docs { flex-grow: 1; padding: 32px 40px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; overflow-y: auto; align-content: start; }
.docs section { display: flex; flex-direction: column; gap: 20px; }
.docs h2 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.docs p { margin: 6px 0 0; line-height: 1.6; color: var(--muted); }
.endpoint { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.method { padding: 4px 10px; border-radius: 6px; background: var(--accent); color: #fff; font-family: var(--mono); font-size: 12px; font-weight: 600; }
.params { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.params > div { display: grid; grid-template-columns: 160px 1fr; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); color: var(--ink-2); }
.params > div:last-child { border-bottom: 0; }
.params code { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--ink); }
.status-list { display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.status-list code { font-family: var(--mono); font-weight: 600; color: var(--danger); margin-right: 8px; }
.status-list code.ok { color: var(--accent-ink); }

/* login */
.login { flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 380px; max-width: 100%; padding: 28px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 16px; }
.login .logo { color: var(--ink); }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; background: var(--dark); color: var(--bg); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.show { opacity: 1; }

@media (max-width: 900px) {
  .top { height: auto; min-height: 56px; flex-wrap: wrap; padding: 8px 16px; gap: 8px 12px; }
  .top nav { margin-left: 0; order: 3; width: 100%; }
  .top nav a { padding: 6px 10px; }
  .title-row { flex-wrap: wrap; align-items: flex-start; }
  h1.mono { font-size: 24px; overflow-wrap: anywhere; }
  .search { display: none; }
  #page { flex-direction: column; }
  .aside { width: auto; border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .main { padding: 20px 16px; }
  .row { grid-template-columns: 1fr; gap: 6px; }
  .row.head { display: none; }
  .row .btns { justify-content: flex-start; }
  .split { flex-direction: column; padding: 20px 16px; }
  .side { width: auto; }
  .users .row, .members .row, .audit .row { grid-template-columns: 1fr; }
  .docs { grid-template-columns: 1fr; padding: 20px 16px; }
  .formats, .k8s-fields { grid-template-columns: 1fr; }
}
