/* cellarhound — design system (plan §12b: hand-rolled, no Node)
   Direction: quiet financial terminal. Warm paper ground, ink text, ONE
   claret accent, hairline rules, tabular numerals. Status is a small dot and
   lowercase words, never a coloured pill. No emoji in the chrome. */

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --line: #eae7e2;
  --line-strong: #ddd9d2;
  --ink: #1b1917;
  --body: #454039;
  --muted: #8a8378;
  --faint: #b5aea2;
  --accent: #7f1d2b;        /* claret */
  --accent-hover: #6b1824;
  --good: #2f7d4f;
  --warn: #a16207;
  --bad: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(27, 25, 23, 0.05);
  --shadow-lift: 0 1px 3px rgba(27, 25, 23, 0.06), 0 4px 16px rgba(27, 25, 23, 0.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--body);
  font: 400 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text",
        "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ------------------------------------------------------------------ header */

header {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 2rem;
  height: 56px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  align-self: center;
}
.ver {
  color: var(--faint);
  font-family: -apple-system, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: .02em;
}

nav { display: flex; gap: .25rem; flex-wrap: wrap; height: 100%; align-items: stretch; }
nav a {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
  padding: 0 .75rem;
  border-top: 2px solid transparent;    /* balances the active underline */
  border-bottom: 2px solid transparent;
  transition: color .12s ease;
}
nav a:hover { color: var(--ink); text-decoration: none; }
nav a.active { color: var(--ink); font-weight: 550; border-bottom-color: var(--accent); }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.env-note { color: var(--faint); font-size: 11.5px; letter-spacing: .01em; white-space: nowrap; }
.logout button {
  background: none; border: 1px solid var(--line-strong); color: var(--muted);
  border-radius: 7px; padding: .3rem .8rem; font-size: 12.5px; font-weight: 500;
  cursor: pointer; box-shadow: none;
}
.logout button:hover { color: var(--ink); border-color: var(--faint); background: none; }

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

main { max-width: 1180px; margin: 0 auto; padding: 2.75rem 2rem 5rem; }

h1 {
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 .3rem;
}
.page-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 2.25rem; }

h2 {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 3rem 0 .35rem;
}
.section-sub { color: var(--muted); font-size: 13px; margin: 0 0 1rem; max-width: 68ch; }
h2 + .table-card, h2 + .pipeline-card, h2 + .chart-card { margin-top: 1rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

.hint { color: var(--muted); font-size: 12.5px; }
.num, .right, td.right, .stat-value { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- stat strip */

.stats {
  display: flex;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0 0 1.25rem;
}
.stat {
  flex: 1 1 160px;
  padding: 1.1rem 1.5rem 1.05rem;
  border-left: 1px solid var(--line);
  min-width: 150px;
}
.stat:first-child { border-left: none; }
.stat-value {
  color: var(--ink);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-top: .3rem;
}
.stat-note { color: var(--faint); font-size: 11px; margin-top: .15rem; }

/* ------------------------------------------------------------------ status */

/* status = dot + quiet lowercase text. classes kept from queries.py */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .42rem;
  font-size: 12.5px;
  font-weight: 480;
  color: var(--muted);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint);
  flex: none;
}
.badge.ok      { color: var(--body); }
.badge.ok::before      { background: var(--good); }
.badge.warn    { color: var(--warn); }
.badge.warn::before    { background: var(--warn); }
.badge.blocked { color: var(--bad); }
.badge.blocked::before { background: var(--bad); }
.badge.todo    { color: var(--faint); }
.badge.live    { color: var(--accent); font-weight: 550; }
.badge.live::before {
  background: var(--accent);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes breathe { 50% { opacity: .35; } }

.status-stack { display: flex; flex-direction: column; gap: .2rem; align-items: flex-start; }

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

.table-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  margin: 0 0 1rem;
}
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: .62rem 1rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13.5px;
}
th:first-child, td:first-child { padding-left: 1.5rem; }
th:last-child, td:last-child { padding-right: 1.5rem; }
th {
  color: var(--muted);
  font-weight: 550;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding-top: .8rem;
  padding-bottom: .55rem;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: #fcfbf9; }
tr.dim td { color: var(--faint); }
tr.dim .badge { color: var(--faint); }
.right { text-align: right; }
td strong { color: var(--ink); font-weight: 550; }

/* ---------------------------------------------------------------- pipeline */

.pipeline-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .6rem 1.5rem;
}
table.pipeline td { border-bottom: none; padding: .55rem .6rem; font-size: 13.5px; }
table.pipeline td:first-child { color: var(--ink); font-weight: 480; padding-left: 0; white-space: nowrap; }
table.pipeline td:last-child { padding-right: 0; }
.bar-cell { width: 52%; }
.bar {
  background: #f1efe9;
  border-radius: 999px;
  height: 5px;
  overflow: hidden;
}
.fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
}

/* ------------------------------------------------------------- live strip */

