/* One stylesheet, no build step. Colours, type and spacing are variables. */
:root {
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --bg: #f3f4f1;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #59616b;
  --border: #dadfd6;
  --header-bg: #17202b;
  --accent: #0e5a6b;
  --accent-hover: #0a4352;
  --accent-soft: #e3eeef;
  --ok: #1e6b3a;
  --ok-soft: #e4f1e7;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --danger: #a3262a;
  --danger-soft: #fbe7e7;
  --idle: #4a525b;
  --idle-soft: #ecedea;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --control-height: 2.5rem;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1 { font-size: 1.7rem; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 var(--space-2); }
h2 { font-size: 1.05rem; font-weight: 600; margin: var(--space-5) 0 var(--space-3); }
h3 { font-size: 1rem; margin: var(--space-4) 0 var(--space-2); }
h1:focus { outline: none; }
p { margin: 0 0 var(--space-3); }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
.muted { color: var(--muted); }

/* Pretty-printed event data */
pre.json { margin: 0; font-family: var(--mono); font-size: 0.85em; line-height: 1.5; white-space: pre-wrap;
  word-break: break-word; min-width: 16rem; }
.col-data { width: 1%; white-space: nowrap; }
/* The data of an event, in a dialog opened from its row */
.chain-dialog.data-dialog { width: min(720px, calc(100vw - 32px)); }

/* Event log: paging through the events, above and below the table */
.log-tools { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); }
.pager { display: flex; gap: var(--space-4); margin: var(--space-2) 0 var(--space-3); }
.log-tools .pager { margin-top: 0; }

/* Event log: the chain icon opens the events of the same operation in a dialog, indented under their causes */
.event-line { display: flex; align-items: baseline; gap: var(--space-2); }
.col-chain { width: 1%; white-space: nowrap; }
.chain-button { min-width: 3.4rem; justify-content: center; flex: none; }
.chain-icon { flex: none; vertical-align: -2px; }
.chain-dialog { width: min(1200px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.25); }
.chain-dialog > div { padding: var(--space-5); }
.chain-dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-3); }
.dialog-head h2:focus { outline: none; }
.dialog-head h2 { margin: 0; display: inline-flex; align-items: center; gap: var(--space-2); }
/* Policy: how a month's premium was calculated, in a dialog */
.premium-summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-5);
  padding-bottom: var(--space-4); border-bottom: 1px solid var(--border); }
.premium-amount { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.figure { display: flex; flex-direction: column; gap: 2px; }
.figure-label { font-size: 0.85rem; color: var(--muted); }
#premium-dialog-body h3 { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em;
  margin: var(--space-5) 0 var(--space-2); }
