:root {
  /* פלטה תואמת מותג Indigo-Sec */
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f2f5fb;
  --line: #e3e8f2;
  --line-strong: #cbd4e6;
  --text: #0f1729;
  --text-soft: #475569;
  --text-mute: #94a3b8;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #e0e7ff;
  --accent: #0ea5e9;
  --ok: #10b981;
  --ok-soft: #d1fae5;
  --warn: #f59e0b;
  --warn-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --info: #0ea5e9;
  --info-soft: #e0f2fe;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  font-family: "Segoe UI", "Assistant", "Heebo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.bg-shape { position: fixed; border-radius: 50%; filter: blur(80px); opacity: 0.4; z-index: 0; pointer-events: none; }
.bg-shape-a { width: 480px; height: 480px; background: #c7d2fe; top: -160px; left: -120px; }
.bg-shape-b { width: 420px; height: 420px; background: #bae6fd; bottom: -160px; right: -120px; }

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Hero ---------- */
.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 26px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "brand copy" "actions actions";
  gap: 18px 22px;
  align-items: center;
  position: relative;
  overflow: visible;
}
.hero::before {
  content: "";
  position: absolute; inset-block-start: 0; inset-inline: 0; height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  border-radius: var(--radius) var(--radius) 0 0;
}
.hero-brand { grid-area: brand; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.hero-copy { grid-area: copy; }
.hero-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 6px; border-top: 1px dashed var(--line); }

.logo-slot {
  width: 92px; height: 92px; border-radius: 18px;
  border: 2px dashed var(--line-strong);
  display: grid; place-items: center; cursor: pointer;
  background: #0a0f1e; overflow: hidden; transition: border-color .15s; /* רקע כהה תמיד (בשני המצבים) */
}
.logo-slot:hover { border-color: var(--brand); }
.logo-placeholder { color: #94a3b8; font-size: 13px; }
.brand-image-preview { width: 100%; height: 100%; object-fit: contain; }
.link-btn { background: none; border: none; color: var(--text-mute); font-size: 12px; cursor: pointer; text-decoration: underline; padding: 0; }
.link-btn:hover { color: var(--danger); }

.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .12em; font-size: 12px; color: var(--brand); font-weight: 700; }
.hero-copy h1 { margin: 4px 0 6px; font-size: 28px; }
.title-input {
  font: inherit; font-size: 28px; font-weight: 700; color: var(--text);
  border: none; border-bottom: 2px solid transparent; background: transparent;
  width: min(100%, 420px); padding: 2px 0;
}
.title-input:focus { outline: none; border-bottom-color: var(--brand); }
.title-input::placeholder { color: var(--text-mute); }
.hero-sub { margin: 0; color: var(--text-soft); font-size: 14px; }

.search-box {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: var(--radius-sm); min-width: 280px;
}
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search-icon { font-size: 13px; opacity: 0.7; }
.search-box input {
  font: inherit; font-size: 13px; border: none; background: transparent; color: var(--text);
  flex: 1; min-width: 0; padding: 2px 0;
}
.search-box input:focus { outline: none; }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-clear { background: none; border: none; cursor: pointer; color: var(--text-mute); font-size: 13px; padding: 0 2px; }
.search-clear:hover { color: var(--danger); }

.field-inline {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13px; color: var(--text-soft);
}
.field-inline span { white-space: nowrap; font-weight: 600; }
.field-inline input, .field-inline select {
  font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fff; color: var(--text);
}
.field-inline input[type="number"] { width: 72px; }

/* ---------- כפתורים ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 13px;
  border-radius: var(--radius-sm); padding: 9px 16px; cursor: pointer;
  border: 1px solid transparent; transition: filter .15s, background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.btn.secondary:hover { background: var(--brand-soft); border-color: var(--brand-soft); color: var(--brand-hover); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.93); }
.file-btn { position: relative; display: inline-flex; align-items: center; }

/* ---------- כרטיסי סיכום ---------- */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px; background: var(--text-mute); }
.card.ok::before { background: var(--ok); }
.card.warn::before { background: var(--warn); }
.card.danger::before { background: var(--danger); }
.card.info::before { background: var(--info); }
.card-label { font-size: 13px; color: var(--text-soft); font-weight: 600; }
.card-value { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.card.ok .card-value { color: var(--ok); }
.card.danger .card-value { color: var(--danger); }
.card.warn .card-value { color: var(--warn); }
.card-sub { font-size: 12px; color: var(--text-mute); margin-top: 2px; }

/* ---------- פאנלים ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.panel-head p { margin: 4px 0 0; color: var(--text-soft); font-size: 13px; }
.panel-total { font-size: 14px; color: var(--text-soft); white-space: nowrap; }
.panel-total strong { color: var(--text); font-size: 17px; }
.badge-soft { font-size: 11px; font-weight: 700; background: var(--ok-soft); color: var(--ok); padding: 3px 9px; border-radius: 999px; }
.badge-soft.danger-soft { background: var(--danger-soft); color: var(--danger); }

/* ---------- תרשים ---------- */
.cashflow-chart-wrap { width: 100%; }
.cashflow-chart { width: 100%; height: 220px; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-text { fill: var(--text-mute); font-size: 11px; font-family: inherit; }
.chart-empty { fill: var(--text-mute); font-size: 16px; font-family: inherit; }
.bar-income { fill: var(--ok); }
.bar-expense { fill: var(--danger); }
.chart-legend { display: flex; gap: 20px; justify-content: center; margin-top: 8px; font-size: 13px; color: var(--text-soft); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.dot-income { background: var(--ok); }
.dot-expense { background: var(--danger); }

/* ---------- טבלאות ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--surface-2); color: var(--text-soft); font-weight: 700; text-align: start;
  padding: 11px 12px; white-space: nowrap; border-bottom: 1px solid var(--line); position: sticky; top: 0;
}
tbody td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.center { text-align: center; }

td input, td select {
  font: inherit; font-size: 13px; border: 1px solid transparent; border-radius: 7px;
  padding: 6px 8px; background: transparent; color: var(--text); width: 100%; min-width: 80px;
}
td input:hover, td select:hover { border-color: var(--line); }
td input:focus, td select:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }
td input.num { text-align: start; min-width: 90px; }
td input[type="date"] { min-width: 130px; color: var(--text-soft); }
td input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.num.strong { font-weight: 700; }

/* תא סכום + בורר מטבע */
.amount-cell { display: flex; align-items: center; gap: 4px; }
.amount-cell input.num { min-width: 78px; }
.cur-select { width: 46px !important; min-width: 46px !important; flex: 0 0 auto; text-align: center; font-weight: 700; color: var(--brand); padding: 6px 2px !important; }
.cur-sub { font-size: 11px; color: var(--text-mute); margin-top: 1px; }

/* בקרת שער דולר */
.fx-rate-text { font-weight: 700; color: var(--brand); white-space: nowrap; }
.inline-check { display: inline-flex; align-items: center; gap: 4px; background: none; border: none; padding: 0; font-size: 12px; color: var(--text-soft); }
.inline-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--brand); }
#fxManualRate { width: 64px; }

.status-badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.st-paid { background: var(--ok-soft); color: var(--ok); }
.st-pending { background: var(--warn-soft); color: var(--warn); }
.st-overdue { background: var(--danger-soft); color: var(--danger); }

.row-overdue td { background: rgba(220, 38, 38, 0.04); }
.row-paid td { background: rgba(22, 163, 74, 0.03); }
.row-inactive { opacity: .55; }

.icon-btn { font: inherit; font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--text-soft); border-radius: 8px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }

.inline-actions { margin-top: 14px; display: flex; gap: 10px; align-items: center; }

/* ---------- Footer ---------- */
.app-footer { display: flex; justify-content: center; padding-top: 4px; }
.save-status { font-size: 12px; color: var(--text-mute); background: var(--surface); border: 1px solid var(--line); padding: 5px 14px; border-radius: 999px; }

@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; grid-template-areas: "brand" "copy" "actions"; text-align: center; }
  .hero-actions { justify-content: center; }
  .hero-copy { text-align: center; }
  .title-input { text-align: center; }
}

