/* n8n team panel ------------------------------------------------------------
   Cool equipment-room palette; DIN-style labels like the ones printed on
   rack hardware; the rack strip is the one loud element, the rest is quiet. */

:root {
  --paper: #eef1f4;
  --surface: #f8fafb;
  --ink: #17222d;
  --steel: #5a6a79;
  --rack: #2a5c86;
  --rack-deep: #1f4566;
  --rack-soft: #d6e2ec;
  --rule: #c8d0d8;
  --ok: #2e7a4e;
  --warn: #a0660f;
  --danger: #a5302b;

  --display: "Bahnschrift", "DIN Alternate", "DIN Next", "Roboto Condensed", "Arial Narrow", sans-serif-condensed, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Menlo, monospace;

  /* modular scale 1.25 */
  --s-1: 0.8rem;
  --s0: 1rem;
  --s1: 1.25rem;
  --s2: 1.563rem;
  --s3: 1.953rem;
  --s4: 2.441rem;

  --radius-control: 6px;
  --radius-panel: 10px;
  --focus: 0 0 0 3px #8fb3d1;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--body);
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }

h1, h2, h3 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.15;
  margin: 0;
}

a { color: var(--rack); text-underline-offset: 2px; }
a:hover { color: var(--rack-deep); }

.muted { color: var(--steel); }
.error { color: var(--danger); margin: 0.5rem 0 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-control); }

/* Buttons ------------------------------------------------------------------ */
.btn {
  font: 500 14px/1 var(--body);
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-control);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--steel); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--rack); border-color: var(--rack); color: #fff; }
.btn.primary:hover { background: var(--rack-deep); border-color: var(--rack-deep); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--steel); }
.btn.ghost:hover { color: var(--ink); border-color: var(--rule); }
.btn.small { padding: 0.4rem 0.6rem; font-size: 13px; }
.btn.wide { width: 100%; padding: 0.75rem; }

/* Forms --------------------------------------------------------------------- */
label { display: grid; gap: 0.3rem; font-size: 13px; font-weight: 500; color: var(--steel); }
input,
select,
textarea {
  font: 400 15px/1.3 var(--body);
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  padding: 0.55rem 0.65rem;
  width: 100%;
}
input:focus,
select:focus,
textarea:focus { outline: none; border-color: var(--rack); box-shadow: var(--focus); }
.hint { font-weight: 400; color: var(--steel); }
fieldset { border: 0; padding: 0; margin: 1.1rem 0 0; }
legend { font-family: var(--display); font-size: var(--s0); font-weight: 600; color: var(--ink); padding: 0; margin-bottom: 0.5rem; }
fieldset.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.span-2 { grid-column: span 2; }
.check { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); font-weight: 400; }
.check input { width: auto; }

/* Login ------------------------------------------------------------------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-panel);
  padding: 2rem;
}
.login-box h1 { font-size: var(--s3); }
.login-box p { margin: 0; }
.login-rack { display: grid; gap: 4px; width: 56px; margin-bottom: 0.25rem; }
.login-rack span { height: 9px; border: 1.5px solid var(--rack); border-radius: 2px; }
.login-rack span.on { background: var(--rack); }

/* Top bar ------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}
.brand { white-space: nowrap; display: flex; align-items: baseline; gap: 0.6rem; font-family: var(--display); font-weight: 600; font-size: var(--s1); }
.brand .muted { font-family: var(--body); font-weight: 400; font-size: 14px; }
.brand-mark { width: 14px; height: 14px; border-radius: 3px; background: var(--rack); align-self: center; }
.topbar-actions { display: flex; gap: 0.25rem; }

.banner {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.6rem 1rem;
  background: #fbf1df;
  color: #5c3b07;
  border-bottom: 1px solid #ecd3a6;
}

.page { max-width: 1240px; margin: 0 auto; padding: clamp(1.25rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2.5rem) 6rem; }

/* Capacity: the rack ---------------------------------------------------------- */
.capacity { margin-bottom: 3rem; }
.cap-headline {
  font-size: clamp(var(--s3), 4.4vw, 3.4rem);
  font-weight: 600;
  max-width: 22ch;
  letter-spacing: -0.015em;
}
.cap-headline .count {
  font-variant-numeric: tabular-nums;
  color: var(--rack);
}
.cap-sub { margin: 0.6rem 0 1.5rem; max-width: 70ch; }

