:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #e2e2e0;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --danger: #c4372f;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161618;
    --surface: #1f1f22;
    --text: #ececee;
    --muted: #9a9aa2;
    --border: #333338;
    --accent: #6b9cf5;
    --accent-text: #0d0d10;
    --warn-bg: #3a2f12;
    --warn-text: #f3d48a;
    --danger: #f07a72;
    color-scheme: dark;
  }
}

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

body {
  margin: 0 auto;
  max-width: 1100px;
  padding: 0 16px 48px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0; }

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 0 12px;
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

button, .button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--muted); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.link { border: none; background: none; color: var(--accent); padding: 0 4px; }
.danger { color: var(--danger); }

input, select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); font-weight: 600; }

.muted { color: var(--muted); }
.warn { color: var(--warn-text); }
.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.toolbar label { display: flex; gap: 6px; align-items: center; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 0.85rem; }
.tile .value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 0.85rem; }

.chart { position: relative; height: 280px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
td.num, th.num { text-align: right; }
tfoot td { font-weight: 600; border-bottom: none; }
tr.unrated td { color: var(--warn-text); }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

h4 { font-size: 0.85rem; color: var(--muted); font-weight: 500; margin: 16px 0 4px; }

.position-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }

.empty { text-align: center; padding: 48px 16px; }
.empty p { color: var(--muted); max-width: 460px; margin: 8px auto 20px; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  width: min(560px, calc(100vw - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.new-position { border-top: 1px solid var(--border); padding: 12px 0 4px; }
.fields { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.fields input { width: 140px; }
.fields select { width: 260px; max-width: 100%; }
.error { color: var(--danger); }

body.dragging main { outline: 2px dashed var(--accent); outline-offset: 8px; }

/* Positions filter: a dropdown of checkboxes */
details.multi { position: relative; }
details.multi summary {
  list-style: none;
  cursor: pointer;
  padding: 5px 28px 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
details.multi summary::-webkit-details-marker { display: none; }
details.multi summary::after { content: '▾'; position: absolute; right: 10px; color: var(--muted); }
.multi-menu {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}
.multi-menu .link { padding: 4px; margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; padding: 4px; cursor: pointer; white-space: nowrap; }
label.check .swatch { margin-right: 0; }

fieldset.apply-to { border: 1px solid var(--border); border-radius: var(--radius); margin: 16px 0 0; padding: 8px 12px; }
fieldset.apply-to legend { color: var(--muted); font-size: 0.85rem; padding: 0 4px; }

fieldset.note-rules { border: 1px solid var(--border); border-radius: var(--radius); margin: 16px 0 0; padding: 8px 12px; }
fieldset.note-rules legend { color: var(--muted); font-size: 0.85rem; padding: 0 4px; }
.note-rule { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.note-rule input[name="rule-text"] { flex: 1; min-width: 0; }
.note-rule input[name="rule-amount"] { width: 100px; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }

.fields input.wide { width: 320px; max-width: 100%; }

.tag { font-size: 0.75rem; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
/* Shifts table: long names wrap, the note sits under the position, and the edit/delete buttons
   stay pinned to the right edge when the table has to scroll on narrow screens. */
table.shifts th, table.shifts td { padding: 6px 8px; }
table.shifts td.wrap { white-space: normal; min-width: 120px; }
table.shifts .note { font-size: 0.8rem; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { position: sticky; right: 0; background: var(--surface); white-space: nowrap; text-align: right; }
tr.unrated td.row-actions { color: inherit; }
button.icon { border: none; background: none; padding: 4px; line-height: 0; color: var(--muted); border-radius: 6px; }
button.icon:hover { background: var(--bg); }
.svg-icon { display: block; }
button.icon:hover { color: var(--accent); }
button.icon.danger { color: var(--danger); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.fields.stacked { flex-direction: column; }
.fields.stacked label { gap: 4px; }
@media (max-width: 1100px) {
  /* The pinned edit/delete column floats over the scrolling table on narrow screens: give it an edge. */
  .row-actions { box-shadow: -10px 0 10px -10px rgb(0 0 0 / 0.5); }
}
