/* IMA Control Panel — quiet dark, ash surfaces, warm cream text. One accent: cream. */
:root {
  color-scheme: dark;

  /* surfaces (Discord-style stack: darkest → lightest) */
  --bg: #2b2d31;          /* main canvas */
  --side: #232428;        /* sidebar */
  --panel: #313338;       /* cards */
  --input: #1e1f22;       /* inputs, log wells */
  --hover: #383a40;
  --active: #404249;

  /* lines */
  --line: #3b3d44;
  --line-strong: #4b4e56;

  /* text — warm, yellowish white */
  --text: #ebe6d8;
  --muted: #a9a698;
  --faint: #7d7b72;

  /* the only accent: cream (buttons, focus, progress) */
  --accent: #ebe6d8;
  --accent-ink: #1e1f22;

  /* status — muted, used sparingly */
  --ok: #8fbf9f;
  --warn: #d6b970;
  --err: #d98a82;

  --radius: 8px;
  --radius-sm: 6px;

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
a { color: var(--text); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--text); }
strong { font-weight: 600; }
::selection { background: rgba(235, 230, 216, .22); }
code {
  font-family: var(--mono); font-size: .86em;
  background: var(--input); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 4px; color: var(--text);
}
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; border: 2px solid transparent; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--side);
  display: flex;
  flex-direction: column;
  border-right: 1px solid #1b1c1f;
}
.brand { padding: 18px 20px 8px; }
.brand h1 {
  margin: 0; font-family: var(--serif); font-size: 21px; font-weight: 500; letter-spacing: -.01em;
}
.brand p { margin: 3px 0 0; font-size: 12px; color: var(--faint); }

.nav { padding: 6px 10px 12px; flex: 1; overflow-y: auto; }
.nav-label {
  padding: 14px 10px 4px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--faint);
}
.nav a, .nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 5px 10px;
  margin: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  font: inherit;
  font-size: 13.5px;
  color: var(--muted);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.nav a:hover, .nav-group-toggle:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: var(--active); color: var(--text); font-weight: 500; }
.nav .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line-strong); flex: 0 0 5px; transition: background .12s ease; }
.nav a.active .dot { background: var(--accent); }
.nav .badge {
  margin-left: auto; font-size: 11px; color: var(--faint);
  background: var(--input); border-radius: 10px; padding: 0 7px; min-width: 22px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav a.active .badge { color: var(--text); }

.nav-group-toggle .chev { margin-left: auto; font-size: 9px; color: var(--faint); transition: transform .15s ease; }
.nav-group.open .nav-group-toggle .chev { transform: rotate(90deg); }
.nav-group.open .nav-group-toggle { color: var(--text); }
.nav-sub { display: none; margin: 2px 0 4px 14px; padding-left: 8px; border-left: 1px solid var(--line); }
.nav-group.open .nav-sub { display: block; }
.nav-sub a { padding-left: 10px; }

.sidebar-foot {
  border-top: 1px solid #1b1c1f;
  padding: 10px 20px 12px;
  font-size: 11.5px;
  color: var(--faint);
  display: grid;
  gap: 3px;
}
.sidebar-foot .row { display: flex; justify-content: space-between; gap: 8px; }
.sidebar-foot .row span:last-child { color: var(--muted); }
.sidebar-foot a { color: var(--muted); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; background: var(--bg); }
.topbar {
  padding: 20px 32px 14px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.topbar h2 { margin: 0; font-family: var(--serif); font-size: 26px; font-weight: 500; letter-spacing: -.015em; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }

.view { flex: 1; overflow-y: auto; padding: 8px 32px 56px; }
.view > * { max-width: 1100px; }
.view[hidden] { display: none; }

/* ---------- primitives ---------- */
.card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 18px;
}
.card > h3 { margin: 0 0 4px; font-size: 14.5px; font-weight: 600; letter-spacing: -.005em; }
.card > .hint { margin: 0 0 16px; font-size: 13px; color: var(--muted); max-width: 78ch; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 980px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 6px;
}
input[type=text], input[type=number], input[type=email], input[type=password],
input[type=date], input[type=time], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--input);
  color: var(--text);
  padding: 8px 11px;
  font: inherit;
  border-radius: var(--radius-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--muted); box-shadow: 0 0 0 3px rgba(235, 230, 216, .09);
}
input:disabled, textarea:disabled, select:disabled { background: var(--side); color: var(--faint); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 14px; height: 14px; vertical-align: -2px; }