.rack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
  padding: 10px;
  background: var(--ink);
  border-radius: var(--radius-panel);
}
.slot {
  position: relative;
  height: 54px;
  border-radius: 4px;
  display: flex;
  align-items: flex-end;
  padding: 6px 8px;
  font: 600 12px/1.1 var(--display);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot.taken { background: var(--rack); color: #fff; }
.slot.taken::before {
  /* status LED */
  content: "";
  position: absolute;
  top: 8px;
  left: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8b98a5;
}
.slot.taken.running::before { background: #6fe39b; }
.slot.taken.problem::before { background: #f0a43a; }
.slot.open { border: 1.5px dashed #5d7b95; color: #8fb3d1; }
.slot.none { background: repeating-linear-gradient(135deg, #222f3c 0 6px, #1c2833 6px 12px); }
.slot.more { border: 1.5px dashed #5d7b95; color: #cfe0ee; justify-content: center; align-items: center; font-size: 14px; }
.slot.taken:hover { background: #33709f; cursor: pointer; }

.rack-legend { display: flex; gap: 1.25rem; margin: 0.6rem 0 1.5rem; font-size: 13px; }
.rack-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.key { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.key.taken { background: var(--rack); }
.key.open { border: 1.5px dashed var(--rack); }
.key.none { background: repeating-linear-gradient(135deg, #5a6a79 0 3px, #8b98a5 3px 6px); }

/* Meters */
.meters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.5rem; }
.meter { padding-top: 0.75rem; border-top: 2px solid var(--rule); }
.meter.limit { border-top-color: var(--warn); }
.meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.meter h3 { font-size: var(--s0); }
.meter-fits { font-size: 13px; color: var(--steel); }
.meter.limit .meter-fits { color: var(--warn); font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--rack-soft); margin: 0.6rem 0 0.45rem; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--rack); width: 0; transition: width 400ms ease; }
.bar.hot > span { background: var(--warn); }
.meter p { margin: 0; font-size: 13px; color: var(--steel); }

.warnings { list-style: none; padding: 0; margin: 1.25rem 0 0; display: grid; gap: 0.4rem; }
.warnings li { font-size: 14px; color: #5c3b07; background: #fbf1df; border-left: 3px solid var(--warn); padding: 0.5rem 0.75rem; border-radius: 0 var(--radius-control) var(--radius-control) 0; }

/* Instances table --------------------------------------------------------------- */
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.9rem; }
.section-head h2 { font-size: var(--s2); }
.table-wrap { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-panel); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font: 500 13px/1.2 var(--body);
  color: var(--steel);
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--rule);
}
.table td { padding: 0.8rem 1rem; border-bottom: 1px solid #e1e6eb; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f1f5f8; }
.num { text-align: right; }
.inst-name { display: grid; gap: 0.1rem; }
.inst-name strong { font-family: var(--display); font-size: var(--s0); font-weight: 600; }
.inst-name a { font-size: 13px; }
.inst-name .note { font-size: 12px; color: var(--steel); }
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #8b98a5; flex: none; }
.dot.running { background: var(--ok); }
.dot.busy { background: var(--rack); animation: pulse 1.2s ease-in-out infinite; }
.dot.problem { background: var(--warn); }
.owner { font-size: 14px; }
.owner small { display: block; color: var(--steel); font-size: 12px; }
.mem { min-width: 120px; font-size: 13px; }
.mem .bar { margin: 0.3rem 0 0; height: 4px; }
.row-actions { display: flex; gap: 0.35rem; justify-content: flex-end; }
.empty { padding: 3rem 1.5rem; text-align: center; }
.empty p { margin: 0 auto 0.5rem; max-width: 52ch; }
.empty .btn { margin-top: 0.75rem; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* Drawer ------------------------------------------------------------------------- */
.backdrop { position: fixed; inset: 0; background: rgba(23, 34, 45, 0.35); z-index: 20; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(620px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--rule);
  z-index: 21;
  display: flex;
  flex-direction: column;
  animation: slide-in 180ms ease-out;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 1.25rem 1.5rem 0.75rem; }
.drawer-head h2 { font-size: var(--s3); }
.drawer-head a { font-size: 14px; }
.tabs { display: flex; gap: 0.15rem; padding: 0 1.25rem; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tabs button {
  font: 500 14px/1 var(--body);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--steel);
  padding: 0.75rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--rack); }
.tabs button[data-tab="delete"] { margin-left: auto; }
.tabs button[data-tab="delete"][aria-selected="true"] { border-bottom-color: var(--danger); }
.drawer-body { padding: 1.25rem 1.5rem 2rem; overflow-y: auto; flex: 1; }
.drawer-body h3 { font-size: var(--s1); margin: 0 0 0.5rem; }
.drawer-body section + section { margin-top: 1.75rem; }
.drawer-body p { max-width: 64ch; }
.stack { display: grid; gap: 0.85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.45rem 1.25rem; margin: 0; font-size: 14px; }
.facts dt { color: var(--steel); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.env-rows { display: grid; gap: 0.4rem; }
.env-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 0.4rem; }
.env-row input { font-family: var(--mono); font-size: 13px; }

.list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-control); }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; padding: 0.6rem 0.75rem; border-bottom: 1px solid #e1e6eb; font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list .meta { display: grid; min-width: 0; }
.list .meta span:first-child { overflow-wrap: anywhere; }
.list .meta small { color: var(--steel); }
.list .acts { display: flex; gap: 0.3rem; flex: none; }

.logs {
  font: 12px/1.45 var(--mono);
  background: var(--ink);
  color: #d5dee6;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-control);
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.75rem 0 0;
}

.callout { border-left: 3px solid var(--warn); background: #fbf1df; padding: 0.6rem 0.8rem; border-radius: 0 var(--radius-control) var(--radius-control) 0; font-size: 14px; color: #5c3b07; }
.callout.danger { border-left-color: var(--danger); background: #f8e5e3; color: #5e1814; }

/* Dialogs ----------------------------------------------------------------------- */
.dialog {
  border: 1px solid var(--rule);
  border-radius: var(--radius-panel);
  padding: 1.75rem;
  width: min(620px, calc(100% - 2rem));
  background: var(--surface);
  color: var(--ink);
}
.dialog.narrow { width: min(460px, calc(100% - 2rem)); }
.dialog::backdrop { background: rgba(23, 34, 45, 0.45); }
.dialog h2 { font-size: var(--s2); margin-bottom: 0.35rem; }
.dialog > form > p { margin: 0 0 0.75rem; }
.dialog > form > label { margin-top: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }
.creds { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1rem; margin: 1rem 0 0; }
.creds dt { color: var(--steel); }
.creds dd { margin: 0; overflow-wrap: anywhere; }
.creds code { font: 600 16px/1.3 var(--mono); background: var(--rack-soft); padding: 0.15rem 0.4rem; border-radius: 4px; }

/* Activity tray ------------------------------------------------------------------ */
.tray {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  width: min(400px, calc(100% - 2rem));
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-panel);
  box-shadow: 0 8px 28px rgba(23, 34, 45, 0.18);
  z-index: 30;
}
.tray-head { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--rule); }
.tray-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.tray-list > li { padding: 0.7rem 0.9rem; border-bottom: 1px solid #e1e6eb; font-size: 13px; }
.tray-list > li:last-child { border-bottom: 0; }
.job-title { display: flex; align-items: center; gap: 0.45rem; font-weight: 600; font-size: 14px; }
.job-step { color: var(--steel); margin-top: 0.2rem; overflow-wrap: anywhere; }
.job-failed .job-step { color: var(--danger); }
details.job-log summary { cursor: pointer; color: var(--rack); margin-top: 0.3rem; }
details.job-log ol { margin: 0.3rem 0 0; padding-left: 1.1rem; color: var(--steel); }

/* Responsive ------------------------------------------------------------------- */
@media (max-width: 860px) {
  .meters { grid-template-columns: 1fr; gap: 1rem; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 0.75rem 1rem; border-bottom: 1px solid var(--rule); }
  .table td { border: 0; padding: 0.2rem 0; }
  .table td.num { text-align: left; }
  .table td[data-label]::before { content: attr(data-label) ": "; color: var(--steel); font-size: 13px; }
  .row-actions { justify-content: flex-start; margin-top: 0.5rem; }
  fieldset.row { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .brand .muted { display: none; }
  .topbar { padding: 0.6rem 1rem; }
  .topbar-actions .btn { padding: 0.5rem 0.4rem; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
