*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #080c11;
  --bg-card:      #161b22;
  --bg-surface:   #0d1117;
  --border:       #30363d;
  --text:         #e6edf3;
  --text-head:    #f0f6fc;
  --text-label:   #8b949e;
  --text-muted:   #6e7681;
  --text-log:     #8b949e;
  --text-log-info:#e6edf3;
  --btn-clear-bg: #30363d;
  --btn-clear-fg: #8b949e;
  --date-scheme:  dark;
  --date-filter:  invert(0.6);
  --shadow:       0 4px 20px rgba(0, 0, 0, 0.55), 0 1px 4px rgba(0, 0, 0, 0.35);
}

body.light {
  --bg:           #e8ecf0;
  --bg-card:      #ffffff;
  --bg-surface:   #f6f8fa;
  --border:       #d0d7de;
  --text:         #24292f;
  --text-head:    #1f2328;
  --text-label:   #57606a;
  --text-muted:   #8c959f;
  --text-log:     #57606a;
  --text-log-info:#24292f;
  --btn-clear-bg: #eaeef2;
  --btn-clear-fg: #57606a;
  --date-scheme:  light;
  --date-filter:  none;
  --shadow:       0 4px 20px rgba(0, 0, 0, 0.10), 0 1px 4px rgba(0, 0, 0, 0.06);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 28px 24px;
  transition: background 0.2s, color 0.2s;
}

/* ── Header card ── */

.header-card {
  padding: 16px 20px 0;
  margin-bottom: 16px;
}

/* ── Top bar ── */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

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

.logo {
  height: 52px;
  width: auto;
  filter: brightness(0) invert(1);
}

body.light .logo {
  filter: none;
}

h1 { font-size: 1.35rem; font-weight: 600; color: var(--text-head); }

#david-toggle {
  background: var(--btn-clear-bg);
  color: var(--text-label);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
#david-toggle:hover { opacity: 0.8; }

/* ── Tabs ── */

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: none;
  margin-bottom: 0;
}

.tab-btn {
  padding: 8px 18px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover:not(:disabled) { color: var(--text); opacity: 1; }
.tab-btn.active { color: var(--text-head); border-bottom-color: #58a6ff; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Card ── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

/* ── Form ── */

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-label);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"] {
  display: block;
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.9rem;
  margin-bottom: 14px;
  transition: border-color 0.15s, background 0.2s, color 0.2s;
}