/* ============ מצב כהה ============ */
body { transition: background-color .2s ease, color .2s ease; }
[data-theme="dark"] {
  --bg: #0a0f1e;
  --surface: #131a2e;
  --surface-2: #1b2236;
  --line: #2a3350;
  --line-strong: #3b4569;
  --text: #e8edf7;
  --text-soft: #9fb0cf;
  --text-mute: #6b7a99;
  --brand: #6366f1;
  --brand-hover: #818cf8;
  --brand-soft: #232a4d;
  --accent: #38bdf8;
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.16);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.16);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}
[data-theme="dark"] .bg-shape-a { background: #312e81; opacity: 0.35; }
[data-theme="dark"] .bg-shape-b { background: #0c4a6e; opacity: 0.35; }
[data-theme="dark"] td input:focus, [data-theme="dark"] td select:focus { background: var(--surface-2); }
[data-theme="dark"] .btn.secondary:hover { color: #c7d2fe; }

/* ============ קבוצת חשבון + ערכת נושא ============ */
.account-group { display: inline-flex; align-items: center; gap: 8px; margin-inline-end: auto; }
.btn.icon-only { padding: 8px 11px; font-size: 16px; line-height: 1; }
.user-chip { font-size: 13px; font-weight: 600; color: var(--brand); background: var(--brand-soft); padding: 6px 12px; border-radius: 999px; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

/* ============ שכבת התחברות ============ */
.auth-overlay, .modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(6px);
}
/* תכונת hidden חייבת לגבור על display:grid של השכבות */
.auth-overlay[hidden], .modal-overlay[hidden] { display: none; }
[data-theme="dark"] .auth-overlay, [data-theme="dark"] .modal-overlay { background: rgba(0, 0, 0, 0.65); }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px 30px; position: relative; overflow: hidden;
}
.auth-card::before { content: ""; position: absolute; inset-block-start: 0; inset-inline: 0; height: 4px; background: linear-gradient(90deg, var(--brand), var(--accent)); }
.auth-brand { text-align: center; margin-bottom: 22px; }
.brand-mark { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; background: linear-gradient(135deg, var(--brand), var(--accent)); color: #fff; font-size: 28px; font-weight: 800; display: grid; place-items: center; }
.auth-brand h1 { margin: 0 0 4px; font-size: 22px; }
.auth-brand p { margin: 0; color: var(--text-soft); font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.auth-form input, .add-user-form input, .add-user-form select {
  font: inherit; font-size: 15px; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text);
}
.auth-form input:focus, .add-user-form input:focus, .add-user-form select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.auth-form .btn { margin-top: 4px; padding: 12px; font-size: 15px; }
.form-error { background: var(--danger-soft); color: var(--danger); font-size: 13px; font-weight: 600; padding: 9px 12px; border-radius: var(--radius-sm); }

/* ============ מודלים ============ */
.modal-card { width: min(620px, 100%); max-height: 86vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px 26px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-close { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; color: var(--text-soft); font-size: 15px; }
.modal-close:hover { background: var(--danger-soft); color: var(--danger); }
.add-user-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.add-user-form h3 { width: 100%; margin: 0 0 4px; font-size: 15px; }
.add-user-form input { flex: 1 1 140px; }
.role-badge { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.role-badge.user { background: var(--surface-2); color: var(--text-soft); }

body.auth-locked .app-shell { display: none; }
body.auth-locked .bg-shape { opacity: 0.25; }

/* ============ סרגל כותרת + תפריט משתמש ============ */
.toolbar-end { display: inline-flex; align-items: center; gap: 10px; margin-inline-start: auto; }
.user-menu-wrap { position: relative; }
.user-avatar {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px 5px 8px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text);
}
.user-avatar:hover { border-color: var(--brand); }
.avatar-circle { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--accent)); display: grid; place-items: center; font-size: 14px; }
.user-name { color: var(--brand); }
.caret { color: var(--text-mute); font-size: 11px; }
.dropdown-menu {
  position: absolute; inset-block-start: calc(100% + 8px); inset-inline-start: 0; z-index: 40;
  min-width: 230px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 6px; overflow: hidden;
}
.dropdown-header { padding: 8px 12px; font-size: 12px; font-weight: 700; color: var(--text-mute); }
.dropdown-item {
  display: block; width: 100%; text-align: start; background: none; border: none; cursor: pointer;
  font: inherit; font-size: 13.5px; color: var(--text); padding: 9px 12px; border-radius: 8px; white-space: nowrap;
}
.dropdown-item:hover { background: var(--brand-soft); color: var(--brand-hover); }
.dropdown-item.danger:hover { background: var(--danger-soft); color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--line); margin: 5px 0; }

/* ============ מודל הגדרות ============ */
.settings-grid { display: flex; flex-direction: column; gap: 16px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.settings-row > span { font-weight: 600; color: var(--text-soft); font-size: 14px; }
.settings-row input[type="number"] { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); width: 90px; }
.settings-row input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.fx-control { display: inline-flex; align-items: center; gap: 10px; }
.settings-note { font-size: 12px; color: var(--text-mute); margin: 4px 0 0; border-top: 1px dashed var(--line); padding-top: 12px; }

/* ===== מסכי ניהול רשימות ===== */
.manage-section { border-top: 1px dashed var(--line); padding-top: 14px; }
.manage-section h3 { margin: 0 0 10px; font-size: 15px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; min-height: 8px; }
.chip-empty { font-size: 12px; color: var(--text-mute); }
.manage-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 13px; font-weight: 600; }
.chip-del { background: none; border: none; cursor: pointer; color: var(--text-mute); font-size: 12px; width: 18px; height: 18px; border-radius: 50%; line-height: 1; }
.chip-del:hover { background: var(--danger); color: #fff; }
.add-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-row input { font: inherit; font-size: 13px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); flex: 1 1 140px; }
.add-row input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.add-row .btn { flex: 0 0 auto; }
.ro-text { color: var(--text-soft); font-size: 13px; }