#premium-dialog-body tfoot th { background: none; text-align: right; border-bottom: 0; }
#premium-dialog-body tfoot td { border-bottom: 0; }
.chain-options { display: flex; flex-wrap: wrap; gap: var(--space-5); }
.chain-options form { margin: 0; }
tr[data-depth] { --indent: 0rem; }
tr[data-depth] .event-line { padding-left: var(--indent); }
tr[data-depth="1"] { --indent: 1.5rem; }
tr[data-depth="2"] { --indent: 3rem; }
tr[data-depth="3"] { --indent: 4.5rem; }
tr[data-depth="4"] { --indent: 6rem; }
tr[data-depth="5"] { --indent: 7.5rem; }
tr[data-depth="6"] { --indent: 9rem; }
tr[data-depth="7"] { --indent: 10.5rem; }
tr[data-depth="8"] { --indent: 12rem; }
tr[data-depth]:not([data-depth="0"]) .event-line::before { content: "\21B3"; color: var(--muted); flex: none; }
table.chain tr.selected td { background: var(--accent-soft); }
table.chain tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
table.chain tr.sibling td { background: #f6f7f9; color: var(--muted); }
.tag.tag-selected { background: var(--accent); color: #fff; }
.event-line details.revert { margin-left: auto; }
.j-key { color: #1f4e79; }
.j-str { color: #1d6b3a; }
.j-num { color: #8a5a00; }
.j-lit { color: #7a3e8f; }
.j-punct { color: #8b95a3; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Header and navigation */
.topbar { background: var(--header-bg); color: #fff; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 var(--space-5); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-5); min-height: 52px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1rem; color: #fff; text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 6px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.nav { display: flex; gap: var(--space-1); flex: 1; }
.nav a { color: #c9cfd6; text-decoration: none; padding: var(--space-2) var(--space-3); border-radius: var(--radius); font-size: 0.92rem; }
.nav a:hover, .nav a.active { background: rgba(255, 255, 255, 0.12); color: #fff; }
.who { display: flex; align-items: center; gap: var(--space-3); color: #c9cfd6; margin-left: auto; font-size: 0.92rem; }
.who form { margin: 0; }
.who button { background: transparent; border: 1px solid rgba(255,255,255,0.4); color: #fff; padding: var(--space-1) var(--space-3); }
.who button:hover { background: rgba(255,255,255,0.14); }

main { max-width: 1280px; margin: 0 auto; padding: var(--space-5); }
.breadcrumbs { font-size: 0.9rem; color: var(--muted); margin-bottom: var(--space-2); }
.breadcrumbs a { color: var(--muted); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }

/* Cards and layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow); margin-bottom: var(--space-4); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.card-head > h2 { margin: 0; }
.grid { display: grid; gap: var(--space-4); margin-bottom: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-1) var(--space-4); margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr[aria-current="date"] td { background: var(--accent-soft); }
tr.reverted td { color: var(--muted); text-decoration: line-through; }
tr.reverted td.actions { text-decoration: none; }
tr.linked td { background: #fff6d6; }
.empty { color: var(--muted); padding: var(--space-4); text-align: center; }

/* Forms */
form { margin: 0; }
.form { display: grid; gap: var(--space-3); }
.form-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 140px; }
.field.wide { flex: 1; min-width: 220px; }
.field > input, .field > select, .field > textarea { width: 100%; max-width: 100%; }
label, .label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.check { flex-direction: row; align-items: center; gap: var(--space-2); }
/* Native look switched off so date fields, selects and text fields get the same height and border on every
   browser, iOS Safari included; selects get their own chevron. */
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text);
  -webkit-appearance: none; appearance: none; margin: 0; min-width: 0; }
select { padding-right: 32px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2359616b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center; }
input[type="date"] { display: flex; align-items: center; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; min-height: 1.45em; }
input[type="date"]::-webkit-datetime-edit { padding: 0; }
input[type="checkbox"], input[type="radio"] { -webkit-appearance: auto; appearance: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { width: auto; }
input:not([type="checkbox"]):not([type="radio"]), select { box-sizing: border-box; height: var(--control-height); }
.hint { font-size: 0.85rem; color: var(--muted); }
.filter-bar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr) auto auto auto; gap: var(--space-2) var(--space-3); align-items: end; }
.filter-bar .field { min-width: 0; }
.filter-bar .filter-actions { display: flex; gap: var(--space-2); }
.filter-bar .filter-actions > * { height: var(--control-height); box-sizing: border-box; }
.filter-bar .hint { grid-column: 4 / -1; margin: 0; }
/* A dropdown of checkboxes, for choosing several values in a filter. */
.multi-select { position: relative; }
.multi-select > summary { list-style: none; cursor: pointer; height: var(--control-height); display: flex; align-items: center; padding: 7px 32px 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2359616b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center; }
.multi-select > summary::-webkit-details-marker { display: none; }
.multi-select > summary > span { overflow: hidden; text-overflow: ellipsis; }
.multi-select > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.multi-select .options { position: absolute; z-index: 20; top: calc(100% + var(--space-1)); left: 0; min-width: 100%; margin: 0;
  display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 12px rgba(16, 24, 40, 0.12); }
.multi-select .options label { display: flex; color: var(--text); font-size: 0.9rem; white-space: nowrap; }
.filter-bar .filter-check { grid-column: 1 / 3; display: inline-flex; align-items: center; gap: var(--space-2); }
form + .hint, .button + .hint, button + .hint, .message + .hint, .table-wrap + .hint, table + .hint { margin-top: var(--space-3); }
.button + .message, button + .message { margin-top: var(--space-4); }
.hint:last-child, .card > p:last-child { margin-bottom: 0; }
button, .button { font: inherit; display: inline-flex; align-items: center; gap: var(--space-2); padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .button:hover { background: var(--accent-hover); color: #fff; }
button.secondary, .button.secondary { background: #fff; color: var(--accent); }
button.secondary:hover, .button.secondary:hover { background: var(--accent-soft); }
button.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
/* Buttons next to fields are as tall as the fields */
.form-row > button, .form-row > .button, .asof > button, .asof > .button { height: var(--control-height); justify-content: center; }
button.small, .button.small { padding: 3px 9px; font-size: 0.85rem; }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }

details.action { display: inline-block; }
details.action > summary { list-style: none; cursor: pointer; color: var(--accent); font-size: 0.9rem; }
details.action > summary::-webkit-details-marker { display: none; }
details.action[open] > summary { margin-bottom: var(--space-2); }
details.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--space-4); }
details.panel > summary { cursor: pointer; padding: var(--space-3) var(--space-4); font-weight: 600; }
details.panel > .panel-body { padding: 0 var(--space-4) var(--space-4); }
.panel-body > form + form { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--border); }

/* Messages */
.message { padding: var(--space-3) var(--space-5); border-radius: var(--radius); margin: var(--space-4) 0; border: 1px solid transparent; }
.message:first-child { margin-top: 0; }
.card > .message:last-child { margin-bottom: 0; }
.message.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe0ca; }
.message.error { background: var(--danger-soft); color: var(--danger); border-color: #f0c3c3; }
.message.warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dca8; }
.message.info { background: var(--accent-soft); color: var(--accent); border-color: #c6d8ea; }
/* A failed htmx request, above the page until closed or the next request. */
.request-error { position: fixed; top: var(--space-4); left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; gap: var(--space-4); align-items: center; max-width: calc(100% - 2 * var(--space-4));
  box-shadow: 0 12px 40px rgba(16, 24, 40, 0.25); }
.form-error { color: var(--danger); background: var(--danger-soft); padding: var(--space-2) var(--space-3); border-radius: var(--radius); }

/* Tags */
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--idle-soft); color: var(--idle); white-space: nowrap; }
.tag-active { background: var(--ok-soft); color: var(--ok); }
.tag-paused { background: var(--warn-soft); color: var(--warn); }
.tag-terminated { background: var(--idle-soft); color: var(--idle); }
.tag-removed { background: var(--danger-soft); color: var(--danger); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-credit { background: var(--accent-soft); color: var(--accent); }
.tag a { color: inherit; }

/* Tabs */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); flex-wrap: wrap; }
.tabs a { padding: var(--space-2) var(--space-4); text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* As-of selector */
.asof { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-2) var(--space-3); }
.asof .field { min-width: 0; }
.asof.past { border-color: var(--warn); background: var(--warn-soft); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 var(--space-3) var(--space-4); }
.timeline li::before { content: ""; position: absolute; left: -8px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline li.current::before { background: var(--accent); }
.timeline .when { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }


/* Login */
.login { max-width: 380px; margin: 10vh auto; }
.login h1 { margin-bottom: var(--space-4); }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; padding: var(--space-2) var(--space-4); }
  .nav { order: 1; flex-basis: 100%; overflow-x: auto; }
  main { padding: var(--space-4); }
  h1 { font-size: 1.45rem; overflow-wrap: anywhere; }
  /* iOS zooms in on fields with text smaller than 16px */
  input, select, textarea { font-size: 16px; }
  .card { padding: var(--space-4); }
  .page-head { align-items: stretch; }
  .page-head > * { min-width: 0; }
  /* Fields share the row and wrap to full width; buttons keep their width */
  .form-row > .field, .form-row > .field.wide { flex: 1 1 100%; min-width: 0; }
  .asof { width: 100%; padding: var(--space-3); }
  .asof .field { flex: 1 1 8rem; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; }
  .tabs a { white-space: nowrap; padding: var(--space-2) var(--space-3); }
  details.panel > summary { padding: var(--space-3); }
  details.panel > .panel-body { padding: 0 var(--space-3) var(--space-3); }
  .filter-bar { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .filter-bar .hint, .filter-bar .filter-check { grid-column: auto; }
}
[hidden] { display: none !important; }