input[type="date"] {
  color-scheme: var(--date-scheme);
  cursor: pointer;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: var(--date-filter);
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

input:focus { outline: none; border-color: #58a6ff; }
input:disabled { opacity: 0.4; cursor: not-allowed; }

.form-row { display: grid; gap: 14px; margin-bottom: 14px; }
.main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.left-stack { display: flex; flex-direction: column; gap: 14px; }

.field-group-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 14px;
}
.field-group-row > div { flex: 1; }
.field-group-row .time-input { width: fit-content; }

#markup-hint, #first-bid-hint, .field-hint {
  color: #3fb950;
  font-size: 0.68rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.field-hint { color: var(--text-muted, #8b949e); }

#markup-hint.low-margin {
  color: #f85149;
}

.form-row input,
.form-row .time-input { margin-bottom: 0; }
.form-row label { margin-bottom: 6px; }

.time-input {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  transition: border-color 0.15s, background 0.2s;
}
.time-input:focus-within { border-color: #58a6ff; }
.time-input input {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
  background: transparent;
  border: none;
  padding: 0;
  text-align: center;
  color: var(--text);
  font-size: 0.9rem;
}
.time-input input:focus { outline: none; border-color: transparent; }
.time-sep {
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Buttons ── */

.btn-row { display: flex; gap: 10px; margin-top: 4px; }

button {
  padding: 9px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

button:disabled { opacity: 0.35; cursor: not-allowed; }
button:not(:disabled):hover { opacity: 0.85; }

#start-btn { background: #238636; color: #fff; }
#stop-btn  { background: #b91c1c; color: #fff; }
#clear-btn { background: var(--btn-clear-bg); color: var(--btn-clear-fg); }

/* ── Live status ── */

.section-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #3fb950;
  flex-shrink: 0;
}
.dot.idle { background: var(--text-muted); }
.dot.active { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: background 0.2s, border-color 0.2s;
}

.stat-card .stat-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0;
}

.stat-card .stat-value {
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-card.highlight { border-color: #3fb95044; border-left: 3px solid #3fb950; }
.stat-card.highlight .stat-value { color: #3fb950; }
.stat-card.warn-card { border-left: 3px solid #f0883e; }
.stat-card.warn-card .stat-value { color: #f0883e; }
.stat-card.blue-card { border-left: 3px solid #58a6ff; }
.stat-card.blue-card .stat-value { color: #58a6ff; }
.stat-card.done-card { border-left: 3px solid #3fb950; }
.stat-card.done-card .stat-value { color: #3fb950; }

/* ── Mode toggle (Counter-bid / Snipe) ─────────────────────────────────── */
.mode-toggle {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 4px 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover:not(:disabled):not(.active) { color: var(--text); }
.mode-btn.active { background: var(--bg); color: var(--text-head); box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.mode-btn:disabled { cursor: default; opacity: 0.6; }

.snipe-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  align-self: flex-end;
}

.lead-hint {
  font-size: 0.78rem;
  font-weight: 500;
  color: #58a6ff;
  margin-left: 6px;
}

/* ── Snipe live status ─────────────────────────────────────────────────── */
#snipe-status { display: flex; flex-direction: column; gap: 12px; }
.snipe-phase {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-head);
}
.snipe-phase.armed  { color: #58a6ff; }
.snipe-phase.firing { color: #f0883e; }
.snipe-phase.done   { color: #3fb950; }
.snipe-fire-card .stat-value { font-size: 1.8rem; }
.snipe-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}
.snipe-summary > div { display: flex; justify-content: space-between; gap: 12px; }
.snipe-summary .exp-label { color: var(--text-muted); }
.snipe-summary .exp-value { color: var(--text); font-family: 'Courier New', monospace; }

#stat-idle {
  padding: 18px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  transition: background 0.2s, border-color 0.2s;
}

/* ── Expired banner ── */

#expired-banner {
  background: #1c1008;
  border: 1px solid #7d2e0e;
  border-left: 4px solid #f85149;
  border-radius: 12px;
  padding: 16px 20px;
  transition: background 0.2s, border-color 0.2s;
}

body.light #expired-banner {
  background: #fff0ee;
  border-color: #fca5a5;
  border-left-color: #f85149;
}

#expired-banner .exp-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f85149;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#expired-banner .exp-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 0.85rem;
}

#expired-banner .exp-label { color: var(--text-muted); }
#expired-banner .exp-value { color: var(--text); font-family: 'Courier New', monospace; }

/* ── Log box ── */

#log-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  height: 420px;
  overflow-y: auto;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.855rem;
  transition: background 0.2s, border-color 0.2s;
}

.log-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  color: var(--text-log);
  line-height: 1.55;
  word-break: break-word;
}

.log-line::before {
  content: '•';
  flex-shrink: 0;
  font-size: 0.65rem;
  opacity: 0.45;
  margin-top: 1px;
}

.log-line span { flex: 1; min-width: 0; }

.log-line.info         { color: var(--text-log-info); }
.log-line.info::before { content: '›'; font-size: 0.9rem; opacity: 0.7; }

.log-line.bid         { color: #3fb950; font-weight: 600; }
.log-line.bid::before { content: '✓'; font-size: 0.8rem; opacity: 1; }

.log-line.warn         { color: #d29922; }
.log-line.warn::before { content: '⚠'; font-size: 0.75rem; opacity: 1; }

.log-line.error         { color: #f85149; }
.log-line.error::before { content: '✕'; font-size: 0.75rem; opacity: 1; }

.log-line.won         { color: #3fb950; font-weight: 700; font-size: 0.9rem; }
.log-line.won::before { content: '★'; font-size: 0.8rem; opacity: 1; }

.log-line.lost         { color: #f85149; font-weight: 600; }
.log-line.lost::before { content: '✕'; font-size: 0.75rem; opacity: 1; }

.log-line.divider {
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.72rem;
  margin: 6px 0;
  opacity: 0.55;
}
.log-line.divider::before {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  align-self: center;
}
.log-line.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  align-self: center;
}

#log-box::-webkit-scrollbar { width: 6px; }
#log-box::-webkit-scrollbar-track { background: transparent; }
#log-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Connection badge ── */

.conn-badge {
  margin-left: auto;
  background: #1a3a1f;
  color: #3fb950;
  border: 1px solid #2ea04344;
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

body.light .conn-badge {
  background: #d1fae5;
  color: #166534;
  border-color: #86efac;
}

/* ── Two-column bid layout ── */

.bid-layout {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  align-items: start;
}

.bid-left,
.bid-right {
  display: flex;
  flex-direction: column;
}

.bid-divider {
  width: 1px;
  background: var(--border);
  margin: 0 20px;
  align-self: stretch;
}

/* ── Top-bar right cluster ── */

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.username-badge {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
}

#logout-btn {
  background: var(--btn-clear-bg);
  color: var(--text-label);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
#logout-btn:hover { opacity: 0.8; }

/* ── Login / auth page ── */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 24px;
}

.auth-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 0;
  overflow: hidden;
}

.auth-tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.auth-tab-btn {
  flex: 1;
  padding: 14px 0;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.auth-tab-btn:hover:not(:disabled) { color: var(--text); opacity: 1; }
.auth-tab-btn.active { color: var(--text-head); border-bottom-color: #58a6ff; }

.auth-panel { display: none; padding: 24px; }
.auth-panel.active { display: block; }

.auth-error {
  margin: 16px 24px 0;
  padding: 10px 14px;
  background: #1c0a0a;
  border: 1px solid #7d0e0e;
  border-left: 3px solid #f85149;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #f85149;
}

body.light .auth-error {
  background: #fff0ee;
  border-color: #fca5a5;
  border-left-color: #f85149;
  color: #b91c1c;
}

.auth-name-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.auth-submit-btn {
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  background: #238636;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.auth-submit-btn:hover { opacity: 0.85; }

.auth-subtitle {
  margin: 24px 24px 0;
  color: var(--text-label);
  font-size: 0.9rem;
  text-align: center;
}

.ms-signin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 20px 24px 28px;
  padding: 12px;
  background: var(--bg-surface);
  color: var(--text-head);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.ms-signin-btn:hover { border-color: #58a6ff; }

/* ── Analytics tab ── */

.analytics-grid {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: stretch;
}

.analytics-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 22px;
}

.analytics-card-win {
  flex-shrink: 0;
  width: 240px;
  aspect-ratio: 1 / 1;
  background: #0d2115;
  border-color: #2ea043;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
}
.analytics-card-win .analytics-label { color: #3fb950; opacity: 0.7; margin-bottom: 10px; }
.analytics-card-win .analytics-value { color: #3fb950; font-size: 4.5rem; line-height: 1; }
.analytics-card-win .analytics-sub   { color: #3fb950; opacity: 0.55; margin-top: 10px; font-size: 0.82rem; }

body.light .analytics-card-win {
  background: #dcfce7;
  border-color: #86efac;
}
body.light .analytics-card-win .analytics-label { color: #15803d; opacity: 1; }
body.light .analytics-card-win .analytics-value { color: #15803d; }
body.light .analytics-card-win .analytics-sub   { color: #16a34a; opacity: 1; }

.analytics-card-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.analytics-card-stack .analytics-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.analytics-card-tall {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.analytics-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.analytics-value {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text-head);
  line-height: 1;
}

.analytics-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 22px;
}

.chart-title {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

/* ── History tab ── */

.history-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.history-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
}

.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 0.82rem;
}

.history-table tr:last-child td { border-bottom: none; }

.history-row { cursor: pointer; }
.history-row:hover td { background: var(--bg-surface); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'Inter', system-ui, sans-serif;
}
.badge.win  { background: #1a3a1f; color: #3fb950; }
.badge.loss { background: #3a1a1a; color: #f85149; }
.badge.skip { background: #2a2a1a; color: #d29922; }

body.light .badge.win  { background: #d1fae5; color: #166534; }
body.light .badge.loss { background: #fee2e2; color: #991b1b; }
body.light .badge.skip { background: #fef3c7; color: #92400e; }

.margin-pos { color: #3fb950; }
.margin-neg { color: #f85149; }
body.light .margin-pos { color: #166534; }
body.light .margin-neg { color: #991b1b; }

.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.detail-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-head);
  font-family: 'Inter', system-ui, sans-serif;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: 'Inter', system-ui, sans-serif;
  transition: border-color 0.15s;
}
.back-btn:hover { border-color: var(--text-muted); }
