/* ── Theme variables ── */
:root {
  --bg:     #1a1a2e; --panel: #16213e; --card: #0f3460;
  --accent: #e94560; --green: #2ecc71; --red: #e74c3c;
  --text:   #eaeaea; --muted: #8892a4; --border: #2a3a5c;
  --hi-row:  rgba(90,160,240,.20);  --hi-col:  rgba(90,160,240,.20);
  --hi-cell: rgba(90,160,240,.55);
}
[data-theme="light"] {
  --bg:     #f0f2f8; --panel: #ffffff; --card: #e4e8f5;
  --accent: #c0392b; --green: #27ae60; --red: #c0392b;
  --text:   #1a1a2e; --muted: #5a647a; --border: #c8cfe0;
  --hi-row:  rgba(30,100,200,.14);  --hi-col:  rgba(30,100,200,.14);
  --hi-cell: rgba(30,100,200,.38);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; touch-action: pan-x pan-y; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; min-height: 100vh; transition: background .2s, color .2s; }

/* ── Theme toggle ── */
.theme-toggle-btn {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; font-size: 1rem;
  cursor: pointer; color: var(--text); transition: background .2s;
  white-space: nowrap; flex-shrink: 0;
}
.theme-toggle-btn:hover { opacity: .82; }
.theme-toggle-btn.phone { padding: 5px 10px; font-size: .9rem; }

