:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --text: #e6e8ec; --muted: #8b93a1; --accent: #4c8dff; --accent2: #2a6795;
  --good: #4caf6a; --good-bg: #14351f; --warn: #e0a63a; --bad: #d9534f;
  --deal: #163a24;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
}
header {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; }
.status { color: var(--muted); font-size: 12px; flex: 1; }
.status .dot { color: var(--good); }
.status .dot.off { color: var(--bad); }
.actions { display: flex; gap: 8px; }
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent2); border-color: var(--accent); }
.bell { position: relative; }
#alertCount { font-weight: 700; }

.tabs { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.tabs button { border-bottom: none; border-radius: 6px 6px 0 0; }
.tabs button.active { background: var(--bg); border-color: var(--line);
  color: var(--accent); font-weight: 600; }

main { padding: 14px 16px 60px; }
.tab { display: none; }
.tab.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 10px; }
.toolbar label { color: var(--muted); font-size: 13px; user-select: none; }
.toolbar .grow { flex: 1; }
input, select {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 5px 7px; font: inherit;
}
input[type=search] { min-width: 220px; }
.muted { color: var(--muted); font-size: 12px; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 9px; text-align: left; border-bottom: 1px solid var(--line);
  vertical-align: top; }
th { background: var(--panel); position: sticky; top: 0; cursor: pointer;
  white-space: nowrap; font-weight: 600; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--panel2); }
tr.deal { background: var(--deal); }
tr.deal:hover { background: #1b4a2e; }
tr.closed { opacity: .5; }

.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 4px;
  background: var(--panel2); }
.lot-title { font-weight: 600; }
.lot-title a { color: var(--text); text-decoration: none; }
.lot-title a:hover { color: var(--accent); }
.lot-cats { color: var(--muted); font-size: 11px; }
.lot-sub { color: var(--muted); font-size: 11px; }

.resale-cell { display: flex; gap: 4px; align-items: center; }
.resale-cell input { width: 62px; text-align: right; }
.ebaylink { font-size: 11px; color: var(--accent); text-decoration: none;
  white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.badge { display: inline-block; padding: 1px 6px; border-radius: 10px;
  font-size: 11px; background: var(--panel2); border: 1px solid var(--line); }
.badge.deal { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.badge.soon { background: #3a2f14; border-color: var(--warn); color: var(--warn); }
.badge.live { background: #3a1430; border-color: #c060a0; color: #e090c8; }

.plan-cell { display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.iconbtn { padding: 3px 6px; font-size: 12px; }
.iconbtn.on { background: var(--accent2); border-color: var(--accent); }

#settings-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px;
  max-width: 760px; margin-bottom: 16px; }
#settings-form label { display: flex; flex-direction: column; gap: 3px;
  font-size: 12px; color: var(--muted); }
#settings-form input { width: 100%; }
#settings-form .full { grid-column: 1 / -1; }

#alerts-panel { position: fixed; right: 14px; top: 56px; width: 380px;
  max-height: 70vh; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; z-index: 40;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); }
#alerts-panel.hidden { display: none; }
.alerts-head { display: flex; gap: 8px; align-items: center; padding: 10px;
  border-bottom: 1px solid var(--line); }
.alerts-head strong { flex: 1; }
#alerts-list { list-style: none; margin: 0; padding: 0; }
#alerts-list li { padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-size: 12px; }
#alerts-list li.unseen { background: var(--panel2); }
#alerts-list .k { font-weight: 700; margin-right: 6px; }

#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--accent2); color: #fff; padding: 10px 16px; border-radius: 8px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; }
.hidden { display: none !important; }

/* auth pages */
.auth-body { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px; }
.auth-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 26px; width: 360px; display: flex;
  flex-direction: column; gap: 12px; }
.auth-card h1 { font-size: 18px; margin: 4px 0 2px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted); }
.auth-card input { width: 100%; padding: 8px; }
.auth-card button { padding: 9px; margin-top: 6px; }
.auth-error { background: #3a1c1c; border: 1px solid var(--bad); color: #f5b5b3;
  padding: 8px 10px; border-radius: 6px; font-size: 13px; }

