* { box-sizing: border-box; margin: 0; }

:root {
  --bg: #f6f3ef;
  --panel: #ffffff;
  --panel-2: #fbf8f5;
  --ink: #221a17;
  --muted: #8a7b74;
  --line: #eadfd9;
  --line-strong: #dcccc4;
  --accent: #c31f26;
  --accent-dark: #8e1013;
  --accent-soft: #fbeeed;
  --green: #2e7d43;
  --green-soft: #e5f2e8;
  --red: #b23b2e;
  --amber: #9a7500;
  --amber-soft: #f7edd4;
  --blue: #2d5f8a;
  --blue-soft: #e3edf5;
  --shadow-sm: 0 1px 2px rgba(60, 20, 15, 0.06), 0 1px 3px rgba(60, 20, 15, 0.05);
  --shadow-md: 0 6px 18px rgba(60, 20, 15, 0.10);
  --shadow-lg: 0 20px 60px rgba(40, 12, 8, 0.28);
  --radius: 14px;
}

html { scroll-padding-top: 90px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image: linear-gradient(180deg, #ece2d7, var(--bg));
  background-repeat: no-repeat;
  background-size: 100% 360px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

/* ---------- header: dark command bar ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 10px 28px;
  background: linear-gradient(180deg, rgba(45, 33, 27, 0.97), rgba(26, 18, 15, 0.97));
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-top: 4px solid var(--accent);
  box-shadow: 0 8px 24px rgba(30, 15, 10, 0.22);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { height: 46px; width: auto; filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.4)); }
.brand h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 21px;
  letter-spacing: 0.02em;
  color: #f6ede5;
  white-space: nowrap;
}
.brand h1 span { font-weight: 400; color: #cdb8ab; }

nav { display: flex; gap: 3px; flex-wrap: wrap; }
nav button {
  border: none;
  background: none;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  color: #c9b5a8;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
nav button:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
nav button.active {
  background: linear-gradient(180deg, #e0342f, var(--accent-dark));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.3);
}

main { max-width: 1140px; margin: 0 auto; padding: 26px 28px 96px; }

.hidden { display: none !important; }

/* ---------- typography ---------- */

h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 18px;
}
h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
}
h3::before {
  content: '';
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), #e0342f);
  flex: none;
}
dialog h3::before, .login-overlay h3::before { display: none; }
h4 {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
}
.sub { color: var(--muted); font-size: 13px; }

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.view-head h2 { margin-bottom: 0; }
.head-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.range-sep { color: var(--muted); font-size: 13px; }
.report-scope { margin: -6px 0 12px; }

/* ---------- controls ---------- */

button, select, input, textarea { font: inherit; color: inherit; }

button {
  padding: 8px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s, background 0.15s;
}
button:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
button:active { transform: translateY(1px); box-shadow: none; }
button.primary {
  background: linear-gradient(180deg, #e0342f, var(--accent-dark));
  border-color: var(--accent-dark);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
button.primary:hover { background: var(--accent-dark); }
button.small { padding: 4px 11px; font-size: 13px; border-radius: 8px; }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); }

select, input, textarea {
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(195, 31, 38, 0.15);
}
nav button:focus-visible, button.link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: none;
}
input[type="search"] { min-width: 190px; }

/* ---------- stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  box-shadow: var(--shadow-sm);
}
.stat .label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.stat .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 5px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat.drill { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s; }
.stat.drill:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}
.stat.drill:hover .label { color: var(--accent); }
tr.drill { cursor: pointer; }
tr.drill:hover td { background: var(--accent-soft); }

/* semantic money coloring */
.stat.good .value { color: var(--green); }
.stat.warn .value { color: var(--amber); }
.stat.urgent .value { color: var(--accent-dark); }