/* ── Loading ── */
#loading { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 999; }
.spinner { width: 44px; height: 44px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.loading-text { color: var(--muted); font-size: .85rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Session error ── */
#session-error { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 998; align-items: center; justify-content: center; flex-direction: column; padding: 32px; }
.session-error-box { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px; max-width: 360px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.session-error-icon { font-size: 2.6rem; }
.session-error-box h2 { color: var(--accent); font-size: 1.15rem; }
.session-error-box p  { color: var(--muted); font-size: .88rem; line-height: 1.6; }

/* ── Start screen ── */
#start-view { display: none; align-items: center; justify-content: center; min-height: 100vh; flex-direction: column; gap: 22px; padding: 32px; }
.start-logo { font-size: 2.2rem; font-weight: 800; color: var(--accent); }
.start-sub  { color: var(--muted); font-size: .95rem; text-align: center; max-width: 320px; line-height: 1.6; }
.btn-start  { background: var(--accent); color: #fff; border: none; padding: 15px 44px; border-radius: 14px; font-size: 1.05rem; font-weight: 700; cursor: pointer; }
.btn-start:hover { opacity: .87; }

/* ── Shared buttons ── */
.btn { background: var(--accent); color: #fff; border: none; padding: 7px 16px; border-radius: 8px; font-size: .82rem; font-weight: 600; cursor: pointer; white-space: nowrap; transition: opacity .15s; }
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .33; cursor: default; }
.btn-ghost  { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #7f1d1d; color: #fca5a5; border: 1px solid #b91c1c; }

/* ── iPad layout ── */
#ipad-view { display: none; flex-direction: column; height: 100vh; overflow: hidden; }

.ipad-header {
  display: flex; align-items: center; gap: 0;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
/* Title [30px] Zeit [15px] Slider [15px] Kalender [30px] Btn */
.ipad-header h1 { font-size: .95rem; color: var(--accent); flex-shrink: 0; margin-right: 30px; }
.week-ctrl { display: flex; align-items: center; gap: 0; flex: 1; min-width: 0; margin-right: 30px; }
.week-info { font-size: .78rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.week-info b { color: var(--text); font-weight: 700; }
#ipad-slider { flex: 1; accent-color: var(--accent); cursor: pointer; min-width: 40px; margin: 0 15px; }

/* Duration info — same plain-text style, clickable */
#dur-info { font-size: .78rem; color: var(--muted); white-space: nowrap; cursor: pointer; flex-shrink: 0; }
#dur-info:hover { color: var(--text); }

/* ── Market table ── */
.table-wrapper { flex: 1; overflow: hidden; }
table { width: 100%; height: 100%; border-collapse: collapse; font-size: 22px; }

thead th {
  background: var(--panel); padding: 4px 8px;
  border: 1px solid var(--border); position: sticky; top: 0; z-index: 3;
  text-align: center; white-space: nowrap; color: var(--muted); font-weight: 600;
  font-size: 13px;
}
thead th.drug-header {
  color: var(--text); font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; max-width: 90px;
}
thead th.zone-th { text-align: left; }
thead th.sub-th { font-size: 11px; }

tbody tr { cursor: pointer; }
tbody tr:nth-child(even) { background: rgba(128,128,128,.04); }
tbody td { padding: 2px 8px; border: 1px solid var(--border); text-align: center; transition: background .1s; vertical-align: middle; }
/* Price cells: width set dynamically by setColWidths() in JS */
tbody td.zone-id   { color: var(--accent); font-weight: 700; width: auto; white-space: nowrap; padding: 2px 10px; font-size: 18px; }
tbody td.zone-name { text-align: left; color: var(--muted); font-weight: 500; width: auto; white-space: nowrap; padding: 2px 10px; font-size: 18px; }

.base-row td                { background: var(--card) !important; font-weight: 600; font-size: 14px; }
.base-row td.zone-name      { font-size: 12px; }

/* Highlight */
tbody tr.hl-row td          { background: var(--hi-row); }
tbody td.hl-col             { background: var(--hi-col); }
tbody tr.hl-row td.hl-col  { background: var(--hi-cell); font-weight: 700; }

.pos  { color: var(--green); font-weight: 600; background: rgba(46,204,113,.10); }
.neg  { color: var(--red);   font-weight: 600; background: rgba(231,76,60,.10); }
.zero { color: var(--muted); }

/* Trend arrow (week-over-week change indicator) */
.trend-arrow { opacity: 0.28; font-size: 0.58em; margin-left: 3px; vertical-align: middle; pointer-events: none; }

/* ── iPad bottom bar ── */
.ipad-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; background: var(--panel);
  border-top: 1px solid var(--border); flex-shrink: 0; gap: 10px;
}
.footer-left  { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.footer-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.session-id-label { font-size: .72rem; color: var(--muted); font-family: monospace; opacity: .6; margin-right: 4px; }
/* Uniform height for all buttons in footer-right */
.footer-right .theme-toggle-btn,
.footer-right .btn { height: 34px; padding: 0 14px; line-height: 34px; display: inline-flex; align-items: center; }
#players-display { font-size: .78rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── QR Overlay ── */
#qr-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.8); z-index: 100; align-items: center; justify-content: center; }
#qr-overlay.show { display: flex; }
.qr-box { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 20px 24px; text-align: center; width: auto; max-width: 95vw; }
.qr-box h2 { color: var(--accent); margin-bottom: 5px; }
.qr-box p  { color: var(--muted); font-size: .8rem; margin-bottom: 14px; }
#qr-img { display: inline-flex; }
#qr-img svg, #qr-img img { width: min(66vw, 66vh); height: min(66vw, 66vh); }
.qr-url      { background: var(--card); padding: 7px 12px; border-radius: 8px; font-size: .7rem; color: var(--text); word-break: break-all; margin-top: 12px; }
.qr-close-btn { margin-top: 14px; width: 100%; }

/* ── Confirm overlay ── */
#confirm-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 200; align-items: center; justify-content: center; }
#confirm-overlay.show { display: flex; }
.confirm-box    { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px 32px; text-align: center; max-width: 340px; }
.confirm-box h3 { color: var(--accent); margin-bottom: 10px; }
.confirm-box p  { color: var(--muted); font-size: .88rem; margin-bottom: 20px; line-height: 1.5; }
.confirm-btns   { display: flex; gap: 10px; justify-content: center; }

/* ── Duration modal ── */
#dur-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.8); z-index: 150; align-items: center; justify-content: center; }
#dur-overlay.show { display: flex; }
.dur-box      { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px; max-width: 420px; width: 92%; max-height: 80vh; overflow-y: auto; }
.dur-box h3   { color: var(--accent); margin-bottom: 14px; }
.dur-row      { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .82rem; }
.dur-row:last-child { border-bottom: none; }
.dur-close    { margin-top: 16px; width: 100%; }

/* ── Reset modal (Phone) ── */
#reset-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 400; align-items: center; justify-content: center; }
.reset-modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px 32px; text-align: center; max-width: 300px; width: 88%; }
.reset-modal-icon { font-size: 2rem; margin-bottom: 10px; }
.reset-modal-box h3 { color: var(--accent); margin-bottom: 10px; }
.reset-modal-box p  { color: var(--muted); font-size: .86rem; margin-bottom: 20px; line-height: 1.5; }
.reset-modal-ok { width: 100%; }

/* ── Phone view ── */
#phone-view { display: none; flex-direction: column; min-height: 100vh; padding: 18px 15px 80px; gap: 16px; }

.phone-header    { text-align: center; }
.phone-header h1 { color: var(--accent); font-size: 1.25rem; }
.phone-header p  { color: var(--muted); font-size: .8rem; margin-top: 2px; }

/* Week nav */
.week-nav { display: flex; align-items: center; justify-content: center; gap: 12px; }
.week-nav button { background: var(--card); border: 1px solid var(--border); color: var(--text); width: 36px; height: 36px; border-radius: 8px; font-size: 1rem; cursor: pointer; }
.week-nav button:disabled { opacity: .28; cursor: default; }
.week-nav span { color: var(--text); font-size: .9rem; font-weight: 600; min-width: 64px; text-align: center; }

/* Player setup overlay */
#setup-overlay { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 300; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 28px; }
#setup-overlay.show { display: flex; }
.setup-box       { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; }
.setup-box h2    { color: var(--accent); text-align: center; }
.setup-box input { background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 12px 14px; border-radius: 10px; font-size: 1rem; width: 100%; }
.color-grid       { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; width: 100%; }
.color-dot        { width: 100%; aspect-ratio: 1; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: transform .15s, border-color .15s; }
.color-dot.active { border-color: var(--text); transform: scale(1.12); }
.setup-btn       { background: var(--accent); color: #fff; border: none; padding: 13px; border-radius: 12px; font-size: 1rem; font-weight: 700; cursor: pointer; width: 100%; }

/* Calc card */
.calc-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: .72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }

/* Drug buttons */
.drug-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.drug-btn  { background: var(--card); border: 1px solid var(--border); color: var(--muted); padding: 9px 4px; border-radius: 10px; text-align: center; cursor: pointer; font-size: .76rem; font-weight: 600; line-height: 1.5; transition: all .15s; }
.drug-btn .emoji { font-size: 1.3rem; display: block; }
.drug-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(233,69,96,.16); }

/* Action toggle */
.toggle-row { display: flex; gap: 8px; }
.toggle-btn { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: .88rem; font-weight: 600; cursor: pointer; text-align: center; }
.toggle-btn.active-buy  { background: rgba(46,204,113,.16); border-color: var(--green); color: var(--green); }
.toggle-btn.active-sell { background: rgba(233,69,96,.16);  border-color: var(--accent); color: var(--accent); }

/* Select with arrow */
.select-wrap { position: relative; }
.select-wrap select { background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 11px 36px 11px 13px; border-radius: 10px; font-size: .92rem; width: 100%; appearance: none; cursor: pointer; }
.select-wrap::after { content:''; position: absolute; right: 13px; top: 50%; transform: translateY(-50%); border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--muted); pointer-events: none; }

/* +/- quantity */
.qty-row  { display: flex; align-items: center; gap: 8px; }
.qty-btn  { background: var(--card); border: 1px solid var(--border); color: var(--text); width: 42px; height: 42px; border-radius: 10px; font-size: 1.4rem; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 300; }
.qty-btn:active { background: var(--border); }
.qty-input { background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 10px; border-radius: 10px; font-size: 1rem; text-align: center; width: 100%; }

/* Saturation */
.sat-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; }
.sat-btn  { padding: 8px 4px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: .75rem; cursor: pointer; text-align: center; }
.sat-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(233,69,96,.14); }

/* Result */
.result-box       { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; text-align: center; }
.result-label     { color: var(--muted); font-size: .76rem; margin-bottom: 4px; }
.result-amount    { font-size: 1.9rem; font-weight: 800; }
.result-amount.buy  { color: var(--red); }
.result-amount.sell { color: var(--green); }
.result-breakdown { color: var(--muted); font-size: .72rem; margin-top: 5px; line-height: 1.7; white-space: pre-line; }

/* Phone bottom bar */
.phone-footer { position: fixed; bottom: 0; left: 0; right: 0; background: var(--panel); border-top: 1px solid var(--border); padding: 0 16px; height: 52px; display: flex; align-items: stretch; justify-content: space-between; gap: 8px; z-index: 50; }
.phone-footer > * { display: flex; align-items: center; }
.phone-footer .theme-toggle-btn { padding: 0 14px; font-size: .9rem; align-self: center; height: 36px; }
.player-tag { flex: 1; gap: 8px; font-size: .85rem; font-weight: 600; color: var(--text); }
.edit-btn { background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--muted); padding: 4px; }
.edit-btn:hover { color: var(--text); }
