/* ============================================================
   STYLES.CSS — Single source of truth (Hebrew RTL)
   ============================================================ */
:root {
    --primary:       #667eea;
    --primary-dark:  #5a67d8;
    --secondary:     #764ba2;
    --success:       #27ae60;
    --danger:        #e74c3c;
    --warning:       #f39c12;
    --info:          #3498db;
    --dark:          #1a1a2e;
    --sidebar-w:     260px;
    --topbar-h:      60px;
    --radius:        12px;
}
*  { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: #f0f2f8; color: #2d3748; min-height: 100vh;
    direction: rtl;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */
.sidebar {
    position: fixed; top: 0; bottom: 0;
    right: 0; left: auto;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    z-index: 300;
    display: flex; flex-direction: column;
    overflow-y: auto;
    transition: transform 0.28s ease;
    transform: translateX(0); /* desktop: always visible */
}
@media (max-width: 768px) {
    .sidebar      { transform: translateX(110%) !important; }
    .sidebar.open { transform: translateX(0)    !important; }
}

.sidebar-logo {
    padding: 20px; text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo span { font-size: 36px; display: block; }
.sidebar-logo h2   { color: white; font-size: 18px; margin-top: 8px; }

.sidebar-nav { flex: 1; padding: 10px 0; }

.nav-section-title {
    color: rgba(255,255,255,0.4); font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1.5px;
    padding: 14px 20px 4px; text-align: right;
}
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 20px; color: rgba(255,255,255,0.7);
    text-decoration: none; font-size: 14px;
    transition: all 0.2s;
    border-right: 3px solid transparent;
}
.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,0.1); color: white;
    border-right-color: var(--primary);
}
.sidebar-footer {
    padding: 14px 20px; text-align: center;
    border-top: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.4); font-size: 12px;
}

/* ── SIDEBAR OVERLAY ──────────────────────────────────────── */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.55); z-index: 299;
}
body.sidebar-open { overflow: hidden; }
body.sidebar-open .sidebar-overlay { display: block; }

/* ── MAIN CONTENT ─────────────────────────────────────────── */
.main-content {
    margin-right: var(--sidebar-w); margin-left: 0;
    min-height: 100vh; display: flex; flex-direction: column;
}
@media (max-width: 768px) {
    .main-content { margin-right: 0; padding-bottom: 64px; }
}

