:root {
  --ink: #1c1c1c;
  --ink-soft: #5a5a58;
  --paper: #fafaf8;
  --line: #dddad3;
  --panel: #ffffff;
  --accent: #6b6256;        /* muted stone/taupe, the one accent */
  --accent-soft: #ece8e1;
  --hover: #f5f3ee;         /* row and surface hover */
  --warn: #9c4a3a;          /* delays and errors only */
  --warn-soft: #f3e7e3;
  --warn-hover: #efd9d3;
  --radius: 3px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Roboto Mono", Consolas, monospace;
  --tbl-fs: 12.5px;         /* commission table text size (set by the size control) */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* One focus style for every form control */
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ========== 2. Layout ========== */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.site-header nav { display: flex; align-items: center; gap: 18px; font-size: 14px; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 16px;
}
.brand .dot { color: var(--accent); }
.logo { height: 38px; width: auto; }

.role-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--line);
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
}
/* The commission list uses the full viewport width */
.container:has(.commissions-page) { max-width: none; }

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.commissions-page .page-title { margin-bottom: 8px; }
.page-title h1 { font-size: 20px; margin: 0; }
.page-title .sub { color: var(--ink-soft); font-size: 13px; }

/* ========== 3. Buttons ========== */

.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { opacity: 0.85; text-decoration: none; }
.btn[disabled] { opacity: 0.4; cursor: default; }

.btn-outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-outline:hover { opacity: 1; border-color: var(--ink); background: var(--accent-soft); }

.btn-danger { background: var(--warn); border-color: var(--warn); }

/* Outline button for destructive actions in dense places (table rows) */
.btn-quiet-danger { color: var(--warn); }
.btn-quiet-danger:hover { border-color: var(--warn); background: var(--warn-soft); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ========== 4. Forms ========== */

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.help-text { color: var(--ink-soft); font-size: 12px; }
.errorlist { color: var(--warn); font-size: 12px; padding-left: 0; margin: 4px 0; list-style: none; }

/* Shared by simple stacked forms (login, status, delete) and the commission form */
:is(form.stack, form.commission-form) label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}
:is(form.stack, form.commission-form)
  :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: var(--paper);
}
:is(form.stack, form.commission-form)
  :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea):hover {
  border-color: var(--accent);
}
:is(form.stack, form.commission-form) :is(input, select, textarea):focus { background: var(--panel); }
:is(form.stack, form.commission-form) textarea { min-height: 96px; resize: vertical; }
:is(form.stack, form.commission-form) .has-error
  :is(input:not([type="checkbox"]):not([type="file"]), select, textarea) {
  border-color: var(--warn);
}

form.stack { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }

.commission-form { display: flex; flex-direction: column; gap: 18px; max-width: 820px; }
.commission-form .errorlist { margin: 0; }
.commission-form .req { color: var(--ink-soft); font-weight: 400; margin-left: 2px; }

.form-alert {
  padding: 12px 14px;
  border: 1px solid var(--warn);
  border-left-width: 4px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  font-size: 13.5px;
}
.form-alert strong { display: block; margin-bottom: 2px; }
.form-alert ul { margin: 6px 0 0; padding-left: 18px; }

.form-section { margin-bottom: 0; }
.form-section > h2 { font-size: 14px; margin: 0 0 4px; }
.form-section > .section-note { margin: 0 0 16px; color: var(--ink-soft); font-size: 12.5px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-grid .field--wide { grid-column: 1 / -1; }

/* Checkbox fields: control and label on one line */
.form-grid .field--check { flex-direction: row; align-items: center; gap: 8px; }
.form-grid .field--check label { order: 2; font-weight: 400; cursor: pointer; }
.form-grid .field--check input { order: 1; width: 16px; height: 16px; margin: 0; }

/* Attachment: Django's ClearableFileInput output */
.file-box {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 13.5px;
  line-height: 1.9;
}
.file-box:focus-within { border-color: var(--accent); border-style: solid; }
.file-box a { text-decoration: underline; word-break: break-all; }
.file-box a:hover { text-decoration: none; }
.file-box input[type="file"] {
  max-width: 100%;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink-soft);
}
.file-box input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.file-box input[type="file"]::file-selector-button:hover {
  border-color: var(--ink);
  background: var(--accent-soft);
}
.file-box input[type="checkbox"] { width: 15px; height: 15px; margin: 0 6px 0 0; vertical-align: middle; }
.file-box input[type="checkbox"] + label {
  font-weight: 400;
  color: var(--ink-soft);
  cursor: pointer;
  vertical-align: middle;
}

