:root {
  --bg: #eef1f4;
  --card: #ffffff;
  --ink: #12333f;
  --ink-2: #0e2a34;
  --teal: #0aa2c0;
  --teal-d: #0b8ba5;
  --text: #243b44;
  --muted: #7b8a93;
  --line: #e4e8ec;
  --ok: #0f9d58; --ok-bg: #e8f6ee;
  --warn: #b0700f; --warn-bg: #fbf0dd;
  --danger: #cc3333; --danger-bg: #fbeaea;
  --info: #1668c1; --info-bg: #e9f1fb;
  --shadow: 0 1px 3px rgba(18,51,63,.06), 0 6px 20px rgba(18,51,63,.05);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "Noto Sans Hebrew", Arial, sans-serif;
  line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar {
  width: 252px; flex: 0 0 252px;
  background: linear-gradient(180deg, var(--ink) 0%, var(--ink-2) 100%);
  color: #eaf6f9; padding: 22px 16px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 10px; font-weight: 800;
  font-size: 17px; color: #fff; padding: 4px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,.10); margin-bottom: 14px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: rgba(10,162,192,.22);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px;
}
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: 10px; color: #cfe3e9; text-decoration: none; font-size: 14.5px;
  font-weight: 500; transition: background .15s, color .15s;
}
.side-nav a .ic { width: 20px; text-align: center; font-size: 15px; opacity: .95; }
.side-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-nav a.active { background: var(--teal); color: #fff; box-shadow: 0 4px 12px rgba(10,162,192,.35); }
.side-logout {
  margin-top: auto; display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; color: #9fb4bb; text-decoration: none;
  font-size: 14px; border-top: 1px solid rgba(255,255,255,.10); margin-top: auto;
}
.side-logout:hover { color: #fff; background: rgba(255,255,255,.06); }
.content { flex: 1; min-width: 0; padding: 30px 34px; max-width: 1180px; }

/* ---------- headings ---------- */
h1 { font-size: 25px; font-weight: 800; color: var(--ink); margin: 0 0 20px; letter-spacing: -.2px; }
h2 {
  font-size: 17px; font-weight: 700; color: var(--ink); margin: 30px 0 12px;
  border-inline-start: 4px solid var(--teal); padding-inline-start: 10px;
}
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.row-between h1 { margin: 0; }

/* ---------- cards & stats ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 10px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 18px; text-align: center; box-shadow: var(--shadow);
  position: relative; overflow: hidden; transition: transform .15s, box-shadow .15s;
}
.stat::before { content: ""; position: absolute; inset-block-start: 0; inset-inline: 0; height: 4px; background: linear-gradient(90deg, var(--teal), #4fcbe0); }
.stat:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(18,51,63,.10); }
.stat .num { font-size: 34px; font-weight: 800; color: var(--ink); line-height: 1.1; }
.stat > div:last-child { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: right; padding: 12px 16px; font-size: 14px; }
thead th { background: #f2f7f8; color: var(--ink); font-weight: 700; font-size: 12.5px; border-bottom: 2px solid var(--teal); }
tbody td { border-top: 1px solid var(--line); color: var(--text); }
tbody tr:first-child td { border-top: 0; }
tbody tr:nth-child(even) td { background: #fafbfc; }
tbody tr:hover td { background: #f2fbfd; }

/* ---------- pills / badges ---------- */
.pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef2f4; color: var(--ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.info { background: var(--info-bg); color: var(--info); }

/* ---------- buttons ---------- */
button, .btn {
  background: var(--teal); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-block; transition: background .15s, transform .05s;
}
button:hover, .btn:hover { background: var(--teal-d); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { background: #b9c6cc; cursor: not-allowed; }
button.link { background: none; color: var(--teal); padding: 5px 8px; font-weight: 600; white-space: nowrap; }
button.link:hover { background: rgba(10,162,192,.10); }
button.link.danger { color: var(--danger); }
button.link.danger:hover { background: var(--danger-bg); }

/* ---------- forms ---------- */
label { display: block; margin-bottom: 14px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 10px 12px; margin-top: 5px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; color: var(--text); background: #fff;
  font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(10,162,192,.15); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.inline { display: flex; gap: 10px; margin-top: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline input, .inline select { width: auto; flex: 1; margin-top: 0; min-width: 120px; }
.inline label { margin-bottom: 0; }
.inline button { flex: 0 0 auto; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* ---------- flashes ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; font-weight: 500; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bce7cf; }
.flash.error, .flash.warn { background: var(--warn-bg); color: var(--warn); border-color: #f0d9a8; }
.flash a { color: inherit; font-weight: 700; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, var(--ink) 0%, var(--ink-2) 60%, #0a3a45 100%); }
.auth-box { width: 100%; max-width: 400px; }
.card.narrow { max-width: 400px; width: 100%; margin: 0; }
.auth-box .card.narrow { box-shadow: 0 20px 60px rgba(0,0,0,.28); }
.auth-box h1 { text-align: center; }

/* ---------- utilities ---------- */
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; direction: ltr; unicode-bidi: plaintext; }
code.mono { background: #f2f7f8; padding: 2px 7px; border-radius: 6px; }

/* ---------- form sections (טפסים מחולקים לקבוצות ברורות) ---------- */
.form-title { font-size: 15px; font-weight: 700; color: var(--ink); margin: 4px 0 6px; display: flex; align-items: center; gap: 8px; }
.form-hint { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.form-sep { border: 0; border-top: 1px dashed var(--line); margin: 18px 0 14px; }
.formrow { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: flex-end; }
.formrow label { flex: 1 1 160px; min-width: 150px; margin-bottom: 8px; }
.formrow label.grow { flex: 2 1 240px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
details.adv { margin-top: 16px; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 14px; background: #fafbfc; }
details.adv summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 13.5px; }
details.adv summary:hover { color: var(--ink); }
details.adv[open] summary { margin-bottom: 10px; color: var(--ink); }

/* ---------- KPI tiles (סיכום מהיר בעמוד העלויות) ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--teal); }
.kpi .kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .kpi-value { font-size: 22px; font-weight: 800; color: var(--ink); margin-top: 2px; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; text-align: right; }
.kpi .kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.kpi.good::before { background: var(--ok); }
.kpi.good .kpi-value { color: var(--ok); }
.kpi.bad::before { background: var(--danger); }
.kpi.bad .kpi-value { color: var(--danger); }

/* ---------- טבלאות רחבות: גלילה אופקית + מספרים מיושרים ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.table-wrap table { box-shadow: none; margin: 0; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; white-space: nowrap; }
td .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .kpis { grid-template-columns: 1fr 1fr; } }
/* ---------- responsive (בסיס) ---------- */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; padding: 14px 16px; }
  .side-nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .side-nav a { padding: 8px 12px; }
  .brand { border-bottom: 0; margin-bottom: 10px; padding-bottom: 8px; }
  .side-logout { margin-top: 10px; border-top: 0; }
  .content { padding: 20px 18px; }
  .cards, .grid2 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) { .cards, .grid2 { grid-template-columns: 1fr; } }
