/* ============================================================
   P&L Dashboard — desktop + iPhone-style mobile
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --bg: #070b1a;
  --bg-2: #0c1230;
  --panel: #111842;
  --panel-2: #182055;
  --line: rgba(255,255,255,0.07);
  --text: #e8ecff;
  --muted: #8b94c4;
  --accent: #6c8cff;
  --accent-2: #21d4a8;
  --warn: #ff8b6b;
  --good: #21d4a8;
  --bad: #ff5d75;

  --grad-rev: linear-gradient(135deg, #6c8cff 0%, #a06bff 100%);
  --grad-exp: linear-gradient(135deg, #ff8b6b 0%, #ff5d75 100%);
  --grad-net: linear-gradient(135deg, #21d4a8 0%, #6c8cff 100%);
  --grad-bg:  radial-gradient(1200px 600px at 80% -10%, rgba(108,140,255,0.16), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, rgba(33,212,168,0.12), transparent 60%),
              linear-gradient(180deg, #070b1a 0%, #050818 100%);
}

html, body { min-height: 100%; }
html { background: #050818; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: var(--text);
  background: var(--grad-bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Visibility switching */
.desktop-shell { display: grid; }
.iphone-shell { display: none; }

body[data-view="mobile"] .desktop-shell { display: none; }
body[data-view="mobile"] .iphone-shell { display: flex; }

/* ============================================================
   DESKTOP LAYOUT
   ============================================================ */

.desktop-shell {
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(7, 10, 28, 0.55);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--grad-net);
  display: grid; place-items: center;
  font-weight: 800; color: #06112c;
  box-shadow: 0 8px 24px rgba(33,212,168,0.25);
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
  text-decoration: none;
}
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(108,140,255,0.18), rgba(160,107,255,0.12));
  color: white;
}
.nav-item.active .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.sources-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.sources-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.source-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: 8px;
  background: rgba(255,255,255,0.03);
  font-size: 13px;
}
.pill { font-size: 10px; padding: 3px 8px; border-radius: 999px; font-weight: 600; }
.pill-mock { background: rgba(255,139,107,0.15); color: #ffbfa9; }
.pill-live { background: rgba(33,212,168,0.16); color: #8df1d1; }

.sidebar-footer { margin-top: auto; font-size: 12px; color: var(--muted); }
.sidebar-footer .muted { font-size: 11px; opacity: 0.7; margin-top: 4px; }

/* --- Main --- */
.main { padding: 28px 36px 64px; min-width: 0; }

.topbar {
  display: flex; justify-content: space-between; align-items: end;
  gap: 24px; margin-bottom: 24px; flex-wrap: wrap;
}
.page-title { font-size: 28px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.controls { display: flex; gap: 12px; }
.segmented {
  display: inline-flex; padding: 4px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.segmented button {
  background: transparent; border: 0; color: var(--muted);
  padding: 7px 14px; font-size: 13px; font-weight: 500;
  border-radius: 7px; cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: linear-gradient(135deg, rgba(108,140,255,0.85), rgba(160,107,255,0.85));
  color: white;
  box-shadow: 0 4px 14px rgba(108,140,255,0.35);
}

/* --- KPI cards --- */
.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-bottom: 22px;
}
.kpi {
  position: relative; overflow: hidden;
  padding: 18px 20px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(24,32,85,0.85), rgba(17,24,66,0.85));
  border: 1px solid var(--line);
  box-shadow: 0 12px 36px rgba(0,0,0,0.30);
}
.kpi::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 100% at 100% 0%, rgba(255,255,255,0.06), transparent 50%);
  pointer-events: none;
}
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-delta { display: inline-flex; gap: 4px; align-items: center; font-weight: 600; font-size: 12px; padding: 3px 8px; border-radius: 999px; }
.kpi-delta.up   { color: var(--good); background: rgba(33,212,168,0.13); }
.kpi-delta.down { color: var(--bad);  background: rgba(255,93,117,0.13); }
.kpi.accent-rev .kpi-value { background: var(--grad-rev); -webkit-background-clip: text; background-clip: text; color: transparent; }
.kpi.accent-net .kpi-value { background: var(--grad-net); -webkit-background-clip: text; background-clip: text; color: transparent; }
.kpi.accent-exp .kpi-value { background: var(--grad-exp); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* --- Grid --- */
.grid { display: grid; gap: 16px; margin-bottom: 22px; }
.grid-2 { grid-template-columns: 1.55fr 1fr; }

.card {
  background: linear-gradient(180deg, rgba(24,32,85,0.85), rgba(17,24,66,0.85));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.30);
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 12px; }