/* user menu */
.usermenu { position: relative; }
.dropdown { position: absolute; right: 0; top: 110%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; display: flex;
  flex-direction: column; min-width: 160px; overflow: hidden; z-index: 30; }
.dropdown button, .dropdown a { background: none; border: none; text-align: left;
  padding: 9px 12px; color: var(--text); text-decoration: none; font-size: 13px; }
.dropdown button:hover, .dropdown a:hover { background: var(--panel2); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; z-index: 60; }
.modal-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 22px; width: 340px; display: flex;
  flex-direction: column; gap: 12px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

#tab-admin h3 { margin: 22px 0 8px; font-size: 14px; }
.tab-badge { background: var(--bad); color: #fff; border-radius: 10px;
  padding: 0 6px; font-size: 11px; font-weight: 700; margin-left: 2px; }

/* desktop hides the merged auctioneer line inside the lot cell */
.c-lot .lot-sub:last-child { display: none; }

/* ============================ mobile ============================ */
@media (max-width: 760px) {
  body { font-size: 15px; }
  header {
    flex-wrap: wrap; gap: 8px 12px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .brand { font-size: 15px; }
  .status { order: 3; flex-basis: 100%; font-size: 11px; }
  .actions { margin-left: auto; }
  .usermenu #userBtn { max-width: 42vw; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; }

  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 8px 12px 0; flex-wrap: nowrap; }
  .tabs button { flex: 0 0 auto; }

  main { padding: 12px 10px 80px; }
  .toolbar { gap: 8px 12px; }
  .toolbar input[type=search] { min-width: 0; flex: 1 1 100%; }

  /* Deals table -> stacked cards */
  .tablewrap { border: none; overflow: visible; }
  #deals, #deals tbody { display: block; width: 100%; }
  #deals thead { display: none; }
  #deals tr {
    border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px;
    padding: 10px 12px; background: var(--panel);
    display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 12px;
  }
  #deals tr.deal { background: var(--deal); border-color: var(--good); }
  #deals td { display: block; border: none; padding: 0; text-align: left; }

  #deals .c-thumb { flex: 0 0 52px; }
  #deals .c-thumb .thumb { width: 52px; height: 52px; }
  #deals .c-thumb:empty { display: none; }
  #deals .c-lot { flex: 1 1 60%; min-width: 0; }
  #deals .c-lot .lot-sub:last-child { display: block; }
  #deals .c-auction { display: none; }
  #deals .lot-title a { font-size: 15px; }

  /* metric cells: small inline key:value chips that wrap under the title */
  #deals td[data-label] {
    flex: 0 0 auto; font-size: 13px; margin-top: 2px;
  }
  #deals td[data-label]::before {
    content: attr(data-label) ": "; color: var(--muted); font-size: 11px;
  }
  #deals td[data-label] .lot-sub { display: inline; color: var(--muted); }
  #deals td.c-resale {
    flex: 1 1 100%; display: flex; flex-wrap: wrap;
    align-items: center; gap: 8px; margin: 8px 0 2px;
  }
  #deals td.c-resale::before { flex-basis: 100%; }
  #deals td.c-resale .resale-input { width: 96px; height: 36px; font-size: 16px; }
  #deals .ebaylink { font-size: 13px; }
  #deals td.c-closes::before { content: "Closes: "; color: var(--muted); font-size: 11px; }
  #deals td.c-closes { font-weight: 600; }

  #deals .c-plan { flex: 1 1 100%; padding-top: 8px; }
  #deals .plan-cell { gap: 8px; }
  #deals .iconbtn { padding: 8px 16px; font-size: 17px; }

  /* settings + admin forms single column */
  #settings-form { grid-template-columns: 1fr; }
  #tab-admin .toolbar, #admin-newuser { flex-direction: column; align-items: stretch; }
  #tab-admin input, #tab-admin select { width: 100%; }

  #alerts-panel { right: 6px; left: 6px; width: auto; top: 52px; }
  .modal-card { width: 92vw; }
}

@media (display-mode: standalone) {
  header { padding-top: calc(10px + env(safe-area-inset-top)); }
}