.live-strip {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 2.5rem;
}

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

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.5rem;
  margin: .75rem 0;
}
.panel p { margin: .25rem 0; }

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  margin: .75rem 0;
}
.empty .empty-title { color: var(--ink); font-weight: 550; font-size: 14px; margin-bottom: .25rem; }

.needs { list-style: none; margin: 0; padding: 0; }
.needs li {
  display: flex; align-items: baseline; gap: .9rem; flex-wrap: wrap;
  padding: .7rem 0; border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.needs li:last-child { border-bottom: none; }
.needs .badge { min-width: 140px; }
.needs strong { color: var(--ink); font-weight: 550; }
.needs .action { color: var(--muted); }

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

button {
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .48rem 1rem;
  font-size: 13px;
  font-weight: 550;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background .12s ease;
  font-family: inherit;
}
button:hover { background: #000; }
button.danger {
  background: none; color: var(--bad);
  border: 1px solid var(--line); box-shadow: none;
  padding: .3rem .7rem; font-size: 12px;
}
button.danger:hover { border-color: var(--bad); background: #fdf3f2; }
form.inline { display: inline; }

input {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  padding: .48rem .85rem;
  font-size: 13.5px;
  font-family: inherit;
  min-width: 280px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder { color: var(--faint); }
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 29, 43, 0.08);
}
.searchbar { display: flex; gap: .6rem; margin: 1.25rem 0 1.75rem; flex-wrap: wrap; }

/* ------------------------------------------------------------------ charts */

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem 1rem;
  margin: .75rem 0;
}
.chart-title { color: var(--ink); font-size: 13.5px; font-weight: 550; margin: 0 0 .75rem; }
canvas { max-width: 100%; }

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

.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.login-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lift);
  padding: 2.5rem 2.25rem;
  display: grid;
  gap: .9rem;
  width: 340px;
}
.login-box h1 { font-size: 18px; text-align: center; margin-bottom: .5rem; }
.login-box input { min-width: 0; }
.login-error { color: var(--bad); font-size: 12.5px; text-align: center; margin: 0; }

@media (max-width: 900px) {
  header { height: auto; padding: .6rem 1rem; flex-wrap: wrap; gap: .75rem; }
  nav { height: auto; }
  nav a { padding: .35rem .6rem; border-bottom-width: 2px; }
  main { padding: 1.5rem 1rem 3rem; }
  .stat { flex-basis: 45%; border-left: none; border-top: 1px solid var(--line); }
}

/* ------------------------------------------------------------- flips board
   Desktop keeps the ledger table. The mobile-only pieces the row carries
   (headroom pill, summary line, meta line, "details" button) are hidden here
   and take over below 720px. */
.star-cell { width: 2rem; }
.star { background: none; border: 0; cursor: pointer; font-size: 1.25rem; line-height: 1;
        color: var(--faint); padding: 0 .2rem; transition: color .15s, transform .1s; }
