:root {
  --bg: #f4f1e8;
  --panel: #ffffff;
  --ink: #12161f;
  --ink-panel: #171c27;
  --muted: #656e7d;
  --line: #e1dccb;
  --brass: #a6813c;
  --blue: #1f3b57;
  --green: #1c7a4d;
  --red: #b3231c;
  --font-sans: "IBM Plex Sans", Arial, Helvetica, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
}

a { color: inherit; }

table {
  font-variant-numeric: tabular-nums;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 250px;
  background: var(--ink-panel);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  padding: 0 6px;
}

.brand-seal {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 999px;
  border: 1.5px solid var(--red);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 0.02em;
  transform: rotate(-8deg);
}

.brand-word {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.sidebar nav {
  display: grid;
  gap: 2px;
  flex: 1;
}

.nav-divider {
  margin: 14px 6px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
}

.sidebar nav a {
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 6px;
  color: rgba(238, 243, 248, 0.78);
  font-size: 13.5px;
  font-weight: 500;
  border-left: 2px solid transparent;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.sidebar nav a.active {
  background: rgba(179, 35, 28, 0.16);
  border-left-color: var(--red);
  color: white;
  font-weight: 600;
}

.userbox {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  gap: 10px;
}

.userbox-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.userbox-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 999px;
  background: rgba(166, 129, 60, 0.25);
  color: var(--brass);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.userbox strong {
  color: white;
  font-size: 13.5px;
  display: block;
}

.role-pill {
  display: inline-block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.userbox a {
  text-decoration: none;
  color: rgba(238, 243, 248, 0.7);
  font-size: 12.5px;
  padding: 2px;
}

.userbox a:hover {
  color: white;
}

/* ---------- content shell ---------- */

.content {
  margin-left: 250px;
  padding: 30px 32px;
}

.login-content {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.panel,
.metric,
.split > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.page-head {
  margin-bottom: 22px;
}

.action-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.page-head h1 {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.page-head p,
.muted {
  margin: 0;
  color: var(--muted);
}

.form,
.settings-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea,
button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font: inherit;
  font-family: var(--font-sans);
  background: var(--panel);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 59, 87, 0.12);
}

button {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  cursor: pointer;
  font-weight: 700;
  transition: background 120ms ease, transform 120ms ease;
}

button:hover {
  background: #17293e;
}

button:active {
  transform: scale(0.98);
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

button.small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.metric-grid.wide {
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
}

.metric {
  padding: 16px;
  display: grid;
  gap: 8px;
  border-top: 2px solid var(--brass);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.metric strong {
  font-family: var(--font-mono);
  font-size: 23px;
  font-weight: 600;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.split.lower {
  margin-top: 18px;
}

.split > div,
.panel {
  padding: 16px;
}

.panel {
  margin-bottom: 18px;
}

.panel h2,
.split h2 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

summary {
  cursor: pointer;
  font-weight: 700;
  margin-bottom: 12px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.field-hint {
  display: grid;
  gap: 4px;
}

.field-hint span {
  color: var(--muted);
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
}

td {
  font-size: 13.5px;
}

th {
  background: #f7f4ec;
  border-bottom: 2px solid var(--brass);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

tbody tr:hover {
  background: #faf8f2;
}

.flash-list {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  padding: 10px 12px;
  border-radius: 6px;
  background: #f7f4ec;
  border: 1px solid var(--line);
  font-size: 13.5px;
}

.flash.success {
  border-color: #9ed9b5;
  color: var(--green);
  background: #f2faf5;
}

.flash.error {
  border-color: #f0b6b0;
  color: var(--red);
  background: #fdf3f2;
}

.commission-settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.settings-form {
  max-width: 760px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

@media (max-width: 900px) {
  .sidebar {
    position: static;
    width: auto;
    padding: 12px;
  }

  .sidebar nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar nav a {
    white-space: nowrap;
    border-left: none;
    border-bottom: 2px solid transparent;
  }

  .sidebar nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--red);
  }

  .nav-divider {
    display: none;
  }

  .userbox {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .content {
    margin-left: 0;
    padding: 16px;
  }

  .split,
  .action-head {
    grid-template-columns: 1fr;
    display: grid;
  }

  table {
    display: block;
    overflow-x: auto;
  }

  .page-head h1 {
    font-size: 20px;
  }

  .period-tabs,
  .search-form {
    flex-wrap: wrap;
  }

  .search-form input {
    max-width: none;
    flex: 1 1 auto;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .content {
    padding: 12px;
  }

  .metric-grid,
  .metric-grid.wide {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}

.calc-box {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f4ec;
  padding: 7px 10px;
  display: grid;
  gap: 2px;
}

.calc-box span {
  color: var(--muted);
  font-size: 12px;
}

.calc-box strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
}

.icon-danger {
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  border-color: #f0b6b0;
  background: #fdf3f2;
  color: var(--red);
  font-weight: 800;
}

.icon-danger:hover {
  background: var(--red);
  color: white;
}

.note-form {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.note-form textarea {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
  resize: vertical;
}

.payment-form {
  display: grid;
  grid-template-columns: minmax(90px, 120px) minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.lower-panel {
  margin-top: 18px;
}

button:disabled,
input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .payment-form {
    grid-template-columns: 1fr;
  }
}

.small-link {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--blue);
  align-self: center;
  text-decoration: none;
}

.small-link:hover {
  text-decoration: underline;
}

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-form input {
  max-width: 320px;
}

.period-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.period-tabs a {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}

.period-tabs a.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eef4fb;
}

/* Login screen styling lives in static/login.css (loaded only on /login). */
