/* PRISMBLEED web panel. Dark theme from the design: ink background, mint accent. Phone first. */

:root {
  --bg: #0D1117;
  --surface: #151B23;
  --surface-2: #1B222C;
  --line: #2A3340;
  --line-soft: #222B36;
  --text: #E6EDF3;
  --muted: #9AA7B5;
  --dim: #7D8A99;
  --accent: #3DDBB6;
  --accent-ink: #06201A;
  --accent-bg: #16282A;
  --accent-line: #2B5B52;
  --warn: #F0B35A;
  --warn-bg: #2A1F12;
  --danger: #FF9B94;
  --danger-line: #6E3A3A;
  --danger-solid: #B3342C;
  --danger-bg: #2A1616;
  --radius: 14px;
  --radius-sm: 10px;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --tabs-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
a { color: var(--accent); }
a:hover { color: #8CF0D9; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 6px; padding: 1px 6px; word-break: break-all; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 30px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 14px; }
.tiny { font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.sm { width: 16px; height: 16px; }

/* ---------- shell */

.app { min-height: 100vh; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: rgba(13, 17, 23, 0.94); border-bottom: 1px solid var(--line-soft); }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; min-width: 0; }
.brand:hover { color: var(--text); }
.logo { width: 38px; height: 38px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 500 14px var(--mono); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text b { font-size: 17px; font-weight: 600; }
.brand-text small { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 6px; }
.tab { min-height: 44px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line); color: var(--text); display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 500; font-size: 15px; white-space: nowrap; }
.tab:hover { color: var(--text); border-color: var(--accent-line); }
.tab[aria-current="page"] { background: var(--surface-2); border-color: var(--accent); }
.tab .i { width: 18px; height: 18px; }
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 28px 20px 56px; outline: none; }
.offline { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #5A4220; padding: 8px 20px; text-align: center; font-size: 14px; }

@media (max-width: 820px) {
  .top-inner { padding: 10px 14px; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 4px; }
  .tab { flex: 1; flex-direction: column; justify-content: center; gap: 2px; min-height: 52px; padding: 4px 2px; border: none; font-size: 12px; border-radius: 8px; }
  .tab[aria-current="page"] { background: var(--accent-bg); color: var(--accent); }
  .tab .i { width: 22px; height: 22px; }
  main { padding: 18px 14px calc(var(--tabs-h) + 48px + env(safe-area-inset-bottom)); }
  h1 { font-size: 25px; }
}

/* ---------- layout */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head > div:first-child { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.layout-2 { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.col-side { flex: 1 1 330px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

/* ---------- cards */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card.accent { border-color: var(--accent); }
.card.danger { border-color: var(--danger-line); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.card-head .title { display: flex; align-items: center; gap: 10px; }
.card-head .title .i { color: var(--accent); }
.subcard { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.subcard.danger { border-color: var(--danger-line); }
.divider { border: none; border-top: 1px solid var(--line-soft); margin: 2px 0; }
@media (max-width: 520px) { .card { padding: 16px; } }

/* ---------- buttons */

.btn { min-height: 46px; padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--accent-line); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: #5BE3C3; }
.btn.danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #fff; font-weight: 600; }
.btn.danger-ghost { color: var(--danger); border-color: var(--danger-line); }
.btn.block { width: 100%; }
.btn.big { min-height: 52px; font-size: 16px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-color: var(--muted) var(--muted) var(--muted) transparent; animation: spin 0.8s linear infinite; }
.icon-btn { width: 44px; height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: transparent; display: grid; place-items: center; cursor: pointer; flex: none; }
.link-btn { background: none; border: none; color: var(--accent); padding: 0 4px; min-height: 44px; font-size: 14px; font-weight: 500; cursor: pointer; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- chips, status */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; text-decoration: none; }
.chip:hover { color: var(--text); border-color: var(--accent-line); }
.chip[aria-pressed="true"], .chip[aria-current="page"] { border-color: var(--accent); background: var(--accent-bg); }
.chip .dot { width: 8px; height: 8px; }
.status { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); flex: none; }
.s-running { color: var(--accent); } .s-running .dot, .dot.s-running { background: var(--accent); }
.s-starting, .s-stopping, .s-waiting { color: var(--warn); } .s-starting .dot, .s-stopping .dot, .s-waiting .dot, .dot.s-starting, .dot.s-stopping, .dot.s-waiting { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.s-crashed { color: var(--danger); } .s-crashed .dot, .dot.s-crashed { background: var(--danger); }
.s-stopped { color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.35; } }
.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 500; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--accent); border-color: var(--accent-line); }
.badge.warn { color: var(--warn); border-color: #5A4220; }
.badge.bad { color: var(--danger); border-color: var(--danger-line); }

/* ---------- notes */

.note { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; line-height: 1.6; border: 1px solid var(--line); background: var(--surface-2); display: flex; gap: 10px; align-items: flex-start; }
.note .i { margin-top: 2px; }
.note > div { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.note.warn { background: var(--warn-bg); border-color: #5A4220; color: #F6CF94; }
.note.warn .i { color: var(--warn); }
.note.danger { background: var(--danger-bg); border-color: var(--danger-line); color: #FFC4BF; }
.note.danger .i { color: var(--danger); }
.note.ok { background: var(--accent-bg); border-color: var(--accent-line); color: #BDF5E6; }
.note.ok .i { color: var(--accent); }
.note pre { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font: 12px/1.5 var(--mono); color: var(--muted); }

/* ---------- key/value */

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 20px; margin: 0; }
.kv > div { display: flex; flex-direction: column; min-width: 0; }
.kv dt { font-size: 13px; color: var(--muted); }
.kv dd { margin: 0; font: 500 14px/1.5 var(--mono); word-break: break-word; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric b { font-size: 26px; font-weight: 700; line-height: 1.2; }
.metric span { font-size: 13px; color: var(--muted); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 14px; }

/* ---------- forms */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span:first-child, .field > .label { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
.field input, .field select, .field textarea, .input { min-height: 46px; width: 100%; padding: 0 12px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font-size: 16px; }
.field textarea { padding: 12px; min-height: 120px; resize: vertical; font: 15px/1.6 var(--mono); }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.field input[type="number"] { font-family: var(--mono); }
.field .hint { font-size: 13px; line-height: 1.5; color: var(--dim); }
.field .err { font-size: 13px; line-height: 1.5; color: var(--danger); }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.field input:disabled { opacity: 0.55; }
.ports-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.switch { display: flex; align-items: flex-start; gap: 12px; background: none; border: none; padding: 4px 0; text-align: left; cursor: pointer; min-height: 44px; width: 100%; }
.switch .track { width: 44px; height: 26px; border-radius: 999px; background: var(--line); flex: none; position: relative; margin-top: 1px; transition: background 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: transform 0.15s; }
.switch[aria-checked="true"] .track { background: var(--accent); }
.switch[aria-checked="true"] .track::after { transform: translateX(18px); background: var(--accent-ink); }
.switch .text { display: flex; flex-direction: column; gap: 2px; }
.switch .text b { font-size: 15px; font-weight: 500; }
.switch .text small { font-size: 13px; color: var(--muted); line-height: 1.5; }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- code, logs, tables */

.code { margin: 0; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; font: 13px/1.6 var(--mono); color: var(--text); white-space: pre-wrap; word-break: break-word; }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row .code { flex: 1; min-width: 0; }
.log { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font: 12.5px/1.6 var(--mono); height: 460px; overflow: auto; overscroll-behavior: contain; }
.log .ln { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.log .ln .t { color: var(--dim); flex: none; }
.log .ln .lv { flex: none; width: 46px; font-weight: 500; color: var(--muted); }
.log .ln .m { min-width: 0; flex: 1; }
.log .lv-warn .lv, .log .lv-warn .m { color: var(--warn); }
.log .lv-error .lv, .log .lv-error .m { color: var(--danger); }
.log .lv-hack .lv, .log .lv-hack .m { color: #E7A6FF; }
.log .lv-debug .m { color: var(--muted); }
.log .lv-panel { color: var(--accent); margin: 4px 0; }
.log .lv-packet { color: #7FB9D9; }
.log .empty { color: var(--muted); }
.log.short { height: 260px; }
@media (max-width: 520px) { .log { height: 380px; font-size: 12px; } .log .ln .lv { width: 40px; } }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 460px; }
table { border-collapse: collapse; width: 100%; font: 13px/1.5 var(--mono); }
th { text-align: left; padding: 10px 12px; color: var(--muted); font-weight: 500; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
td { padding: 9px 12px; border-top: 1px solid var(--line-soft); white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.list-item:first-child { border-top: none; padding-top: 0; }
.list-item .grow { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; }
.list-item .name { font: 500 14px var(--mono); word-break: break-all; }

/* ---------- servers */

.srv-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px; }
.srv-head h2 { font-size: 21px; }
.services { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.service { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.service b { font-size: 15px; font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; }
.service span { font: 13px var(--mono); color: var(--muted); }

/* ---------- setup steps */

.steps-list { display: flex; flex-direction: column; gap: 14px; }
.setup-step, .card.setup-step { display: flex; flex-direction: row; gap: 16px; align-items: flex-start; }
.setup-step .num .i { width: 18px; height: 18px; }
.setup-step .num { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font: 500 15px var(--mono); background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.setup-step.ok .num { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.setup-step.todo .num { border-color: var(--warn); color: var(--warn); }
.setup-step .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.sysline { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- job sheet */

.jobpill { position: fixed; right: 16px; bottom: 16px; z-index: 40; min-height: 48px; max-width: calc(100vw - 32px); padding: 0 18px; border-radius: 999px; border: 1px solid var(--warn); background: var(--warn-bg); color: var(--warn); font-weight: 500; display: flex; align-items: center; gap: 10px; cursor: pointer; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }
.jobpill span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jobpill.done { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }
.jobpill.failed { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; flex: none; }
@media (max-width: 820px) { .jobpill { bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom)); right: 12px; } }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 12, 0.72); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.sheet-card, .modal-card { background: var(--surface); border: 1px solid var(--line); width: 100%; max-width: 760px; max-height: 92vh; display: flex; flex-direction: column; gap: 14px; padding: 20px; overflow: auto; }
.sheet-card { border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 821px) { .overlay { align-items: center; padding: 24px; } .sheet-card { border-radius: 18px; } }
.modal-card { border-radius: 18px; max-width: 520px; margin: auto 12px; }
.overlay.center { align-items: center; padding: 16px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.jobsteps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.jobsteps li { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.jobsteps .mark { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--line); flex: none; color: var(--dim); }
.jobsteps .mark .i { width: 14px; height: 14px; }
.jobsteps .done .mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.jobsteps .running { color: var(--warn); }
.jobsteps .running .mark { border-color: var(--warn); }
.jobsteps .failed { color: var(--danger); }
.jobsteps .failed .mark { border-color: var(--danger); color: var(--danger); }
.jobsteps .skipped { color: var(--dim); text-decoration: line-through; }
.joblog { height: 300px; }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s; }

/* ---------- toasts */

.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; font-size: 15px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); display: flex; gap: 10px; align-items: flex-start; }
.toast.ok { border-color: var(--accent-line); } .toast.ok .i { color: var(--accent); }
.toast.bad { border-color: var(--danger-line); } .toast.bad .i { color: var(--danger); }

/* ---------- login */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; display: flex; flex-direction: column; gap: 18px; }
.login-card .error { color: var(--danger); font-size: 14px; min-height: 20px; }
.boot { min-height: 60vh; display: grid; place-items: center; color: var(--muted); }

#inst-chips { margin: -6px 0 20px; }
.modal-card.wide { max-width: 760px; }
.modal-card ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

details.adv { border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
details.adv > summary { min-height: 46px; display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--muted); list-style: none; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform 0.15s; margin-right: 4px; }
details.adv[open] > summary::before { transform: rotate(45deg); }
details.adv[open] { padding-bottom: 14px; }
.settings-one { max-width: 860px; }
#settings-body > .chips { margin-bottom: 4px; }
@media (max-width: 520px) {
  .log .ln .lv { display: none; }
  .log .ln { gap: 8px; }
  .log .lv-warn, .log .lv-error, .log .lv-hack { padding-left: 6px; }
  .log .lv-warn { box-shadow: inset 2px 0 var(--warn); }
  .log .lv-error { box-shadow: inset 2px 0 var(--danger); }
  .log .lv-hack { box-shadow: inset 2px 0 #E7A6FF; }
}
body.has-job main { padding-bottom: 120px; }
@media (max-width: 820px) { body.has-job main { padding-bottom: calc(var(--tabs-h) + 110px + env(safe-area-inset-bottom)); } }
