/* Nomat Host panel. Palette from SPEC.md; layout is the new one.
   Works from 360 px wide; the page itself never scrolls horizontally. */

:root {
  --bg: #eaf8f4;
  --panel: #dff1eb;
  --panel2: #d5efe7;
  --line: #bdded4;
  --text: #0b130e;
  --muted: #556e64;
  --accent: #2dbe86;
  --accent2: #61fecb;
  --mint: #20aa77;
  --red: #7d000e;

  --radius: 10px;
  --gap: 8px;
  --pad: 16px;
  --shadow: 0 1px 2px rgb(11 19 14 / 0.06), 0 4px 16px rgb(11 19 14 / 0.05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--sans);
  min-height: 100vh;
}
a { color: var(--mint); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}
h1, h2 { margin: 0; line-height: 1.25; }
.h1 { font-size: 22px; font-weight: 650; }
.h2 { font-size: 16px; font-weight: 600; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, code, pre, .log, .secret { font-family: var(--mono); }
.strong { font-weight: 600; color: var(--text); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.min0 { min-width: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -48px; background: var(--accent); color: var(--text);
  padding: 8px 12px; border-radius: var(--radius); z-index: 100;
}
.skip-link:focus { top: 8px; }

/* ------------------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px var(--pad);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar--guest { justify-content: center; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; flex: none; }
.search { flex: 1 1 260px; position: relative; min-width: 0; margin: 0; }
.search .input { padding-right: 56px; }
.kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font: 600 11px var(--mono); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; background: var(--bg);
  pointer-events: none;
}
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__panel {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 220px; z-index: 40;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: grid; gap: 2px;
}
.menu--end .menu__panel { right: 0; }
.menu__item {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; color: var(--text); font: inherit;
}
.menu__item:hover { background: var(--panel); text-decoration: none; }
.menu__panel form { margin: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text); font-size: 12px; white-space: nowrap;
}
.chip:hover { text-decoration: none; border-color: var(--mint); }
.chip--bad { border-color: var(--red); color: var(--red); }

/* ------------------------------------------------------------ layout */
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px var(--pad) 48px; }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 0 0 12px; padding: 0; color: var(--muted); font-size: 12px; }
.crumbs li + li::before { content: "/"; margin-right: 8px; color: var(--line); }
.crumbs a { color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--pad); margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card.empty { text-align: center; padding: 32px var(--pad); }
.card.empty .btn { margin-top: 8px; }
.card.danger { border-color: var(--red); }
.card.danger .h2 { color: var(--red); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px var(--pad); margin-top: 16px; }
.panel > summary { cursor: pointer; list-style: none; }
.panel > summary::-webkit-details-marker { display: none; }
.row-between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.row-end { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row form { margin: 0; }
.badge, .tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.tag--ok { color: var(--mint); border-color: var(--mint); }

.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); }
.notice--warn { border-color: var(--red); color: var(--red); background: #fff; }
.notice--ok { border-color: var(--mint); }
.flash { margin: 0 0 16px; padding: 10px 14px; border-radius: var(--radius); background: var(--panel2); border: 1px solid var(--mint); }
.flash--error { border-color: var(--red); color: var(--red); background: #fff; }

/* ------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: 600 14px var(--sans); cursor: pointer; white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: var(--mint); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.6; cursor: progress; }
.btn--primary { background: var(--accent); border-color: var(--mint); color: var(--text); }
.btn--primary:hover { background: var(--accent2); }
.btn--ghost { background: transparent; }
.btn--danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn--danger-ghost, .btn--ghost.btn--danger { color: var(--red); border-color: var(--red); }
.btn--sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn--icon { min-height: 32px; min-width: 32px; padding: 0 8px; font-size: 18px; line-height: 1; }
.btn--block { width: 100%; }
.btn[aria-busy="true"] { position: relative; }

.input, select.input, textarea.input {
  width: 100%; min-height: 36px; padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit;
  min-width: 0;
}
.input:focus { border-color: var(--mint); }
.input[aria-invalid="true"] { border-color: var(--red); }
textarea.input { min-height: 0; resize: vertical; }
.textarea-env { font-size: 13px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label { font-weight: 600; font-size: 13px; }
.field .muted.small { margin: 0; }
.field-error { margin: 2px 0 0; color: var(--red); font-size: 13px; }
.form-grid { display: grid; gap: 12px; }
.form-grid--row { grid-template-columns: 1fr; }
.form-grid.narrow, .narrow { max-width: 640px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.inline-form .input { flex: 1 1 180px; width: auto; }
.inline-form .field-error { flex-basis: 100%; }
.check { display: inline-flex; align-items: center; gap: 8px; }
.value-cell { max-width: 360px; }

/* ------------------------------------------------------------ filters, table */
.filters { display: grid; gap: 8px; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 13px;
}
.chip-link:hover { text-decoration: none; border-color: var(--mint); }
.chip-link.is-active { background: var(--accent); border-color: var(--mint); font-weight: 600; }
.count { font-size: 12px; color: var(--muted); }
.chip-link.is-active .count { color: var(--text); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; vertical-align: middle; border-top: 1px solid var(--line); }
.table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); border-top: 0; background: var(--panel2); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; width: 1%; }
.table .actions form { display: inline-block; margin: 0; }
.table tbody tr:hover { background: rgb(255 255 255 / 0.4); }
.value-cell { max-width: 360px; }
.app-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-cell .dot { align-self: flex-start; margin-top: 6px; }
.fleet td:first-child { min-width: 200px; }

