/* מסכים צרים קודם: טלפון, ואז מחשב. ציר ימין-לשמאל. */
:root {
  --bg: #FAF8F5;
  --panel: #FFFFFF;
  --fg: #2B1D16;
  --muted: #7A6A60;
  --line: #E9E2DA;
  --accent: #C98A12;        /* זהב – הסדרה הראשית */
  --accent-soft: #F6E7C6;
  --comp1: #3F6E80;         /* השוואה 1 */
  --comp2: #A79B91;         /* השוואה 2 */
  --good: #2F7D4F;
  --bad: #B23B2E;
  --good-bg: #E5F2EA;
  --bad-bg: #F8E6E3;
  --neutral-bg: #F1ECE6;
  --radius: 14px;
  --font: 'Heebo', 'Arial Hebrew', Arial, sans-serif;
  --font-num: 'Rubik', 'Heebo', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110D; --panel: #211915; --fg: #F3ECE6; --muted: #B3A398; --line: #3A2E27;
    --accent: #E7AD3C; --accent-soft: #3D2F17; --comp1: #7FB2C4; --comp2: #8C8078;
    --good: #6CC08E; --bad: #F08A7C; --good-bg: #1D3226; --bad-bg: #3A201C; --neutral-bg: #2B221D;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin-top: 14px; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 8px 0 0; }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.summary { margin: 6px 0 10px; color: var(--muted); }
.summary b { color: var(--fg); font-family: var(--font-num); font-weight: 500; }

/* ---------- כפתורים ושדות ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  font: inherit; font-weight: 500; padding: 10px 16px; border-radius: 10px; cursor: pointer; min-height: 42px;
}
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 8px 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible, .icon-btn:focus-visible, .chip:focus-visible,
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select {
  font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-height: 40px; max-width: 100%;
}
.select { padding-inline-end: 28px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

/* ---------- התחברות ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px 22px; display: flex; flex-direction: column; gap: 10px;
}
.login-card h1 { font-size: 22px; }
.login-card .btn { margin-top: 8px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: #2B1D16;
  display: grid; place-items: center; font-family: var(--font-num); font-weight: 600; font-size: 24px;
}
.brand-mark.small { width: 32px; height: 32px; font-size: 16px; }

/* ---------- כותרת וניווט ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding-top: env(safe-area-inset-top, 0px); border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 10px; max-width: 1100px; margin: 0 auto;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
}
.title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.title > div { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.title .muted { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs {
  display: flex; gap: 4px; overflow-x: auto; max-width: 1100px; margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  appearance: none; border: 0; background: none; font: inherit; color: var(--muted); padding: 10px 10px 12px;
  border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; font-weight: 500;
}
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }

/* ---------- תצוגות ---------- */
.view {
  max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px));
}
.controls { display: flex; flex-direction: column; gap: 10px; }
.controls.sticky {
  position: sticky; top: var(--topbar-h, 98px); z-index: 10;
  background: var(--bg); padding: 6px 0 8px; margin-top: -6px;
}
.seg { display: inline-flex; background: var(--neutral-bg); border-radius: 11px; padding: 3px; gap: 2px; align-self: flex-start; max-width: 100%; overflow-x: auto; }
.seg button {
  appearance: none; border: 0; background: transparent; font: inherit; color: var(--muted);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; font-weight: 500;
}
.seg button.active { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg.small button { padding: 5px 10px; font-size: 13px; }
.nav-row { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  appearance: none; width: 42px; height: 42px; flex: none; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.period-label { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; text-align: center; }
.period-label strong { font-size: 16px; }
.date-input { min-height: 32px; padding: 3px 8px; font-size: 13px; border-color: transparent; background: transparent; color: var(--muted); }
.custom-row { display: flex; gap: 10px; flex-wrap: wrap; }
.custom-row label { flex: 1; min-width: 140px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--fg); font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px; cursor: pointer; }

/* ---------- כרטיסים ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { flex: 1; min-width: 140px; }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-family: var(--font-num); font-weight: 500; font-size: clamp(19px, 5.4vw, 30px); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-comp { display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.kpi-comp .row { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); }
.delta { font-family: var(--font-num); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }
@media (max-width: 420px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi#kpi-revenue { grid-column: 1 / -1; }
}

.insights { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.insights li { padding: 9px 12px; border-radius: 10px; background: var(--neutral-bg); line-height: 1.5; }
.insights li.good { background: var(--good-bg); }
.insights li.bad { background: var(--bad-bg); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.legend i.line { height: 3px; border-radius: 2px; }
.legend i.dash { height: 0; border-top: 3px dashed var(--comp2); background: none !important; }
.chart-box { position: relative; height: 300px; }
@media (min-width: 800px) { .chart-box { height: 360px; } }

/* ---------- טבלאות ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap.tall { max-height: 70vh; overflow-y: auto; }
.table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 8px 10px; text-align: start; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 500; font-size: 12.5px; z-index: 1; }
.table td.num, .table th.num { text-align: end; font-family: var(--font-num); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.wrap { white-space: normal; min-width: 220px; }
.table .bar-cell { position: relative; }
.table .bar-cell .bar { position: absolute; inset-block: 6px; inset-inline-start: 0; background: var(--accent-soft); border-radius: 4px; z-index: 0; }
.table .bar-cell span { position: relative; z-index: 1; }
.table .sub { display: block; color: var(--muted); font-size: 11.5px; }
.table tr.empty td { color: var(--muted); text-align: center; padding: 18px; }
.table.pnl td:first-child, .table.pnl th:first-child { position: sticky; inset-inline-start: 0; background: var(--panel); z-index: 2; min-width: 150px; white-space: normal; }
.table.pnl tr.kind td { background: var(--neutral-bg); font-weight: 600; }
.table.pnl tr.kind td:first-child { background: var(--neutral-bg); }
.table.pnl tr.subtotal td { font-weight: 600; }
.table.pnl tr.profit td { font-weight: 700; background: var(--accent-soft); }
.table.pnl tr.profit td:first-child { background: var(--accent-soft); }
.neg { color: var(--bad); }

/* ---------- העלאה ---------- */
.drop {
  margin-top: 12px; border: 1.5px dashed var(--line); border-radius: 12px; padding: 22px 16px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; text-align: center; color: var(--fg);
}
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-title { font-weight: 600; font-size: 15px; }
.file-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.file-list li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.file-list .fname { font-weight: 500; word-break: break-all; }
.file-list .meta { color: var(--muted); font-size: 13px; }
.file-list .state { font-size: 13px; }
.file-list .state.ok { color: var(--good); }
.file-list .state.err { color: var(--bad); }
.file-list .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.file-list .actions .btn { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 14px; }
.pm-columns { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 12px; }
.pm-columns .pm-col { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pm-columns .pm-col span { min-width: 120px; font-size: 13.5px; }
#pnl-mapper .btn { margin-top: 8px; }

.pnl-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  max-width: 480px; margin: 0 auto; background: var(--fg); color: var(--bg); padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.loading { opacity: .55; transition: opacity .15s; }
@media (prefers-reduced-motion: reduce) { .loading { transition: none; } }

.range-inputs { display: flex; gap: 10px; flex-wrap: wrap; }
.range-inputs label { flex-direction: row; align-items: center; gap: 6px; }
.range-inputs input { width: 68px; }

.report-list { margin: 8px 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 4px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--neutral-bg); color: var(--fg); white-space: nowrap; }
.pill.ok { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--accent-soft); color: var(--fg); }
.table.wrap-head th { white-space: normal; min-width: 70px; }
.table.wrap-cells td:nth-child(2) { white-space: normal; min-width: 150px; }
.table.wrap-cells .pill { white-space: normal; }