/* view entrance */
.view.entering { animation: viewin 0.24s ease; }
.view.entering .stat { animation: rise 0.4s ease backwards; }
.view.entering .stat:nth-child(2) { animation-delay: 40ms; }
.view.entering .stat:nth-child(3) { animation-delay: 80ms; }
.view.entering .stat:nth-child(4) { animation-delay: 120ms; }
.view.entering .stat:nth-child(5) { animation-delay: 160ms; }
.view.entering .stat:nth-child(6) { animation-delay: 200ms; }
.view.entering .stat:nth-child(7) { animation-delay: 240ms; }
.view.entering .stat:nth-child(8) { animation-delay: 280ms; }
.view.entering .stat:nth-child(n+9) { animation-delay: 320ms; }
.view.entering .panel { animation: rise 0.45s ease backwards; animation-delay: 140ms; }
@keyframes viewin { from { opacity: 0; transform: translateY(8px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ---------- layout panels ---------- */

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 940px) { .two-col { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

/* ---------- tables ---------- */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
}
.table-scroll table { min-width: 100%; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel table { box-shadow: none; }
th, td {
  text-align: left;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: top;
}
th {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 2px solid var(--line-strong);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td, table tr:hover td { background: var(--panel-2); }
table tr:hover th { background: transparent; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.open, .badge.upcoming, .badge.unpaid, .badge.partial, .badge.owed { background: var(--amber-soft); color: var(--amber); }
.badge.live, .badge.sold, .badge.paid { background: var(--green-soft); color: var(--green); }
.badge.closed, .badge.passed, .badge.void { background: #efe9e4; color: var(--muted); }
.badge.exempt, .badge.qty { background: var(--blue-soft); color: var(--blue); }
.badge.exempt::before, .badge.qty::before { display: none; }

/* ---------- misc content ---------- */

.empty {
  padding: 40px 28px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  font-size: 15px;
}

.form-grid { display: grid; gap: 12px; }
.form-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; color: var(--ink); }

label.check {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
label.check input { width: auto; accent-color: var(--accent); }

details.bids { margin-top: 6px; }
details.bids summary { cursor: pointer; font-size: 13px; color: var(--accent-dark); font-weight: 500; }
details.bids summary:hover { color: var(--accent); }
.bid-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.bid-row.pay { color: var(--green); }
.invoice-lines { margin: 6px 0 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

/* proportional meter bars (single-hue magnitude) */
.meter {
  margin-top: 5px;
  height: 6px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
  max-width: 260px;
}
.meter span {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
  transition: width 0.3s ease;
}
.meter-table td { vertical-align: middle; }

/* ---------- dialogs ---------- */

dialog {
  margin: auto;
  border: none;
  border-radius: 16px;
  padding: 24px;
  width: min(460px, 92vw);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(35, 18, 14, 0.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
dialog h3 {
  color: var(--ink);
  text-transform: none;
  font-size: 18px;
  letter-spacing: 0;
  margin-bottom: 14px;
  font-weight: 700;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

#detail { width: min(800px, 95vw); max-height: 88vh; overflow-y: auto; }
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.detail-head h3 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 22px;
  margin: 0;
}
#detail h4 { margin: 20px 0 8px; }
#detail table { font-size: 13px; box-shadow: none; }
.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px 18px;
  margin-bottom: 14px;
  font-size: 14px;
}
.kv .label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.detail-stats { margin-bottom: 4px; }
.detail-stats .stat { padding: 10px 12px; box-shadow: none; }
.detail-stats .value { font-size: 20px; }

/* ---------- global search ---------- */

.global-search { position: relative; flex: 1; max-width: 360px; min-width: 210px; }
.global-search input {
  width: 100%;
  border-radius: 999px;
  padding-left: 15px;
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  box-shadow: none;
}
.global-search input::placeholder { color: #b6a294; }
.global-search input:hover { border-color: rgba(255, 255, 255, 0.4); }
.global-search input:focus {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(195, 31, 38, 0.3);
}
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 440px;
  overflow-y: auto;
  z-index: 60;
}
.search-group {
  padding: 9px 13px 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.search-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  padding: 7px 13px;
  background: none;
  font-size: 14px;
  box-shadow: none;
}
.search-item:hover { background: var(--accent-soft); box-shadow: none; }
.search-item .sub { font-size: 12px; }

button.link {
  border: none;
  background: none;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  color: var(--accent-dark);
  text-decoration: underline;
  text-decoration-color: rgba(195, 31, 38, 0.3);
  text-underline-offset: 2px;
  cursor: pointer;
  box-shadow: none;
}
button.link:hover { color: var(--accent); box-shadow: none; }

/* ---------- clerk ---------- */

.clerk-progress {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.clerk-card { border-top: 4px solid var(--accent); box-shadow: var(--shadow-md); }
.clerk-lotnum { font-size: 13px; font-weight: 800; letter-spacing: 0.14em; color: var(--accent); }
.clerk-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 30px;
  font-weight: 700;
  margin: 5px 0 6px;
}
.clerk-meta { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-bottom: 18px; }
.clerk-meta .highbid { color: var(--green); font-weight: 600; }
.clerk-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.clerk-form label { display: grid; gap: 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.clerk-form input { font-size: 26px; width: 160px; padding: 10px 12px; font-variant-numeric: tabular-nums; }
button.big { font-size: 20px; padding: 13px 28px; border-radius: 12px; }

/* ---------- login ---------- */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.login-overlay .panel { width: min(340px, 90vw); box-shadow: var(--shadow-md); }
.login-overlay input[name="pin"] { font-size: 22px; text-align: center; letter-spacing: 0.3em; }
#login-error { color: var(--red); text-align: center; }

/* ---------- demo banner ---------- */

.demo-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 9px 16px;
  background: rgba(34, 26, 23, 0.94);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 13px;
  z-index: 40;
}
.demo-banner button {
  padding: 3px 11px;
  font-size: 12px;
  background: none;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: none;
}
.demo-banner button:hover { border-color: #fff; box-shadow: none; }

/* ---------- audit log ---------- */

.audit { max-height: 420px; overflow-y: auto; font-size: 13px; }
.audit-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.audit-row .sub { margin-right: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 90;
  box-shadow: var(--shadow-lg);
}
.toast.error { background: var(--red); }

/* ---------- small screens ---------- */

@media (max-width: 700px) {
  html { scroll-padding-top: 110px; }
  body { overflow-x: hidden; }

  /* compact sticky header: logo + search on one row, nav as one scrollable row */
  header { padding: 8px 12px 0; gap: 8px 10px; }
  .brand h1 { display: none; }
  .brand .logo { height: 36px; }
  .global-search { flex: 1; min-width: 0; max-width: none; }
  .global-search input { padding: 7px 14px; }
  nav {
    flex: 1 0 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 8px;
  }
  nav::-webkit-scrollbar { display: none; }
  nav button { white-space: nowrap; padding: 6px 12px; }

  main { padding: 18px 12px 130px; }
  h2 { font-size: 23px; margin-bottom: 14px; }

  /* prevent iOS auto-zoom on focus */
  input, select, textarea { font-size: 16px; }

  /* filter rows become tidy full-width stacks */
  .head-controls { width: 100%; }
  .head-controls select,
  .head-controls input:not([type="date"]) { flex: 1 1 150px; min-width: 0; }
  .head-controls input[type="date"] { flex: 1 1 130px; min-width: 0; }
  input[type="search"] { min-width: 0; }

  th, td { padding: 8px 10px; font-size: 13px; }
  .stat { padding: 13px 13px 11px; }
  .stat .value { font-size: 22px; }

  .clerk-form { gap: 10px; }
  .clerk-form label { flex: 1 1 40%; }
  .clerk-form input { width: 100%; font-size: 24px; }
  .clerk-form button.big { flex: 1 1 auto; }
  .clerk-title { font-size: 25px; }

  .detail-head h3 { font-size: 19px; }
  .demo-banner { font-size: 12px; padding: 8px 10px; }

  /* nav: fade hints there's more to swipe; active tab auto-centers via JS */
  nav {
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 28px), transparent);
  }

  /* thumb-sized touch targets */
  button.small { padding: 8px 14px; font-size: 14px; border-radius: 9px; }
  button.link { padding: 2px 0; }

  /* search results become a full-width sheet under the header */
  .search-results {
    position: fixed;
    left: 10px;
    right: 10px;
    top: 60px;
    max-height: 62vh;
  }
  .search-item { padding: 11px 14px; }

  /* dialogs become bottom sheets */
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px calc(22px + env(safe-area-inset-bottom));
  }
  dialog[open] { animation: sheet-up 0.22s ease; }
  #detail { width: 100%; max-height: 90vh; }
  .modal-actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 10px; }
  .modal-actions button { flex: 1; padding: 12px; }

  /* toast clears the demo banner */
  .toast {
    left: 12px;
    right: 12px;
    bottom: 88px;
    transform: none;
    text-align: center;
  }

  /* ---- wide tables become card stacks ---- */
  .table-scroll { overflow: visible; border-radius: 0; }
  .table-scroll:has(> table:not(.rtable)) { overflow-x: auto; }
  .rtable {
    display: block;
    border: none;
    background: none;
    box-shadow: none;
    min-width: 0 !important;
  }
  .rtable tbody { display: block; }
  .rtable tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
  }
  .rtable tr:first-child { display: none; } /* header row */
  .rtable td {
    display: block;
    border: none;
    padding: 4px 0;
    background: none !important;
    font-size: 14px;
  }
  .rtable td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 1px;
  }
  .rtable td.num { text-align: left; }
  .rtable td.actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    text-align: left;
    padding-top: 10px;
    margin-top: 6px;
    border-top: 1px dashed var(--line);
    white-space: normal;
  }
  .rtable td.actions:empty { display: none; }
  .rtable td:empty { display: none; }
}

@keyframes sheet-up {
  from { transform: translateY(28px); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}