.star:hover { color: #d9a400; transform: scale(1.15); }
.star.on { color: #e6b400; text-shadow: 0 0 2px rgba(200,150,0,.35); }
.star:disabled { opacity: .5; cursor: progress; }
.lot-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.lot-title { min-width: 0; }
/* the lot column is prose and must not be squeezed by ten numeric columns —
   give it room and let the card scroll sideways on a narrow desktop instead */
.flip-table td.lot-cell { min-width: 22ch; }
.flip-table .lot-note { white-space: normal; max-width: 34ch; }
.table-card:has(.flip-table) { overflow-x: auto; }
.m-headroom, .m-summary, .m-meta, .m-more, .m-showmore-row { display: none; }
.lot-note { margin-top: .15rem; }

.best-deal { padding: 1.1rem 1.4rem; }
.best-label { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.best-title { display: block; font-size: 17px; font-weight: 600; margin: .25rem 0 .75rem; }
.best-numbers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem;
                margin-bottom: .6rem; font-variant-numeric: tabular-nums; }
.best-numbers .k { display: block; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase;
                   color: var(--muted); }
.best-numbers .v { display: block; font-size: 20px; font-weight: 500; color: var(--ink); line-height: 1.2; }
.best-numbers .v.strong { font-weight: 700; }
.best-numbers .v.good { color: var(--good); }
.warn-text { color: var(--warn); }

/* ------------------------------------------------------------- mobile pass
   The flips board and settings are used from a phone during a live sale.
   Below 720px each lot is one glanceable card: title, a headroom pill on the
   right (the number that decides everything), one line with the three figures
   you bid with, one muted meta line, and a "details" tap that opens the full
   ledger. Header/intro/stats compress so lots reach the first screen. */
@media (max-width: 720px) {
  header { padding: .5rem .75rem; gap: .5rem; height: auto; }
  header .ver { display: none; }
  nav { gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap;
        max-width: 100%; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; padding: .5rem .55rem; font-size: 14px; }
  .header-right { display: none; }
  main { padding: .9rem .75rem 3rem; }
  h1 { font-size: 20px; margin-bottom: .35rem; }
  h2 { font-size: 15px; margin: 1.4rem 0 .5rem; }
  h2 + .table-card { margin-top: .5rem; }
  .page-sub { margin-bottom: 1rem; }
  .flips-intro { display: none; }

  /* stats: one tight strip, four numbers */
  .flips-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: .9rem; }
  .flips-stats .stat { flex: none; min-width: 0; padding: .6rem .75rem; border: 0;
                       border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
  .flips-stats .stat:nth-child(-n+2) { border-top: 0; }
  .flips-stats .stat:nth-child(odd) { border-left: 0; }
  .flips-stats .stat-value { font-size: 20px; }
  .flips-stats .stat-label { font-size: 10px; letter-spacing: .04em; line-height: 1.2; }
  .flips-stats .stat-note { display: none; }

  .best-deal { padding: .9rem 1rem; margin-bottom: 1rem; }
  .best-title { font-size: 16px; margin-bottom: .6rem; }
  .best-numbers { grid-template-columns: repeat(2, 1fr); gap: .5rem .75rem; }
  .best-numbers .v { font-size: 19px; }

  /* the card */
  .flip-table thead { display: none; }
  .flip-table, .flip-table tbody { display: block; width: 100%; }
  .flip-table tr[data-lot] { display: grid; grid-template-columns: 2rem minmax(0, 1fr);
                             column-gap: .5rem; padding: .8rem .8rem .8rem .55rem;
                             border-bottom: 1px solid var(--line); }
  .flip-table tr[data-lot]:last-of-type { border-bottom: 0; }
  .flip-table td { border: 0; padding: 0; text-align: left; }
  .flip-table td.star-cell { grid-column: 1; grid-row: 1; padding-top: .05rem; }
  .flip-table .star { font-size: 1.55rem; padding: 0; width: 2rem; height: 2rem; line-height: 2rem; }
  .flip-table td.lot-cell { grid-column: 2; grid-row: 1; min-width: 0; }
  .lot-title { font-size: 15px; font-weight: 550; line-height: 1.3; }
  .lot-title .badge { display: inline-block; margin-top: .2rem; }
  .m-headroom { display: flex; flex-direction: column; align-items: flex-end; flex: 0 0 auto;
                font-variant-numeric: tabular-nums; line-height: 1.05; padding-left: .5rem; }
  .m-headroom-pct { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
  .m-headroom-gbp { font-size: 11.5px; color: var(--muted); margin-top: .15rem; }
  .m-headroom.pos .m-headroom-pct { color: var(--good); }
  .m-headroom.neg .m-headroom-pct { color: var(--bad); }
  .m-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .4rem;
               margin-top: .45rem; font-size: 14px; font-variant-numeric: tabular-nums; }
  .m-summary em { font-style: normal; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
                  color: var(--muted); margin-right: .15rem; }
  .m-summary strong { font-weight: 700; }
  .m-summary .sep { color: var(--faint); }
  .m-meta { display: flex; justify-content: space-between; align-items: center; gap: .5rem;
            margin-top: .35rem; font-size: 12px; color: var(--muted); }
  .m-more { display: inline; background: none !important; border: 0 !important; box-shadow: none;
            padding: .1rem .3rem; margin: -.1rem -.3rem; font: inherit; font-size: 12px;
            color: var(--accent); cursor: pointer; border-radius: 0; }
  .lot-note { display: none; }
  .flip-table tr.open .lot-note { display: block; }

  /* full ledger, tucked behind "details" */
  .flip-table td.detail { display: none; grid-column: 2; }
  .flip-table tr.open td.detail { display: flex; justify-content: space-between; gap: .75rem;
                                   font-size: 13px; padding: .12rem 0; }
  .flip-table tr.open td.detail:first-of-type { margin-top: .5rem; padding-top: .5rem;
                                                border-top: 1px dashed var(--line); }
  .flip-table td.detail::before { content: attr(data-label); color: var(--muted); }
  .flip-table td.detail.right { text-align: right; }

  /* caps: past the 50th (deals) / 20th (over-max) row, hidden until "show all" */
  .flip-table tr[data-lot]:nth-of-type(n+51) { display: none; }
  #outbid-body tr[data-lot]:nth-of-type(n+21) { display: none; }
  .flip-table tbody.show-all tr[data-lot] { display: grid; }
  .m-showmore-row { display: block; }
  .m-showmore-row td { display: block; padding: .6rem .8rem; }
  .m-showmore { width: 100%; padding: .6rem; font: inherit; font-size: 13.5px; color: var(--accent);
                background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
                cursor: pointer; }
  .flip-table tr[id$="-empty"] { display: block; }
  .flip-table tr[id$="-empty"] td { display: block; padding: .8rem; }
  .table-card { overflow: visible; }
}
body.focused main { max-width: 1100px; }