/* ===== שדה חובה ריק ===== */
td input.missing, td select.missing { border-color: var(--danger) !important; background: var(--danger-soft); }
.status-select { font-weight: 600; }

/* ===== דיאלוג אישור מחיקה ===== */
.confirm-card {
  width: min(420px, 100%); background: var(--surface); border: 2px solid var(--danger);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; text-align: center;
}
.confirm-icon { font-size: 40px; line-height: 1; }
.confirm-card h2 { margin: 10px 0 6px; font-size: 21px; color: var(--danger); }
.confirm-msg { margin: 0 0 6px; font-size: 15px; color: var(--text); }
.confirm-warn { margin: 0 0 18px; font-size: 13px; font-weight: 700; color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: var(--radius-sm); }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions .btn { min-width: 110px; padding: 11px 18px; }

/* ============ קבצים מצורפים ============ */
.attach-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; min-width: 130px; }
.file-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--brand-soft); border-radius: 999px; padding: 2px 4px 2px 9px; max-width: 160px; }
.file-link { color: var(--brand-hover); font-size: 12px; font-weight: 600; text-decoration: none; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-link:hover { text-decoration: underline; }
.file-del { background: none; border: none; cursor: pointer; color: var(--text-mute); font-size: 12px; width: 18px; height: 18px; border-radius: 50%; line-height: 1; }
.file-del:hover { background: var(--danger); color: #fff; }
.attach-btn { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 1px dashed var(--line-strong); cursor: pointer; font-size: 15px; }
.attach-btn:hover { border-color: var(--brand); background: var(--brand-soft); }
