/* ============================================================
 * styles.css — עיצוב עסקי, נקי, RTL
 * משלים ל-Tailwind CDN. כאן: משתני צבע, כרטיסים, badges, פירוט.
 * ============================================================ */

:root {
  --brand: #1e40af;          /* כחול עסקי */
  --brand-dark: #1e3a8a;
  --brand-light: #eff6ff;
  --accent: #0d9488;         /* טורקיז לתוצאות חיוביות */
  --gold: #b45309;           /* דירוג מוביל */
  --gold-bg: #fffbeb;
  --gold-border: #f59e0b;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
  --shadow-lg: 0 4px 12px rgba(15,23,42,.12), 0 16px 48px rgba(15,23,42,.10);
}

* { box-sizing: border-box; }

body {
  font-family: 'Heebo', -apple-system, 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: #fff;
  box-shadow: var(--shadow);
}
.app-header h1 { letter-spacing: -.5px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 600; border: none; cursor: pointer;
  border-radius: 10px; padding: .6rem 1.1rem; font-size: .95rem;
  transition: all .15s ease; white-space: nowrap;
}
.btn-primary { background: #fff; color: var(--brand-dark); }
.btn-primary:hover { background: #e0edff; transform: translateY(-1px); }
.btn-ghost { background: rgba(255,255,255,.15); color: #fff; }
.btn-ghost:hover { background: rgba(255,255,255,.28); }
.btn-outline { background: #fff; color: var(--brand); border: 1.5px solid var(--brand); }
.btn-outline:hover { background: var(--brand-light); }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid #fca5a5; }
.btn-danger-ghost:hover { background: #fef2f2; }

/* ---------- Deal cards grid ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

.deal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
  transition: box-shadow .2s, transform .2s;
  position: relative;
}
.deal-card.is-leader {
  border: 2px solid var(--gold-border);
  box-shadow: var(--shadow-lg);
}
.deal-card.is-leader .card-head { background: var(--gold-bg); }

.card-head {
  padding: 1rem 1.1rem .8rem;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem;
}
.card-head .rank-badge {
  flex-shrink: 0; font-weight: 800; font-size: .8rem;
  padding: .28rem .6rem; border-radius: 999px;
  background: var(--brand-light); color: var(--brand-dark);
}
.rank-badge.gold { background: var(--gold-border); color: #fff; }
.rank-badge.na { background: #f1f5f9; color: var(--muted); }

.card-body { padding: 1rem 1.1rem; }

/* ---------- Inputs ---------- */
.field { margin-bottom: .7rem; }
.field label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--muted); margin-bottom: .25rem;
}
.field-row { display: flex; align-items: center; gap: .4rem; }
.field input, .field select {
  width: 100%; padding: .5rem .6rem; font-size: .92rem;
  border: 1.5px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); font-family: inherit;
  transition: border-color .15s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
.field input.manual, .field select.manual {
  border-color: var(--gold-border); background: var(--gold-bg);
}
.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }

/* ---------- Manual-edit badge ---------- */
.manual-badge {
  display: inline-flex; align-items: center; gap: .25rem;
  font-size: .68rem; font-weight: 700;
  color: var(--warn); background: var(--warn-bg);
  padding: .12rem .45rem; border-radius: 6px; margin-top: .2rem;
  cursor: pointer; border: none; font-family: inherit;
}
.manual-badge:hover { background: #fde68a; }

/* ---------- Results (5 big numbers) ---------- */
.results-block {
  margin: 1rem 0 .5rem;
  border-top: 1px dashed var(--line); padding-top: .9rem;
}
.result-hero {
  text-align: center; margin-bottom: .8rem;
  background: linear-gradient(135deg, #f0fdfa, #ecfeff);
  border: 1px solid #99f6e4; border-radius: 12px; padding: .7rem;
}
.result-hero .label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.result-hero .value { font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.result-hero .value.neg { color: var(--danger); }

.results-mini {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem;
}
@media (max-width: 400px) { .results-mini { grid-template-columns: repeat(2, 1fr); } }
.mini {
  background: #f8fafc; border: 1px solid var(--line);
  border-radius: 10px; padding: .55rem .6rem; text-align: center;
}
.mini .label { font-size: .72rem; color: var(--muted); font-weight: 600; }
.mini .value { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.mini .value.neg { color: var(--danger); }
.mini.wide { grid-column: 1 / -1; }

.incomplete-note {
  background: var(--warn-bg); color: var(--warn);
  border: 1px solid var(--gold-border); border-radius: 10px;
  padding: .6rem .7rem; font-size: .82rem; font-weight: 600; text-align: center;
}

/* ---------- Breakdown (פירוט חישוב) ---------- */
.breakdown-toggle {
  width: 100%; margin-top: .8rem;
  background: var(--brand-light); color: var(--brand-dark);
  border: none; border-radius: 10px; padding: .6rem;
  font-weight: 700; font-size: .88rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: .4rem;
}
.breakdown-toggle:hover { background: #dbeafe; }
.breakdown { margin-top: .6rem; display: none; }
.breakdown.open { display: block; }

.step {
  border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .65rem; margin-bottom: .45rem; background: #fff;
}
.step .step-label { font-weight: 700; font-size: .85rem; color: var(--ink); display:flex; justify-content:space-between; gap:.5rem; }
.step .step-value { color: var(--brand); font-weight: 800; }
.step .step-formula { font-size: .74rem; color: var(--muted); margin-top: .15rem; }
.step .step-calc { font-size: .78rem; color: #475569; margin-top: .1rem; font-family: 'Courier New', monospace; direction: ltr; text-align: right; }
.step .sub-items { margin-top: .35rem; padding-top: .35rem; border-top: 1px dashed var(--line); }
.step .sub-item { display: flex; justify-content: space-between; font-size: .76rem; color: var(--muted); padding: .1rem 0; }

.advanced-toggle {
  font-size: .8rem; color: var(--brand); background: none; border: none;
  cursor: pointer; font-weight: 600; padding: .3rem 0; margin-bottom: .3rem;
}
.advanced-fields { display: none; }
.advanced-fields.open { display: block; padding-top: .3rem; border-top: 1px dashed var(--line); }

.scenario-box {
  margin-top: .5rem; background: #f8fafc; border: 1px dashed var(--brand);
  border-radius: 10px; padding: .55rem .65rem; font-size: .8rem;
}
.scenario-box .sc-title { font-weight: 700; color: var(--brand-dark); margin-bottom:.3rem; }
.scenario-box .sc-row { display:flex; justify-content:space-between; padding:.1rem 0; color:#475569; }

/* ---------- Add-card tile ---------- */
.add-tile {
  border: 2.5px dashed #cbd5e1; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 200px; color: var(--muted); cursor: pointer; background: #fff;
  transition: all .15s; font-weight: 700;
}
.add-tile:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }
.add-tile i { font-size: 2rem; margin-bottom: .5rem; }

/* ---------- Comparison table ---------- */
.compare-wrap {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  overflow-x: auto; margin-top: 1.5rem;
}
.compare-wrap h2 { padding: 1rem 1.2rem 0; margin:0; font-size:1.15rem; }
table.compare { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.compare th, table.compare td { padding: .7rem .8rem; text-align: center; border-bottom: 1px solid var(--line); }
table.compare th { background: #f8fafc; color: var(--muted); font-weight: 700; font-size: .82rem; }
table.compare td.name { text-align: right; font-weight: 700; }
table.compare tr.leader td { background: var(--gold-bg); }
table.compare .pos { color: var(--accent); font-weight: 700; }
table.compare .neg { color: var(--danger); font-weight: 700; }
table.compare .rank-cell { font-weight: 800; }

/* ---------- Section labels & hints (v1.1) ---------- */
.section-label {
  font-size: .75rem; font-weight: 800; color: var(--brand-dark);
  margin: .8rem 0 .4rem; padding-bottom: .2rem;
  border-bottom: 1px solid var(--line); letter-spacing: -.2px;
}
.hint-note {
  font-size: .72rem; color: var(--muted); background: #f8fafc;
  border-radius: 8px; padding: .4rem .55rem; margin: .2rem 0 .5rem;
  display: flex; align-items: center; gap: .35rem;
}
.hint-note i { color: var(--brand); }

/* ---------- History modal (v1.1) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 1rem;
}
.modal-box {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-head .btn-ghost { background: #f1f5f9; color: var(--ink); }
.history-list { overflow-y: auto; padding: .8rem 1.2rem 1.2rem; }
.history-empty { text-align: center; color: var(--muted); padding: 2rem 0; font-weight: 600; }
.history-empty i { display: block; font-size: 2rem; margin-bottom: .5rem; opacity: .5; }
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; margin-bottom: .5rem;
}
.history-item:hover { border-color: var(--brand); background: var(--brand-light); }
.hi-name { font-weight: 700; font-size: .95rem; }
.hi-meta { font-size: .75rem; color: var(--muted); }
.hi-actions { display: flex; gap: .35rem; flex-shrink: 0; }
.hi-actions .btn-primary { background: var(--brand); color: #fff; }

/* ---------- Sensitivity tables (v1.1) ---------- */
.sensitivity-wrap { margin-top: 1.5rem; }
.sensitivity-wrap h2 { font-size: 1.15rem; margin: 0 0 .8rem; }
.sens-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.sens-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: .9rem 1rem;
}
.sens-title { font-weight: 800; font-size: 1rem; margin-bottom: .5rem; color: var(--brand-dark); }
.sens-sub { font-size: .76rem; font-weight: 700; color: var(--muted); margin: .6rem 0 .3rem; }
table.sens-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.sens-table td { padding: .4rem .5rem; border-bottom: 1px solid var(--line); text-align: center; }
table.sens-table td.sens-label { text-align: right; font-weight: 600; color: #475569; }
table.sens-table tr.sens-base { background: var(--brand-light); }
table.sens-table tr.sens-base td { font-weight: 700; }
table.sens-table .neg { color: var(--danger); font-weight: 700; }
.sens-na { color: var(--muted); font-size: .78rem; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .cards-grid { grid-template-columns: 1fr; }
  .result-hero .value { font-size: 1.6rem; }
}

/* ---------- Print / Report ---------- */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}