button {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--line-strong);
  background: var(--hover);
  color: var(--text);
  padding: 7px 15px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background .12s ease, border-color .12s ease, transform .05s ease;
}
button:hover:not(:disabled) { background: var(--active); border-color: var(--faint); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--muted); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: #fff8e8; border-color: #fff8e8; }
button.danger { color: var(--err); background: transparent; border-color: rgba(217, 138, 130, .35); }
button.danger:hover:not(:disabled) { background: rgba(217, 138, 130, .1); border-color: var(--err); }
button.small { padding: 4px 10px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-row input { flex: 1 1 0; min-width: 0; }
.btn-row button { flex: 0 0 auto; }

.chip {
  display: inline-block; font-size: 11.5px; font-weight: 500; padding: 1px 9px;
  background: var(--input); border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chip.ok { color: var(--ok); border-color: rgba(143, 191, 159, .35); background: rgba(143, 191, 159, .08); }
.chip.warn { color: var(--warn); border-color: rgba(214, 185, 112, .35); background: rgba(214, 185, 112, .08); }
.chip.err { color: var(--err); border-color: rgba(217, 138, 130, .35); background: rgba(217, 138, 130, .08); }

.stat { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-family: var(--serif); font-size: 28px; font-weight: 500; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; }

.empty { color: var(--faint); font-size: 13px; padding: 22px 0; text-align: center; }
.error-box {
  border: 1px solid rgba(217, 138, 130, .35); background: rgba(217, 138, 130, .08);
  color: var(--err); padding: 10px 14px; font-size: 13px; margin-bottom: 16px; border-radius: var(--radius-sm);
}
.note { font-size: 12.5px; color: var(--muted); }

/* ---------- master / detail ---------- */
.split {
  display: grid; grid-template-columns: 330px 1fr; gap: 0;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  min-height: 460px; overflow: hidden;
}
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.split .list { border-right: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; min-height: 0; }
.split .list .search { padding: 10px; border-bottom: 1px solid var(--line); }
.split .list .items { overflow-y: auto; max-height: 62vh; }
.split .detail { padding: 22px 24px; overflow-y: auto; max-height: 70vh; }

.item {
  padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
  display: flex; align-items: flex-start; gap: 8px;
  box-shadow: inset 2px 0 0 transparent;
  transition: background .1s ease;
}
.item:hover { background: var(--hover); }
.item.active { background: var(--active); box-shadow: inset 2px 0 0 var(--accent); }
.item .name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; min-width: 0; line-height: 1.4; }
.item .meta { padding-top: 1px; margin-left: auto; font-size: 11.5px; color: var(--faint); white-space: nowrap; }
.list-foot { padding: 9px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; white-space: nowrap; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: pre-wrap; word-break: break-word; }

/* ---------- logs ---------- */
.logs { border: 1px solid var(--line); border-radius: var(--radius); margin-top: 4px; overflow: hidden; }
.logs-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--side);
}
.logs-head .title { font-size: 12px; font-weight: 600; }
.logs-head .spacer { flex: 1; }
.logs-head label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.log-body {
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  padding: 10px 14px; height: 240px; overflow-y: auto; background: var(--input);
}
.log-body.tall { height: 340px; }
.log-line { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-word; }
.log-line .t { color: var(--faint); flex: 0 0 auto; }
.log-line .l { flex: 0 0 54px; }
.log-line.INFO .l { color: var(--muted); }
.log-line.WARNING .l { color: var(--warn); }
.log-line.ERROR .l, .log-line.CRITICAL .l { color: var(--err); }
.log-line.DEBUG .l { color: var(--faint); }
.log-line .m { flex: 1; min-width: 0; }
.log-empty { color: var(--faint); }

/* ---------- job strip ---------- */
.job {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 11px 14px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.job .step { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .spacer { flex: 1; }
.bar { height: 3px; background: var(--line); margin-top: 8px; border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s ease; }

.result { border: 1px solid var(--line); border-radius: var(--radius); margin-top: 16px; overflow: hidden; background: var(--panel); }
.result h4 { margin: 0; padding: 9px 14px; font-size: 12.5px; font-weight: 600; border-bottom: 1px solid var(--line); background: var(--side); }
.result pre {
  margin: 0; padding: 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word; max-height: 420px; overflow-y: auto; background: var(--input);
}
details.raw { margin-top: 12px; }
details.raw summary { cursor: pointer; font-size: 12.5px; color: var(--muted); }
details.raw summary:hover { color: var(--text); }

/* ---------- folded log cards (one per tool page) ---------- */
.logs-card { padding: 0; }
.logs-card > h3 {
  margin: 0; padding: 14px 22px; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500;
}
.logs-card > h3::before { content: "\25B8"; font-size: 10px; color: var(--faint); transition: transform .15s ease; }
.logs-card:not(.collapsed) > h3::before { transform: rotate(90deg); }
.logs-card > h3:hover { color: var(--text); }
.logs-card:not(.collapsed) > [data-logpanel] { padding: 0 22px 20px; }
.logs-card.collapsed > [data-logpanel] { display: none; }
