:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #e7e9ee;
    --muted: #9aa1ac;
    --border: #2d313a;
    --accent: #3b82f6;
    --accent-dark: #60a5fa;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }

.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--surface); padding: 40px; border-radius: 12px; width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); border: 1px solid var(--border); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.subtitle { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.login-card label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.login-card button { margin-top: 20px; width: 100%; padding: 10px; border: none; border-radius: 8px; background: var(--accent); color: white; font-weight: 600; cursor: pointer; }
.login-card button:hover { background: var(--accent-dark); }
.alert { background: rgba(220,38,38,0.1); color: var(--danger); padding: 10px; border-radius: 8px; font-size: 14px; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; }
.brand-sub { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 0; }

.layout { display: flex; min-height: calc(100vh - 57px); }
.sidebar { width: 240px; background: var(--surface); border-right: 1px solid var(--border); padding: 16px; }
.nav-btn { display: block; width: 100%; text-align: left; padding: 10px 12px; margin-bottom: 4px; border: none; background: none; border-radius: 8px; cursor: pointer; color: var(--text); font-size: 14px; }
.nav-btn:hover { background: var(--bg); }
.nav-btn.active { background: var(--accent); color: white; }
.product-list { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.product-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.product-item:hover, .product-item.active { background: var(--bg); color: var(--text); }

.content { flex: 1; padding: 28px 32px; max-width: 1000px; }
.view.hidden { display: none; }
.hint { color: var(--muted); font-size: 14px; }
.hidden { display: none !important; }

input[type=file], input[type=number], select { padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
button { cursor: pointer; }
#btn-confirm-upload, #btn-run-forecast, #btn-export {
  padding: 10px 18px; border: none; border-radius: 8px; background: var(--accent); color: white; font-weight: 600; margin-top: 14px;
}
#btn-confirm-upload:hover, #btn-run-forecast:hover, #btn-export:hover { background: var(--accent-dark); }

.preview-table, .products-table, .metrics-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 13px; overflow-x: auto; display: block; }
.preview-table th, .preview-table td, .products-table th, .products-table td, .metrics-table th, .metrics-table td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left; white-space: nowrap;
}
.products-table tr:hover { background: var(--surface); cursor: pointer; }
.metrics-table .best { color: var(--success); font-weight: 700; }

.mapping-row { margin: 10px 0; display: flex; align-items: center; gap: 10px; }
.mapping-row label { width: 260px; font-size: 14px; color: var(--muted); }

.forecast-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 18px 0; background: var(--surface); border: 1px solid var(--border); padding: 16px; border-radius: 10px; }
.forecast-controls label { font-size: 13px; }
.forecast-controls .methods-label { margin-left: 10px; color: var(--muted); }
#horizon-input { width: 90px; }

.status-ok { color: var(--success); }
.status-error { color: var(--danger); }

canvas { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-top: 10px; }

/* Matrix loader overlay */
.matrix-overlay {
  position: fixed; inset: 0; z-index: 9999; background: #000;
  display: flex; align-items: center; justify-content: center;
}
.matrix-overlay.hidden { display: none; }
#matrix-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.matrix-terminal {
  position: relative; z-index: 1; font-family: "Share Tech Mono", "VT323", monospace;
  color: #4ade80; text-shadow: 0 0 6px #4ade80; font-size: 15px; line-height: 1.6;
  background: rgba(0,0,0,0.55); padding: 20px 26px; border: 1px solid #22c55e; border-radius: 6px;
  max-width: 480px; white-space: pre-wrap;
}

/* Actions box */
.actions-box { margin: 16px 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.actions-box summary { cursor: pointer; font-weight: 600; }
#actions-list { list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; }
#actions-list li { display: flex; justify-content: space-between; padding: 6px 8px; border-bottom: 1px solid var(--border); }
#actions-list button { background: none; border: none; color: var(--danger); cursor: pointer; }

/* Tabs within product view */
.tabbar { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab-btn { background: none; border: none; padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-pane.hidden { display: none; }

/* What-If sliders */
.whatif-sliders { display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; max-width: 480px; }
.whatif-sliders label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.whatif-sliders input[type=range] { width: 100%; }

/* Chat */
.chat-box { margin-top: 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 12px; }
#chat-messages { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.chat-msg { padding: 8px 12px; border-radius: 8px; font-size: 13px; max-width: 80%; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: white; }
.chat-msg.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); white-space: pre-wrap; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; }