.chart-wrap { position: relative; height: 260px; }
.chart-wrap-pie { height: 260px; }
.chart-card { display: flex; flex-direction: column; }

.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--muted); }
.leg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.leg-rev { background: linear-gradient(135deg, #6c8cff, #a06bff); }
.leg-exp { background: linear-gradient(135deg, #ff8b6b, #ff5d75); }
.leg-net { background: linear-gradient(135deg, #21d4a8, #6c8cff); }

/* --- P&L table --- */
.table-wrap { overflow-x: auto; }
.pnl-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.pnl-table th, .pnl-table td {
  padding: 10px 14px; text-align: right; font-size: 13px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.pnl-table th { color: var(--muted); font-weight: 500; }
.pnl-table th:first-child, .pnl-table td:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); }
.pnl-table thead th { position: sticky; top: 0; background: var(--panel-2); z-index: 1; }
.pnl-table tr.section td { background: rgba(108,140,255,0.06); color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .08em; }
.pnl-table tr.totals td { font-weight: 700; background: rgba(255,255,255,0.04); }
.pnl-table tr.totals.net td { background: linear-gradient(90deg, rgba(33,212,168,0.10), rgba(108,140,255,0.10)); }
.pnl-table tr.detail td:first-child { padding-left: 28px; color: var(--muted); }
.num-pos { color: var(--good); }
.num-neg { color: var(--bad); }

/* ============================================================
   IPHONE-STYLE MOBILE
   ============================================================ */
.iphone-shell {
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  background: var(--grad-bg);
  padding-bottom: 0;
}

.ios-status {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 28px 6px;
  padding-top: max(14px, env(safe-area-inset-top));
  font-size: 15px; font-weight: 600;
  color: var(--text);
}
.ios-time { font-variant-numeric: tabular-nums; }
.ios-notch {
  flex: 1; max-width: 110px; height: 26px; margin: 0 18px;
  background: #000; border-radius: 14px;
}
.ios-icons { display: flex; gap: 6px; align-items: center; color: var(--text); }

.ios-header { padding: 12px 22px 8px; }
.ios-eyebrow { font-size: 12px; color: var(--muted); letter-spacing: .04em; }
.ios-title { font-size: 34px; margin: 2px 0 14px; font-weight: 800; letter-spacing: -0.02em; }

.ios-segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: rgba(255,255,255,0.07);
  border-radius: 10px; padding: 3px;
}
.ios-segmented button {
  background: transparent; border: 0;
  padding: 8px 0; font-size: 14px; font-weight: 600;
  color: var(--muted); border-radius: 8px; cursor: pointer;
  font-family: inherit;
}
.ios-segmented button.active {
  background: rgba(255,255,255,0.12);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.15);
}

.ios-body { padding: 8px 16px 100px; flex: 1; overflow-y: auto; }

.ios-hero-card {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #21d4a8 0%, #6c8cff 100%);
  border-radius: 22px;
  padding: 18px 20px 8px;
  color: white;
  box-shadow: 0 20px 50px rgba(33,212,168,0.25);
  margin-bottom: 14px;
}
.ios-hero-label { font-size: 12px; opacity: 0.85; letter-spacing: .04em; text-transform: uppercase; }
.ios-hero-value { font-size: 34px; font-weight: 800; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ios-hero-meta  { font-size: 13px; opacity: 0.9; margin-top: 2px; }
.ios-spark { margin-top: 10px; height: 60px; }

.ios-card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.ios-mini-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 14px 16px;
}
.ios-mini-label { font-size: 12px; color: var(--muted); }
.ios-mini-value { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.ios-section-title {
  font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  margin: 18px 4px 8px;
}
.ios-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 14px;
  position: relative;
  height: 230px;
}
.ios-card canvas { height: 100% !important; }

.ios-list { list-style: none; padding: 0; margin: 0;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  overflow: hidden;
}
.ios-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 14px;
}
.ios-list li:last-child { border-bottom: 0; }
.ios-list .meta { color: var(--muted); font-size: 12px; }
.ios-list .val  { font-weight: 600; font-variant-numeric: tabular-nums; }

.ios-spacer { height: 30px; }

.ios-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(7, 10, 28, 0.85);
  backdrop-filter: blur(24px);
  border-top: 1px solid rgba(255,255,255,0.06);
  display: grid; grid-template-columns: repeat(4, 1fr);
}
.ios-tabbar button {
  background: transparent; border: 0; color: var(--muted);
  padding: 10px 0 12px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.ios-tabbar button span { font-size: 22px; }
.ios-tabbar button.active { color: var(--text); }

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .desktop-shell { display: none; }
  .iphone-shell { display: flex; }
}