/* status dots */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--line); }
.dot--running { background: var(--mint); box-shadow: 0 0 0 3px rgb(32 170 119 / 0.18); }
.dot--starting { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.dot--stopped { background: var(--muted); }
.dot--error { background: var(--red); }
.dot--unknown { background: var(--line); }
@keyframes pulse { 50% { opacity: 0.35; } }

.chip .dot { width: 8px; height: 8px; }
.chip--ok .dot { background: var(--mint); }

/* ------------------------------------------------------------ app page */
.app-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 16px; }
.app-head__main { min-width: 0; flex: 1 1 320px; }
.app-head__title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.app-head__title .h1 { overflow-wrap: anywhere; }
.app-head__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.app-head__actions form { margin: 0; }
.facts { display: grid; grid-template-columns: 1fr; gap: 8px 16px; margin: 12px 0 0; }
.facts > div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts--wide { grid-template-columns: 1fr; }
.app-layout { display: grid; gap: 16px; }
.tabrail ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.tabrail__link {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 8px 12px; border-radius: 10px; color: var(--text); border: 1px solid transparent;
}
.tabrail__link:hover { background: var(--panel); text-decoration: none; }
.tabrail__link[aria-current="page"] { background: var(--panel2); border-color: var(--line); font-weight: 600; }
.tabrail__link.is-soon { color: var(--muted); }
.app-body { min-width: 0; }
.stat-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.stat { margin: 0; }
.stat .eyebrow { margin-bottom: 8px; }
.stat__value { font-size: 24px; font-weight: 650; margin: 0; font-variant-numeric: tabular-nums; }
.stat__value--small { font-size: 16px; }
.log {
  margin: 0; padding: 12px; background: #0b130e; color: #d9f5ea; border-radius: var(--radius);
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; overflow: auto;
  max-height: 60vh; min-height: 120px;
}
.log--tall { max-height: none; min-height: 240px; }
.log--short { max-height: 280px; margin-top: 12px; }
.secret { display: block; margin: 8px 0; padding: 10px; background: var(--bg); border: 1px dashed var(--mint); border-radius: var(--radius); overflow-wrap: anywhere; }
.form-grid .card, .card form.form-grid { margin: 0; }

/* ------------------------------------------------------------ drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60;
  width: min(560px, 100vw); overflow-y: auto;
  background: var(--bg); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgb(11 19 14 / 0.12);
}
.drawer__inner { padding: var(--pad); display: grid; gap: 12px; }
.drawer__head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.drawer__head .h2 { overflow-wrap: anywhere; }

/* ------------------------------------------------------------ auth */
.auth { max-width: 420px; margin: 40px auto; }
.auth .h1 { margin-bottom: 4px; }
.auth form { margin-top: 12px; }

/* ------------------------------------------------------------ toasts */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 80;
  display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow); transition: opacity 0.3s;
}
.toast--error { background: var(--red); color: #fff; }
.toast.is-leaving { opacity: 0; }

/* ------------------------------------------------------------ tabs: files, storage, github, coolify */
.textarea-code { font: 13px/1.5 var(--mono); min-height: 240px; white-space: pre; tab-size: 4; }
.lazy { min-height: 48px; }
.subtabs ul { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.subtab {
  display: inline-block; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--text); font-size: 13px; background: var(--bg);
}
.subtab:hover { text-decoration: none; border-color: var(--mint); }
.subtab.is-active { background: var(--accent); border-color: var(--mint); font-weight: 600; }
.sqlite-grid { display: grid; gap: 12px; grid-template-columns: 1fr; min-width: 0; }
.sqlite-tables { max-height: 240px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; background: var(--bg); }
.sqlite-tables .list { margin-top: 0; }
.sqlite-main { min-width: 0; overflow-x: auto; }
.storage-item { border-top: 1px solid var(--line); padding: 16px 0 4px; min-width: 0; }
.storage-item:first-of-type { border-top: 0; padding-top: 0; }
.storage-item .inline-form { margin: 8px 0; }
.table td .check { white-space: normal; max-width: 220px; }
.table .actions form + form { margin-top: 6px; }
.check.small { font-size: 12px; }
.notice + .notice { margin-top: 8px; }
.card .notice:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ responsive */
@media (min-width: 640px) {
  .form-grid--row { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .facts--wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hide-sm { display: table-cell; }
}
@media (min-width: 900px) {
  .sqlite-grid { grid-template-columns: 220px minmax(0, 1fr); align-items: start; }
  .app-layout { grid-template-columns: 200px minmax(0, 1fr); align-items: start; }
  .tabrail ul { flex-direction: column; overflow: visible; position: sticky; top: 72px; }
  .tabrail__link { width: 100%; }
}
@media (max-width: 639px) {
  .hide-sm { display: none; }
  .topbar .search { order: 3; flex-basis: 100%; }
  .topbar .chip { font-size: 11px; }
  .menu__panel { right: auto; left: 0; }
  .page-head .btn { flex: 1 1 auto; }
  .drawer { width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
