:root {
  --bg: #0a0e14;
  --bg-alt: #0d1220;
  --panel: #131826;
  --panel-2: #171d2e;
  --border: #232a3d;
  --text: #e7eaf0;
  --text-muted: #8b93a7;
  --text-faint: #5b6478;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.14);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.14);
  --purple: #a78bfa;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: 72px; /* room for mobile bottom nav */
}

a { color: var(--blue); }

.app-shell { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  flex: none;
}
.brand-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand-subtitle { font-size: 12.5px; color: var(--text-muted); }

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); padding: 9px 14px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; cursor: pointer; display: inline-flex;
  align-items: center; gap: 6px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); border-color: #2c3450; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #2f6fe0; }
.btn-danger { color: var(--red); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tabs / nav ---------- */
.tabs {
  display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px; margin-bottom: 20px; overflow-x: auto;
}
.tab-btn {
  border: none; background: transparent; color: var(--text-muted); padding: 9px 14px;
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600; cursor: pointer;
  white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.tab-btn.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.card-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.card-subtitle { font-size: 12.5px; color: var(--text-muted); margin-bottom: 14px; }
.card-header-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 860px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }

/* ---------- KPI tiles ---------- */
.kpi-tile { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.kpi-value.pos { color: var(--green); }
.kpi-value.neg { color: var(--red); }
.kpi-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; }

/* ---------- Pills / badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill-green { background: var(--green-bg); color: var(--green); }
.pill-red { background: var(--red-bg); color: var(--red); }
.pill-amber { background: var(--amber-bg); color: var(--amber); }
.pill-blue { background: var(--blue-bg); color: var(--blue); }
.pill-muted { background: var(--panel-2); color: var(--text-muted); border: 1px solid var(--border); }

/* ---------- Calendar ---------- */
.calendar-nav { display: flex; align-items: center; gap: 8px; }
.calendar-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.calendar-grid.no-weekend { grid-template-columns: repeat(5, 1fr) 1fr; }
.calendar-head-cell { background: var(--panel-2); color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 8px 10px; letter-spacing: .04em; }
.calendar-cell { background: var(--panel); min-height: 92px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.calendar-cell.empty { background: var(--bg-alt); }
.calendar-cell.total { background: var(--panel-2); align-items: flex-end; justify-content: flex-end; text-align: right; }
.calendar-day-num { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.calendar-chip { font-size: 10.5px; font-weight: 700; padding: 3px 6px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calendar-chip-more { font-size: 10px; color: var(--text-faint); padding: 2px 6px; }
.calendar-week-total { font-size: 13px; font-weight: 800; }
.calendar-footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px 4px; }

@media (max-width: 700px) {
  .calendar-grid, .calendar-grid.no-weekend { grid-template-columns: repeat(7, minmax(0,1fr)); font-size: 11px; }
  .calendar-cell { min-height: 64px; }
}

/* ---------- Recommendation cards ---------- */
.rec-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; margin-bottom: 12px; }
.rec-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.rec-title { font-weight: 700; font-size: 14.5px; margin-bottom: 6px; }
.rec-desc { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; line-height: 1.5; }
.rec-line { font-size: 13px; margin-bottom: 6px; display: flex; gap: 8px; }
.rec-line b { color: var(--text); }
.rec-metric { margin-top: 10px; display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border); padding: 5px 10px; border-radius: 999px; font-size: 12px; }
.rec-metric .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
.table-scroll { overflow-x: auto; }
tr:hover td { background: var(--panel-2); }

/* ---------- Upload ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 36px 18px;
  text-align: center; color: var(--text-muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--blue); background: var(--blue-bg); }
.dropzone-icon { font-size: 30px; margin-bottom: 8px; }

.mapping-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.mapping-row select { width: 100%; }
select, input[type=text], input[type=number], textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; width: 100%;
}
label { font-size: 12.5px; color: var(--text-muted); display: block; margin-bottom: 4px; }

/* ---------- Lists ---------- */
.simple-list { list-style: none; margin: 0; padding: 0; }
.simple-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; display: flex; gap: 8px; align-items: flex-start; }
.simple-list li:last-child { border-bottom: none; }
.bullet-pro::before { content: '✓'; color: var(--green); font-weight: 800; flex: none; }
.bullet-con::before { content: '✕'; color: var(--red); font-weight: 800; flex: none; }
.bullet-watch::before { content: '👁'; flex: none; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .big { font-size: 34px; margin-bottom: 10px; }

/* ---------- Mobile bottom nav (PWA-style) ---------- */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--panel); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.bottom-nav button {
  background: none; border: none; color: var(--text-muted); font-size: 10.5px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 6px; flex: 1;
}
.bottom-nav button .ic { font-size: 18px; }
.bottom-nav button.active { color: var(--blue); }

@media (max-width: 760px) {
  .tabs { display: none; }
  .bottom-nav { display: flex; }
  .app-shell { padding-bottom: 84px; }
}

.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow);
  z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: center; justify-content: center; z-index: 80; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 640px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow); }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.close-x { cursor: pointer; color: var(--text-muted); font-size: 18px; background: none; border: none; }