.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-actions--bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: 0;
  padding: 12px 0;
  background: var(--paper);
  border-top: 1px solid var(--line);
  align-items: center;
}
.form-actions--bar .btn { min-height: 38px; padding: 8px 18px; }

/* ========== 5. Filter bar ========== */

.filter-bar {
  display: flex;
  gap: 10px 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filter-bar .field { gap: 4px; }
.filter-bar .field--search { flex: 1 1 240px; }
.filter-bar .field--search input { width: 100%; }
.filter-bar label {
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.filter-bar input, .filter-bar select {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--paper);
  color: var(--ink);
}

/* ========== 6. Commission table ========== */

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.text-size { display: flex; align-items: center; gap: 6px; }
.text-size .fs-label { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
.text-size .btn { min-width: 30px; line-height: 1; font-weight: 700; }

/* Top bar: [title] [Filter] ........ [count + text size] [New] */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.top-bar .bar-title { font-size: 15px; margin: 0 4px 0 0; white-space: nowrap; flex: 0 0 auto; }
.top-bar .btn {
  height: 30px;
  padding: 0 12px;
  font-size: 12.5px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.filter-toggle { position: relative; }
.filter-toggle.is-open { background: var(--accent-soft); border-color: var(--ink); }
.filter-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn);
}
.top-bar .bar-tools {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
  font-size: 12.5px; color: var(--ink-soft); white-space: nowrap;
}
/* no filter-toggle gap trick needed: tools push right; if absent, New does */
.top-bar .bar-new { flex: 0 0 auto; }
.top-bar > .bar-new:nth-child(3) { margin-left: auto; }
.top-bar .text-size { gap: 4px; }
.top-bar .text-size .btn { min-width: 30px; padding: 0; }
.top-bar .text-size .fs-label { min-width: 38px; }

/* Collapsible filter panel (second line) */
.filter-panel[hidden] { display: none; }
.filter-panel { align-items: flex-end; gap: 10px 12px; padding: 8px 10px; margin-bottom: 8px; }
.filter-panel .field--search { flex: 1 1 260px; max-width: 420px; }
.filter-panel select { min-width: 160px; }
.filter-panel input, .filter-panel select { height: 30px; padding: 0 8px; }
.filter-panel .btn { height: 30px; display: inline-flex; align-items: center; }

@media (max-width: 1000px) {
  .top-bar .bar-tools .count,
  .top-bar .text-size-label { display: none; }
}
@media (max-width: 900px) {
  .top-bar { flex-wrap: wrap; }
  .top-bar .bar-title { flex: 1 1 100%; }
  .top-bar .bar-tools { margin-left: 0; }
  .filter-panel .field { flex: 1 1 100%; }
  .filter-panel .field--search { max-width: none; }
}

/* Scroll region: header and key columns stay in view */
.table-wrap {
  min-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

table.commission-table {
  width: 100%;
  table-layout: fixed;          /* widths come from <col>, declared in em */
  border-collapse: separate;    /* keeps borders on sticky cells */
  border-spacing: 0;
  font-size: var(--tbl-fs);
}
table.commission-table--admin { min-width: 127em; }
table.commission-table--staff { min-width: 111em; }

table.commission-table th,
table.commission-table td {
  padding: 4px 8px;
  text-align: left;
  vertical-align: middle;
  overflow-wrap: break-word;
  border-bottom: 1px solid var(--line);
}
table.commission-table tbody tr:last-child td { border-bottom: 0; }

table.commission-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--accent-soft);
  font-size: 0.86em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  font-weight: 600;
}
table.commission-table th a { color: inherit; }
table.commission-table th a:hover { color: var(--ink); }

td.nowrap-cell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* Row state is a variable so sticky cells always get an opaque background */
table.commission-table tbody tr { --row-bg: var(--panel); }
table.commission-table tbody tr:hover { --row-bg: var(--hover); }
table.commission-table tbody tr.delayed { --row-bg: var(--warn-soft); }
table.commission-table tbody tr.delayed:hover { --row-bg: var(--warn-hover); }
table.commission-table tbody td { background: var(--row-bg); }

/* Sticky first and last columns */
table.commission-table .col-first,
table.commission-table .actions-cell,
table.commission-table thead .col-last { position: sticky; z-index: 1; }
table.commission-table .col-first { left: 0; font-weight: 600; box-shadow: 1px 0 0 var(--line); }
table.commission-table .actions-cell,
table.commission-table thead .col-last { right: 0; }
table.commission-table .actions-cell { box-shadow: -1px 0 0 var(--line); }
table.commission-table thead .col-first,
table.commission-table thead .col-last { z-index: 3; }

