:root{
--bg:#f6f3ee;
  --card:#ffffff;
  --text:#1b1b1b;
  --muted:#6b6b6b;
  --line:#d6d6d6;
  --calc-line:#b17b4a;
  --calc-bg:#f3e6d7;
  --shadow: 0 8px 24px rgba(0,0,0,.08);
  --radius:16px;
  --orange-light:#ffd3b1;
  --orange:#f28c28;
  --orange-dark:#c94800;
  --accent:var(--orange);
}

*{box-sizing:border-box}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background:var(--bg);
  color:var(--text);
}

.topbar{display:flex;align-items:center;gap:12px;height:56px;}

.brand{display:flex; align-items:center; gap:12px;}
.logo{
  width:42px; height:42px;
  border-radius:14px;
  background:#1b1b1b;
  color:#fff;
  display:flex; align-items:center; justify-content:center;
  font-weight:800;
}
.title{font-weight:750; letter-spacing:.2px;}
.subtitle{font-size:12px; color:var(--muted); margin-top:2px;}

.topbar-actions{display:flex; gap:10px; align-items:center;}
.pill{
  display:flex; gap:8px; align-items:center;
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:999px;
  background:#fff;
}
.pill label{font-size:12px; color:var(--muted)}
.pill select{border:none; outline:none; background:transparent; font-weight:600}

.btn{
  border:1px solid var(--line);
  background:#fff;
  border-radius:999px;
  padding:10px 14px;
  font-weight:700;
  cursor:pointer;
}
.btn:hover{filter:brightness(.98)}
.icon-btn{
  border:none;background:transparent;font-size:18px;cursor:pointer;padding:8px;border-radius:10px;
}
.icon-btn:hover{background:rgba(0,0,0,.06)}

.container{
  padding:18px 16px 48px;
  max-width:1100px;
  margin:0 auto;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.card{
  background:var(--card);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:16px;
}
.card-h{display:flex; align-items:flex-end; justify-content:space-between; gap:10px; flex-wrap:wrap}
.card h2{margin:0; font-size:18px}
.hint{color:var(--muted); font-size:12px}

.grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap:10px;
  margin-top:12px;
}

.field{grid-column: span 6;}
@media (max-width:820px){ .field{grid-column: span 12;} }

.label{font-size:12px; color:var(--muted); margin-bottom:6px}
.control{
  display:flex; align-items:center;
  border-radius:14px;
  padding:10px 12px;
  gap:8px;
  min-height:42px;
}
.control.editable{
  border:1px solid var(--line);
  background:#fff;
}
.control.calculated{
  border:1px solid var(--calc-line);
  background:var(--calc-bg);
}
.control input{
  width:100%;
  border:none;
  outline:none;
  font-size:14px;
  background:transparent;
  font-weight:650;
}
.unit{font-size:12px;color:var(--muted);font-weight:700;white-space:nowrap}

.kpi-row{
  margin-top:14px;
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:10px;
}
@media (max-width:820px){ .kpi-row{grid-template-columns:1fr;} }

.kpi{
  border:1px solid rgba(0,0,0,.06);
  border-radius:16px;
  padding:12px 12px;
  background:rgba(255,255,255,.7);
}
.kpi-label{font-size:12px;color:var(--muted)}
.kpi-value{margin-top:6px;font-size:22px;font-weight:850; letter-spacing:.2px}

.model-picker{
  margin-top:12px;
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap:10px;
}
.model-chip{
  grid-column: span 4;
  border:1px solid var(--line);
  background:#fff;
  border-radius:16px;
  padding:10px;
  display:flex;
  gap:10px;
  align-items:flex-start;
}
@media (max-width:820px){ .model-chip{grid-column: span 12;} }
.model-chip input{transform:scale(1.1); margin-top:3px}
.model-meta{min-width:0}
.model-name{font-weight:800}
.model-sub{font-size:12px;color:var(--muted); margin-top:2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}