/* ── TOPBAR ───────────────────────────────────────────────── */
.topbar {
    background: white; height: var(--topbar-h);
    padding: 0 20px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.07);
    position: sticky; top: 0; z-index: 50; gap: 10px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-title {
    font-size: 18px; font-weight: 700; color: var(--dark);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-icon {
    width: 40px; height: 40px; border-radius: 50%; border: none;
    background: #f0f2f8; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #555; font-size: 18px; flex-shrink: 0; transition: all 0.2s;
}
.btn-icon:hover { background: var(--primary); color: white; }
.user-badge { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #555; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 14px;
}
@media (max-width: 480px) {
    .topbar { padding: 0 10px; }
    .topbar-title { font-size: 15px; }
    .user-badge .user-name { display: none; }
}

/* ── PAGE CONTENT ─────────────────────────────────────────── */
.page-content { flex: 1; padding: 20px; }
@media (max-width: 768px) { .page-content { padding: 12px; } }

/* ── CARDS ────────────────────────────────────────────────── */
.card {
    background: white; border-radius: var(--radius);
    padding: 20px; box-shadow: 0 2px 15px rgba(0,0,0,0.06);
    margin-bottom: 16px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.card-title { font-size: 16px; font-weight: 700; color: var(--dark); }
@media (max-width: 480px) { .card { padding: 14px; margin-bottom: 12px; } }

/* ── STAT CARDS ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px; margin-bottom: 18px;
}
.stat-card {
    background: white; border-radius: var(--radius); padding: 18px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.06);
    display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
    width: 46px; height: 46px; border-radius: 10px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.stat-icon.green  { background: #e8f8f0; }
.stat-icon.red    { background: #fef0ef; }
.stat-icon.blue   { background: #e8f2ff; }
.stat-icon.purple { background: #f3eeff; }
.stat-icon.orange { background: #fff4e5; }
.stat-info  { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; color: #888; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--dark); margin: 3px 0 2px; }
.stat-sub   { font-size: 12px; color: #aaa; }
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card  { padding: 14px 12px; gap: 10px; }
    .stat-value { font-size: 19px; }
    .stat-icon  { width: 38px; height: 38px; font-size: 17px; }
}
@media (max-width: 360px) { .stats-grid { grid-template-columns: 1fr; } }

/* ── TABLES ───────────────────────────────────────────────── */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table  { width: 100%; border-collapse: collapse; direction: rtl; }
thead th {
    background: #f8fafc; padding: 11px 14px; text-align: right;
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.5px; color: #888; border-bottom: 2px solid #eee;
}
tbody tr { border-bottom: 1px solid #f0f0f0; transition: background 0.15s; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 12px 14px; font-size: 14px; color: #444; text-align: right; }
@media (max-width: 768px) { .hide-mobile { display: none !important; } }

/* ── BADGES ───────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 9px; border-radius: 20px;
    font-size: 11px; font-weight: 700; direction: ltr;
}
.badge-success { background: #e8f8f0; color: var(--success); }
.badge-danger  { background: #fef0ef; color: var(--danger);  }
.badge-warning { background: #fff4e5; color: var(--warning); }
.badge-info    { background: #e8f2ff; color: var(--info);    }
.badge-gray    { background: #f0f0f0; color: #666;           }
.badge-deposit { background: #e8f8f0; color: var(--success); }
.badge-expense { background: #fef0ef; color: var(--danger);  }

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 8px;
    font-size: 14px; font-weight: 600; border: none; cursor: pointer;
    transition: all 0.2s; text-decoration: none; white-space: nowrap;
    min-height: 40px; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary);  color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success);  color: white; }
.btn-success:hover { background: #219a52; }
.btn-danger  { background: var(--danger);   color: white; }
.btn-danger:hover  { background: #c0392b; }
.btn-warning { background: var(--warning);  color: white; }
.btn-warning:hover { background: #d68910; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-ghost   { background: transparent; color: #666; }
.btn-ghost:hover { background: #f0f2f8; }
.btn-sm { padding: 6px 12px; font-size: 12px; min-height: 34px; }

/* ── FORMS ────────────────────────────────────────────────── */
.form-group  { margin-bottom: 16px; }
.form-label  { display: block; font-size: 13px; font-weight: 600; color: #555; margin-bottom: 6px; }
.form-control {
    width: 100%; padding: 10px 14px;
    border: 2px solid #eee; border-radius: 8px;
    font-size: 16px; color: #333; direction: rtl;
    transition: border-color 0.2s; background: white;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(102,126,234,0.15); }
select.form-control { cursor: pointer; }

/* ── MODALS ───────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white; border-radius: 18px; padding: 28px;
    width: 90%; max-width: 520px; max-height: 88vh; overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,0.25);
    animation: modalIn 0.25s ease; direction: rtl;
}
@keyframes modalIn { from { opacity:0; transform:translateY(-14px) scale(0.97); } to { opacity:1; transform:none; } }
@media (max-width: 768px) {
    .modal-overlay.active { align-items: flex-end; }
    .modal { width:100%; max-width:100%; border-radius:20px 20px 0 0; padding:22px 18px; animation:sheetUp 0.28s ease; }
    @keyframes sheetUp { from { transform:translateY(100%); } to { transform:translateY(0); } }
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.modal-title  { font-size: 18px; font-weight: 700; }
.modal-close  { background: none; border: none; font-size: 22px; cursor: pointer; color: #aaa; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-start; margin-top: 20px; flex-wrap: wrap; }

/* ── ALERTS ───────────────────────────────────────────────── */
.alert {
    padding: 12px 16px; border-radius: 10px; font-size: 14px;
    margin-bottom: 14px; display: flex; align-items: center; gap: 10px;
}
.alert-success { background: #e8f8f0; color: var(--success); border-right: 4px solid var(--success); }
.alert-danger  { background: #fef0ef; color: var(--danger);  border-right: 4px solid var(--danger);  }
.alert-warning { background: #fff4e5; color: var(--warning); border-right: 4px solid var(--warning); }

/* ── TOAST ────────────────────────────────────────────────── */
.toast-container {
    position: fixed; z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
    /* Mobile: full-width above bottom nav */
    bottom: 72px; right: 12px; left: 12px;
}
@media (min-width: 769px) {
    .toast-container { bottom: 24px; right: 24px; left: auto; width: 320px; }
}
.toast {
    padding: 13px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,0.18);
    display: flex; align-items: center; gap: 10px;
    animation: toastIn 0.3s ease; cursor: pointer; direction: rtl;
}
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } }
.toast-success { background: var(--success); color: white; }
.toast-error   { background: var(--danger);  color: white; }
.toast-info    { background: var(--info);    color: white; }
.toast-warning { background: var(--warning); color: white; }

/* ── BOTTOM NAV ───────────────────────────────────────────── */
.bottom-nav {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    background: white; border-top: 1px solid #e8e8e8;
    box-shadow: 0 -3px 16px rgba(0,0,0,0.09); z-index: 90;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (max-width: 768px) { .bottom-nav { display: block; } }
.bottom-nav-inner {
    display: flex; justify-content: space-around; align-items: stretch; height: 56px;
}
.bottom-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: #bbb; text-decoration: none; font-size: 10px; font-weight: 600;
    transition: color 0.15s; border: none; background: none; cursor: pointer;
    position: relative; padding: 4px 2px; -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item .bn-icon { font-size: 21px; line-height: 1; }
.bottom-nav-item.active   { color: var(--primary); }
.bottom-nav-item:active   { transform: scale(0.88); }
.bn-badge {
    position: absolute; top: 5px; left: 50%; transform: translateX(8px);
    background: var(--danger); color: white; border-radius: 50%;
    min-width: 16px; height: 16px; font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

/* ── SPINNER ──────────────────────────────────────────────── */
.spinner {
    width: 18px; height: 18px; border-radius: 50%; display: inline-block; vertical-align: middle;
    border: 2px solid rgba(255,255,255,0.3); border-top-color: white;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { display: flex; align-items: center; justify-content: center; padding: 40px; color: #aaa; }

/* ── UTILITIES ────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.amount-positive { color: var(--success); font-weight: 700; direction: ltr; display: inline-block; }
.amount-negative { color: var(--danger);  font-weight: 700; direction: ltr; display: inline-block; }
.amount-neutral  { color: #888;           font-weight: 600; direction: ltr; display: inline-block; }

.divider { height: 1px; background: #eee; margin: 16px 0; }
.balance-bar      { height: 6px; border-radius: 3px; background: #eee; overflow: hidden; margin-top: 5px; }
.balance-bar-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }
.search-box { position: relative; }
.empty-state { text-align: center; padding: 50px 20px; color: #aaa; }
.empty-state i { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .bottom-nav    { padding-bottom: env(safe-area-inset-bottom); }
        .toast-container { bottom: calc(70px + env(safe-area-inset-bottom)); }
    }
}