/* Delayed rows: left edge marker plus the DELAYED text (not colour alone) */
table.commission-table tr.delayed td.col-first {
  box-shadow: inset 3px 0 0 var(--warn), 1px 0 0 var(--line);
}

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 0.95em;
  border: 1px solid var(--line);
  background: var(--accent-soft);
  color: var(--ink);
  overflow-wrap: break-word;
}
.delay-flag {
  display: block;
  margin-top: 2px;
  color: var(--warn);
  font-weight: 600;
  font-size: 0.85em;
  white-space: nowrap;
}

.row-actions { display: flex; padding-left: 0px; gap: 4px; }
.row-actions .btn { padding: 3px 8px; font-size: 1em; line-height: 1.4; white-space: nowrap; }

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

/* ========== 7. Panels, details, logs, messages, login ========== */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 24px; }
.detail-grid .item dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 3px;
}
.detail-grid .item dd { margin: 0; font-size: 14.5px; }

.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th, .log-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.log-table th { color: var(--ink-soft); font-size: 11px; text-transform: uppercase; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  font-size: 13.5px;
  margin-bottom: 8px;
}

.login-wrap {
  max-width: 360px;
  margin: 80px auto;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-wrap h1 { font-size: 18px; margin-top: 0; }

/* ========== 8. Utilities ========== */

.muted { color: var(--ink-soft); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ========== Full-page commission list (desktop) ========== */
@media (min-width: 901px) {
  body:has(.commissions-page) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .container:has(.commissions-page) {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 10px 16px;
  }
  .commissions-page {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .commissions-page > * { flex-shrink: 0; }
  .commissions-page > .table-wrap { flex: 1 1 auto; min-height: 0; }
  .commissions-page > .empty-state { overflow: auto; }
}

/* ========== Logout button (red) ========== */
.site-header a[href*="logout"],
.site-header button[name="logout"],
.site-header form[action*="logout"] button,
.logout-btn {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid #c62828;
  border-radius: var(--radius);
  background: #c62828;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.site-header a[href*="logout"]:hover,
.site-header button[name="logout"]:hover,
.site-header form[action*="logout"] button:hover,
.logout-btn:hover {
  background: #a31f1f;
  border-color: #a31f1f;
  text-decoration: none;
}

/* ========== Profile menu ========== */
.profile-menu { position: relative; }
.profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  user-select: none;
}
.profile-btn::-webkit-details-marker { display: none; }
.profile-btn::marker { content: ""; }
.profile-menu[open] .profile-btn { border-color: var(--ink); background: var(--accent-soft); }
.avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.profile-name { font-weight: 600; }
.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 180px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
.profile-info { display: flex; flex-direction: column; gap: 1px; padding: 2px 4px 10px; margin-bottom: 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.profile-info .muted { font-size: 12px; }
.profile-dropdown form { margin: 0; }
.profile-dropdown .logout-btn { width: 100%; text-align: center; }

/* ========== 9. Responsive ========== */

@media (max-width: 900px) {
  /* Commission table becomes one card per commission */
  .table-toolbar .text-size { display: none; }
  .table-wrap { max-height: none; min-height: 0; overflow: visible; border: 0; background: transparent; }

  table.commission-table--admin,
  table.commission-table--staff { min-width: 0; }

  table.commission-table { font-size: max(var(--tbl-fs), 14px); }
  table.commission-table colgroup,
  table.commission-table thead { display: none; }
  table.commission-table,
  table.commission-table tbody,
  table.commission-table tr { display: block; width: 100%; }

  table.commission-table tbody tr {
    margin-bottom: 10px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--row-bg);
  }
  table.commission-table tbody tr.delayed { border-left: 3px solid var(--warn); }

  table.commission-table tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    border: 0;
    background: transparent;
    text-align: right;
  }
  table.commission-table td.is-empty { display: none; }
  table.commission-table td.nowrap-cell { overflow: visible; text-overflow: clip; }
  table.commission-table td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    flex-shrink: 0;
    color: var(--ink-soft);
    font-weight: 400;
  }

  /* Card header: the commission name */
  table.commission-table td.col-first {
    position: static;
    justify-content: flex-start;
    margin-bottom: 4px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
    font-size: 1.15em;
    box-shadow: none !important;
  }
  table.commission-table td.col-first::before { display: none; }

  table.commission-table td.actions-cell {
    position: static;
    justify-content: flex-start;
    margin-top: 4px;
    box-shadow: none;
  }
  .row-actions { justify-content: flex-start; }
  .row-actions .btn { padding: 6px 12px; }
}

@media (max-width: 720px) {
  .container { padding: 16px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions--bar { flex-wrap: wrap; }
  .form-actions--bar .btn { flex: 1 1 auto; text-align: center; }
}

table.commission-table th { overflow-wrap: normal; word-break: normal; }