:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #059669;
  --primary-ink: #ffffff;
  --primary-soft: #ecfdf5;
  --success: #10b981;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 14px;
}
:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #172033;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #34d399;
  --primary-ink: #052e1f;
  --primary-soft: #06281e;
  --success: #34d399;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Heebo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 62px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand a { font-weight: 800; font-size: 1.15rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand a:hover { text-decoration: none; }
.brand .logo { flex-shrink: 0; }
.topbar nav { display: flex; gap: 6px; flex: 1; }
.topbar nav a {
  padding: 8px 14px; border-radius: 10px; color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.user-area { display: flex; align-items: center; gap: 12px; }
.user-area .email { color: var(--muted); font-size: .85rem; }
.user-area .logout { color: var(--muted); font-size: .85rem; }
.icon-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; }
.lang-toggle { font-size: .8rem; font-weight: 700; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 9px; color: var(--muted); }
.lang-toggle:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }

/* ---- layout ---- */
.container { max-width: 1000px; margin: 0 auto; padding: 32px 16px; }
.narrow { max-width: 520px; margin: 0 auto; padding: 48px 16px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 16px; }
.sub { color: var(--muted); margin: 0 0 28px; }

/* ---- cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px; margin-bottom: 20px;
}
.card h2 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ---- stat tiles ---- */
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; }
.stat.primary { background: var(--primary-soft); border-color: transparent; }

/* ---- forms ---- */
label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; color: var(--muted); }
input, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--text);
  font-family: inherit; font-size: .95rem;
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }
.field { margin-bottom: 16px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 11px 20px; border-radius: 10px; border: 1px solid transparent;
  font-family: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  background: var(--primary); color: var(--primary-ink);
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); padding: 7px 12px; font-size: .85rem; }
.btn.sm { padding: 7px 14px; font-size: .85rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
/* ---- payment method options (checkbox style) ---- */
.pm-options { display: flex; gap: 12px; flex-wrap: wrap; }
.pm-opt { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1rem;
  cursor: pointer; padding: 11px 18px; border: 1px solid var(--border); border-radius: 12px;
  transition: border-color .1s, background .1s; }
.pm-opt:hover { border-color: var(--success); }
.pm-opt input { width: 20px; height: 20px; accent-color: var(--success); cursor: pointer; }
.pm-opt:has(input:checked) { border-color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent); }

/* ---- download dropdowns (payslip) ---- */
.dl-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dl-title { flex: 0 0 auto; font-weight: 600; font-size: .9rem; color: var(--muted); }
.dropdown { position: relative; flex: 1 1 160px; }   /* הכפתורים מתפרסים לכל הרוחב */
.dropdown-toggle { width: 100%; }
.dl-send { flex: 1 1 160px; }
.dl-send .btn { width: 100%; }
.dropdown-toggle .caret { opacity: .75; margin-inline-start: 4px; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); inset-inline-start: 0; min-width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; display: none; z-index: 30; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a { display: block; padding: 9px 14px; border-radius: 8px; color: var(--text);
  font-weight: 600; white-space: nowrap; }
.dropdown-menu a:hover { background: var(--surface-2); text-decoration: none; }
.dropdown-menu form { margin: 0; }
.dropdown-menu button { display: block; width: 100%; text-align: inherit; background: none;
  border: none; padding: 9px 14px; border-radius: 8px; color: var(--text); font-weight: 600;
  font-family: inherit; font-size: .95rem; cursor: pointer; white-space: nowrap; }
.dropdown-menu button:hover { background: var(--surface-2); }
@media (max-width: 720px) {
  .dl-row { flex-direction: column; align-items: stretch; }
  .dl-title { width: 100%; }
}

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; text-align: right; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: .8rem; font-weight: 600; }
tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; }
.alert.info { background: var(--primary-soft); color: var(--text); }
.alert.ok { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.alert.err { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.pill { display: inline-block; font-size: .72rem; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* ---- live preview panel ---- */
.preview { position: sticky; top: 82px; }
.line { display: flex; justify-content: space-between; padding: 6px 0; }
.line.total { border-top: 2px solid var(--border); margin-top: 8px; padding-top: 12px; font-weight: 800; font-size: 1.15rem; }
.line .pos { color: var(--success); }
.line .neg { color: var(--danger); }
.section-label { font-size: .8rem; color: var(--muted); margin: 14px 0 4px; font-weight: 700; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---- month calendar (work days) ---- */
.readonly-box { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-weight: 600; }
.cal-head, .cal { display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 6px; max-width: 360px; }
.cal-head { margin-bottom: 6px; }
.cal-h { text-align: center; font-size: .72rem; color: var(--muted); font-weight: 700; }
.cal-day { position: relative; display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1 / 1; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: .9rem; user-select: none; transition: background .1s, border-color .1s; }
.cal-day input { position: absolute; opacity: 0; width: 0; height: 0; }
.cal-day:hover { border-color: var(--success); }
.cal-day:has(input:checked) { background: var(--success); color: #fff; border-color: transparent; }
.cal-day.sat { border-style: dashed; }               /* רמז ויזואלי שזו שבת */
.cal-blank { aspect-ratio: 1 / 1; }

/* ---- mini month calendar (issued payslip view) — fills the card width ---- */
.mini-cal { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 6px; margin-top: 8px; }
.mini-cal th { font-size: .74rem; color: var(--muted); font-weight: 700; padding: 2px 0 6px; text-align: center; }
.mini-cal td { border: 1px solid var(--border); border-radius: 8px; height: 48px;
  text-align: center; vertical-align: middle; font-size: .9rem; font-weight: 600; }
.mini-cal td.on { background: var(--success); color: #fff; border-color: transparent; font-weight: 700; }
.mini-cal td.blank { border: none; }

/* ---- payslip form two-column layout ---- */
.payslip-grid { grid-template-columns: 1.4fr 1fr; }

/* ---- tables scroll horizontally on narrow screens ---- */
.card > table { display: table; }
@media (max-width: 720px) {
  .card { overflow-x: auto; }
}

/* ===========================================================
   MOBILE (≤ 720px)
   =========================================================== */
@media (max-width: 720px) {
  /* top bar stacks and nav scrolls horizontally */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 10px;
    row-gap: 8px;
  }
  .topbar nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
  }
  .topbar nav a { white-space: nowrap; padding: 8px 12px; }
  .user-area { margin-inline-start: auto; }
  .user-area .email { display: none; }           /* חוסך מקום בטלפון */

  .container { padding: 20px 16px; }
  .narrow { padding: 28px 16px; }
  h1 { font-size: 1.35rem; }
  .card { padding: 18px 16px; }

  /* every multi-column layout collapses to one column */
  .payslip-grid,
  .grid.cols-2,
  .grid.cols-3,
  .row { grid-template-columns: 1fr !important; }

  /* live preview stops being sticky so it sits naturally below the form */
  .preview { position: static; }

  /* comfortable tap targets */
  input, select, .btn { font-size: 16px; }        /* 16px מונע זום אוטומטי ב-iOS */
  .btn { padding: 12px 18px; }
  .btn-row { flex-direction: column; }
  .btn-row .btn, .btn-row form, .btn-row form .btn { width: 100%; }
}