.table-wrap{overflow:auto; border-radius:16px; border:1px solid rgba(0,0,0,.06); margin-top:12px}
.matrix{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  min-width:880px;
}
.matrix th, .matrix td{
  padding:10px 12px;
  border-bottom:1px solid rgba(0,0,0,.06);
  vertical-align:middle;
}
.matrix th{
  position:sticky; top:0;
  background:#fff;
  z-index:1;
  text-align:left;
  font-size:12px;
  color:var(--muted);
}
.matrix td:first-child{font-weight:800; color:#2b2b2b; width:260px}
.matrix tr:last-child td{border-bottom:none}
.badge{
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 10px;
  border-radius:999px;
  font-weight:800;
  font-size:12px;
  border:1px solid rgba(0,0,0,.1);
  background:#fff;
}
.badge.ref{border-color:#1b1b1b}
.minPayback{
  outline:3px solid rgba(25, 135, 84, .45);
  background:rgba(25, 135, 84, .08);
  border-radius:12px;
}

dialog::backdrop{background:rgba(0,0,0,.35)}
.dlg{
  width:min(720px, 96vw);
  border:none;
  border-radius:20px;
  padding:0;
  overflow:hidden;
  box-shadow:var(--shadow);
}
.dlg-h{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 14px;
  border-bottom:1px solid rgba(0,0,0,.06);
  background:#fff;
}
.dlg-h h3{margin:0}
.dlg-body{padding:14px; background:#fff}
.dlg-actions{padding:12px 14px; background:#fff; border-top:1px solid rgba(0,0,0,.06); display:flex; justify-content:flex-end}
.help{font-size:11px;color:var(--muted);margin-top:6px}


/* Currency chip next to language */
.currency-chip{ margin-left:10px; font-weight:600; opacity:0.85; }


#currencySelect{ min-width:84px; }

#refPayback.minPayback{ display:inline-block; padding:2px 6px; border-radius:8px; }

.dlg-section{ margin-top:18px; }
.dlg-section h4{ margin:0 0 10px 0; font-size:14px; opacity:0.9; }
.dlg-section table{ width:100%; border-collapse:collapse; font-size:12px; }
.dlg-section th, .dlg-section td{ border-bottom:1px solid rgba(0,0,0,0.08); padding:8px 6px; text-align:left; vertical-align:top; }
.dlg-section th{ position:sticky; top:0; background:rgba(255,255,255,0.95); }
.dlg-section input{ width:100%; }
.small-note{ font-size:12px; opacity:0.8; }

/* Make Settings dialog scrollable when content grows */
.dlg{ max-height:90vh; display:flex; flex-direction:column; }
.dlg-body{ overflow:auto; }



/* Slider fields (orange scheme like legacy UI) */
.field .slider-wrap{ margin-top:10px; position:relative; }
.field input[type="range"]{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  background:transparent;
  position:relative;
  height:24px;
  margin:0;
  border-radius:999px;
}
.field input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width:26px;
  height:26px;
  border-radius:50%;
  background:#fff;
  border:3px solid var(--orange-dark);
  box-shadow:0 4px 10px rgba(0,0,0,.15);
  margin-top:-7px;
  cursor:pointer;
}
.field input[type="range"]::-moz-range-thumb{
  width:26px;
  height:26px;
  border-radius:50%;
  background:#fff;
  border:3px solid var(--orange-dark);
  box-shadow:0 4px 10px rgba(0,0,0,.15);
  cursor:pointer;
}
.field input[type="range"]::-webkit-slider-runnable-track{
  height:10px;
  border-radius:999px;
  background:#e8eaef;
}
.field input[type="range"]::-moz-range-track{
  height:10px;
  border-radius:999px;
  background:#e8eaef;
}

.field .slider-scale{
  display:flex;
  justify-content:space-between;
  color:var(--muted);
  font-size:12px;
  margin-top:8px;
}
.field .slider-context{
  display:flex;
  justify-content:space-between;
  color:#6b7280;
  font-size:12px;
  margin-top:6px;
}



/* ===== UI polish: larger numeric inputs, better headers, nicer KPI cards ===== */

/* Section headers */
.card-h{align-items:center;}
.card h2{font-size:22px; font-weight:850; letter-spacing:.2px}
.hint{font-size:13px;}

/* Make the value boxes feel like the legacy UI: big bold numbers */
.field .control.editable{
  border-radius:18px;
  padding:12px 14px;
  min-height:54px;
}
.field .control.editable input{
  font-size:22px;
  font-weight:850;
  letter-spacing:.2px;
}
.field .control.editable .unit{
  font-size:14px;
  font-weight:800;
  opacity:.85;
}

/* Slightly lighter labels and more breathing room */
.field .label{font-size:13px; margin-bottom:8px}

/* KPI cards */
.kpi-row{margin-top:18px; gap:12px}
.kpi{
  background:linear-gradient(180deg, #fff7f0 0%, #ffffff 100%);
  border:1px solid rgba(242,140,40,.25);
  box-shadow:0 10px 22px rgba(16,24,40,.06);
  border-radius:20px;
  padding:14px 14px;
}
.kpi-label{font-size:12px; color:#6b7280; font-weight:750; text-transform:none}
.kpi-value{font-size:28px; font-weight:900; margin-top:8px}

/* Make slider track a bit more visible */
.field input[type="range"]::-webkit-slider-runnable-track{ background:#e6e9ef; }
.field input[type="range"]::-moz-range-track{ background:#e6e9ef; }


/* Highlight whole KPI card when reference payback is global minimum */
.kpi.kpi-min{
  background:rgba(34,197,94,.22);
  border-color:rgba(34,197,94,.55);
}
.kpi.kpi-min .kpi-value{ }

/* Force KPI row into one line (desktop) */
#kpiRow{ flex-wrap:nowrap; }
#kpiRow .kpi{ flex:1 1 0; min-width:0; }
@media (max-width: 980px){
  #kpiRow{ flex-wrap:wrap; }
}

/* Tighten value box width a bit */
.field .control.editable{ max-width:340px; }
@media (max-width: 900px){
  .field .control.editable{ max-width:none; }
}
/* Unit alignment closer to legacy */
.field .control.editable{ gap:10px; }
.field .control.editable .unit{ min-width:28px; text-align:left; }


/* Payback KPI row styling in comparison table */
td.paybackCell{
  background:linear-gradient(180deg, #fff7f0 0%, #ffffff 100%);
  border:1px solid rgba(242,140,40,.55);
  border-radius:12px;
  font-weight:850;
}
tr td.paybackCell{ padding:10px 10px; }
td.paybackCell + td.paybackCell{ } /* noop */
td.minPayback{
  /* keep highlight subtle on top of peach */
  outline:3px solid rgba(34,197,94,.55);
  outline-offset:-3px;
}

/* Top centered logo */
.topbar{display:flex; align-items:center; justify-content:space-between; gap:16px;}
.topbar-center{flex:1; display:flex; justify-content:center;}
.logo-box{width:220px; height:64px; border-radius:14px; background:#fff; border:1px solid rgba(31,41,55,.10); display:flex; align-items:center; justify-content:center; overflow:hidden;}
.logo-box img{max-width:100%; max-height:100%; object-fit:contain; padding:8px;}


/* Title weight per request */
.title{font-weight:250;}



/* === Mobile responsiveness === */
:root{
  --container-pad: 16px;
}

/* Prevent horizontal overflow on small screens */
html, body{
  max-width: 100%;
  overflow-x: hidden;
}

/* Make containers breathe on mobile */
.container, .page, .settings-content, .content{
  padding-left: var(--container-pad);
  padding-right: var(--container-pad);
}

/* Tables: allow horizontal scroll instead of breaking layout */
.table-wrap{
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table{
  min-width: 640px;
}

/* Chips/selector wrap nicely */
.chips, .picker-chips, .selected-chips, .chip-row{
  flex-wrap: wrap;
  gap: 8px;
}

/* Inputs + KPI grids become single column on phones */
@media (max-width: 640px){
  /* Generic grid fallbacks */
  .grid, .grid-2, .grid-3, .grid-4,
  .inputs-grid, .inputsGrid, #inputsGrid,
  .kpi-grid, .kpiGrid, #kpiGrid,
  .settings-grid, .settingsGrid{
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* KPI cards: full width */
  .kpi, .kpi-card, .kpi-box, .metric-card, .card{
    width: 100%;
  }

  /* Make slider controls easier to use */
  input[type="range"]{
    width: 100%;
  }

  /* Reduce heavy paddings/margins */
  .section, .panel, .card, .kpi, .kpi-card{
    padding: 12px !important;
  }

  /* Headings wrap and reduce size slightly */
  h1{ font-size: 20px !important; }
  h2{ font-size: 16px !important; }
  h3{ font-size: 14px !important; }

  /* Buttons stretch to full width where appropriate */
  .btn, button{
    max-width: 100%;
  }

  /* Modals fit on mobile */
  .modal, .dialog, .modal-content{
    width: calc(100% - 24px) !important;
    max-width: 520px !important;
  }
}

/* Slightly wider phones / small tablets */
@media (max-width: 900px){
  .table-wrap table{
    min-width: 720px;
  }
}


/* Admin PW modal */
.modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none; /* toggled to flex when open */
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 10000;
}
.modal-content{
  background: #fff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.20);
  width: 420px;
  max-width: calc(100% - 24px);
}


/* --- Mobile/UI tweaks for Calculator V2 --- */

/* Revenue + OpCosts inputs: aim for 4 fields per row on desktop/tablet */
#inputsGrid .field, #opCostsGrid .field { grid-column: span 3; }

/* On smaller screens: 2 per row */
@media (max-width:820px){
  #inputsGrid .field, #opCostsGrid .field { grid-column: span 6; }
}

/* On very small phones: 1 per row */
@media (max-width:520px){
  #inputsGrid .field, #opCostsGrid .field { grid-column: span 12; }
}

/* KPI row: 4 KPI cards in first row, reference payback centered below */
.kpi-row{ grid-template-columns: repeat(4, 1fr); }
#kpiRefPayback{ grid-column: 2 / span 2; justify-self: center; width:100%; max-width:520px; }

@media (max-width:820px){
  .kpi-row{ grid-template-columns: repeat(2, 1fr); }
  #kpiRefPayback{ grid-column: 1 / -1; max-width:none; }
}
@media (max-width:520px){
  .kpi-row{ grid-template-columns: 1fr; }
  #kpiRefPayback{ grid-column: 1 / -1; }
}

/* Percent fields: force unit to appear as prefix (left) */
.control.editable{ flex-direction: row; }

.topbar .title{ font-weight:800; }

/* Center reference KPI text */
#kpiRefPayback .kpi-label, #kpiRefPayback .kpi-value{ text-align:center; }
#kpiRefPayback{ align-items:center; }

/* Revenue collapse */
.revenue-collapsed #inputsGrid{ display:none !important; }

.topbar .title{
  white-space: nowrap;
  line-height: 1;
}

/* Percent sign on LEFT for % inputs */
.control.editable .unit{
  order: -1;
  margin-right: 6px;
  margin-left: 0;
}

/* Final header alignment polish */
.topbar{
  align-items: center;
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Add breathing room below top bar */
main.page{
  padding-top: 18px;
}

/* Header final vertical alignment */
.topbar{
  height: 72px;
  align-items: center;
}

.topbar .title{
  align-self: center;
}

/* More space below header */
main.page{
  padding-top: 28px;
}

/* Header FINAL centering + spacing */
header.topbar{
  height: 64px !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  display: flex;
  align-items: center;
}

header.topbar *{
  align-self: center;
}

main.page{
  padding-top: 20px !important;
}

/* Percent sign LEFT fix */
.control.editable{
  display:flex;
  flex-direction:row;
  align-items:center;
}
.control.editable > .unit{
  order:-1 !important;
  margin-right:6px !important;
  margin-left:0 !important;
}


/* Mobile topbar fix: ensure Settings + Currency visible */
@media (max-width: 900px){
  header.topbar{
    height: auto !important;
    padding: 10px 12px !important;
    flex-wrap: wrap;
    row-gap: 10px;
  }
  .brand{ flex: 1 1 100%; justify-content: center; text-align:center; }
  .topbar-center{ flex: 1 1 100%; display:flex; justify-content:center; }
  .topbar-actions{
    flex: 1 1 100%;
    display:flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-actions .pill{ min-width: 140px; }
  .topbar-actions .pill label{ display:none; } /* save space */
  .topbar-actions select{ width: 100%; }
  #fxWrap{ width: 100%; }
  #settingsLink{ padding: 8px 12px; font-size: 13px; }
  .container{ padding-top: 10px; } /* breathing room under wrapped header */
}

@media (max-width: 520px){
  .topbar-actions .pill{ min-width: 46%; }
  #settingsLink{ width: 100%; max-width: 260px; text-align:center; }
}


/* Mobile topbar wrap fix (keep Settings + Currency visible) */
@media (max-width: 900px){
  header.topbar{
    height: auto !important;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px !important;
  }
  header.topbar .brand{
    flex: 1 1 100%;
    display:flex;
    justify-content:center;
    align-items:center;
    gap: 10px;
  }
  header.topbar .brand > div{ text-align:center; }
  header.topbar .topbar-center{
    flex: 1 1 100%;
    display:flex;
    justify-content:center;
    align-items:center;
  }
  header.topbar .topbar-actions{
    flex: 1 1 100%;
    display:flex;
    justify-content:center;
    align-items:flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }
  header.topbar .topbar-actions .pill{
    flex: 1 1 160px;
    min-width: 150px;
  }
  header.topbar .topbar-actions .pill label{
    display:none;
  }
  #fxWrap{ margin-top:6px !important; }
}


/* Settings actions sticky bar (mobile-friendly) */
.settings-actions{
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  background: var(--bg);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  margin-top: 14px;
  z-index: 50;
}
@media (max-width:520px){
  .settings-actions .btn{
    flex: 1 1 auto;
  }
}

/* Settings sticky actions */
.settings-actions{
  display:flex;
  gap:10px;
  justify-content:flex-end;
  align-items:center;
  margin-top:14px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid rgba(0,0,0,0.08);
}

/* Keep space so fixed bar doesn't cover content */
body.settings-page, .settings-page main.page{
  padding-bottom: 76px;
}

@media (max-width: 900px){
  .settings-actions{
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

/* Revenue header alignment */
#revenueZone .card-h{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
#revenueZone .card-h h2{ margin:0; }
#revenueZone #toggleRevenueBtn{ margin-left:auto; }

/* Revenue header: left title + right collapse */
#revenueZone .revenue-h{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}
#revenueZone .card-h-left{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  text-align:left;
}
#revenueZone .card-h-left h2{ margin:0; }
#revenueZone .card-h-left .hint{ margin-top:2px; }

/* Custom model editor */
.custom-editor{
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px;
  background: #fff;
}
.custom-editor .row{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}
.custom-editor .field{
  flex: 1 1 160px;
  min-width: 140px;
}
.custom-editor label{
  display:block;
  font-size: 12px;
  opacity: 0.85;
  margin-bottom: 4px;
}
.custom-editor input, .custom-editor select{
  width:100%;
  padding:10px 10px;
  border:1px solid rgba(0,0,0,0.12);
  border-radius: 12px;
  font-size: 14px;
}
.custom-editor .readonly{
  background: rgba(0,0,0,0.03);
}
.custom-editor .note{
  font-size:12px;
  opacity:0.7;
  margin-top:8px;
}
/* Inline editor inputs inside comparison matrix */
.miniInput{
  width: 90px;
  max-width: 100%;
  padding: 6px 8px;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 10px;
  font-size: 12px;
}


code{background:rgba(31,41,55,.06);padding:2px 6px;border-radius:6px;}

.version-notice{
  max-width:1100px;
  margin:16px auto 0;
  padding:12px 16px;
  background:#fff7e8;
  border:1px solid #f0c98f;
  border-radius:16px;
  box-shadow:var(--shadow);
  display:flex;
  gap:12px;
  align-items:flex-start;
  justify-content:space-between;
}
.version-refresh-hint{font-weight:700}
.version-notice-close{white-space:nowrap}
.fx-meta{
  margin-top:6px;
  font-size:11px;
  color:var(--muted);
  line-height:1.35;
}
.fx-meta.pending{color:#7a5a00}
.fx-meta.ok{color:#1f6f3b}
.fx-meta.fallback{color:#8a4b08}
.fx-meta a{color:inherit}


.negative-value{ color:#b42318 !important; font-weight:900; }
.negative-note{ color:#b42318; font-weight:700; }
.kpi.kpi-negative{
  background:linear-gradient(180deg, #fff1f0 0%, #ffffff 100%);
  border-color:rgba(180,35,24,.35);
}


/* Shekel requested simplified calculator view */
.hidden-compare-section{ display:none !important; }
.better-shekel-btn{ align-self:center; justify-self:center; min-height:46px; font-weight:800; }
#kpiShekelPayback{ align-items:center; text-align:center; }


.kpi.kpi-best{
  background:linear-gradient(180deg, #dcfce7 0%, #f0fdf4 100%);
  border-color:rgba(22, 163, 74, .55);
  box-shadow:0 8px 22px rgba(22, 163, 74, .12);
}
.kpi.kpi-best .kpi-value{ color:#166534; }
