/* ═══════════════════════════════════════════════════════════════════════════
   Budget Tool — Mobile-First CSS
   Arabic RTL | Tajawal Font | Deep Navy + Cyan Palette
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700;800&display=swap');

/* ── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --primary:        #0a2e44;
  --primary-light:  #0d3d5c;
  --accent:         #00b4d8;
  --accent-dark:    #0096b7;
  --success:        #2ecc71;
  --success-dark:   #27ae60;
  --warning:        #f39c12;
  --warning-dark:   #d68910;
  --danger:         #e74c3c;
  --danger-dark:    #c0392b;
  --info:           #3498db;
  --purple:         #9b59b6;
  --gray-100:       #f8fafc;
  --gray-200:       #f1f5f9;
  --gray-300:       #e2e8f0;
  --gray-400:       #cbd5e1;
  --gray-500:       #94a3b8;
  --gray-600:       #64748b;
  --gray-700:       #475569;
  --gray-800:       #1e293b;
  --gray-900:       #0f172a;
  --white:          #ffffff;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,.15);
  --shadow-lg:      0 10px 30px rgba(0,0,0,.2);
  --radius-sm:      8px;
  --radius-md:      14px;
  --radius-lg:      20px;
  --radius-full:    9999px;
  --font:           'Tajawal', sans-serif;
  --transition:     all 0.2s ease;
  --tab-height:     64px;
  --topbar-height:  60px;
}

/* ── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-800);
  direction: rtl;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem;   font-weight: 700; }

/* ── Top App Bar ────────────────────────────────────────────────────────── */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.top-bar-title {
  color: var(--white);
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}

.top-bar-btn {
  background: none;
  border: none;
  color: var(--white);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.3rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.top-bar-btn:hover { background: rgba(255,255,255,.15); }

/* ── Page Content Area ──────────────────────────────────────────────────── */
.page-content {
  padding-top: calc(var(--topbar-height) + 1rem);
  padding-bottom: calc(var(--tab-height) + 1rem);
  padding-left: 1rem;
  padding-right: 1rem;
  min-height: 100vh;
}

/* ── Bottom Tab Bar ─────────────────────────────────────────────────────── */
.bottom-tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--tab-height);
  background: var(--white);
  display: flex;
  box-shadow: 0 -2px 12px rgba(0,0,0,.1);
  z-index: 100;
  border-top: 1px solid var(--gray-300);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--gray-500);
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 6px 4px;
  transition: var(--transition);
  position: relative;
}

.tab-btn .tab-icon { font-size: 1.3rem; }

.tab-btn.active {
  color: var(--accent);
}

.tab-btn.active::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 4px 4px;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1rem;
}

.card-body { padding: 1rem; }

.project-card {
  cursor: pointer;
  transition: var(--transition);
  border: 1.5px solid transparent;
}

.project-card:hover,
.project-card:active {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.project-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.project-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-800);
  line-height: 1.3;
}

.project-card-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-bottom: 0.75rem;
}

.project-card-meta span { display: flex; align-items: center; gap: 4px; }

.project-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--gray-200);
}

.financial-chip {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gray-700);
}

.financial-chip.positive { color: var(--success-dark); }
.financial-chip.negative { color: var(--danger); }

/* ── Status Badges ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-draft            { background: var(--gray-200); color: var(--gray-700); }
.badge-pending_ceo_approval { background: #fff3cd;      color: #856404; }
.badge-pending_fc_approval  { background: #fde68a;      color: #92400e; }
.badge-approved         { background: #d1fae5;          color: #065f46; }
.badge-ongoing          { background: #dbeafe;          color: #1e3a5f; }
.badge-rejected         { background: #fee2e2;          color: #991b1b; }
.badge-closed           { background: var(--gray-300);  color: var(--gray-600); }

/* ── Section Headers ────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--gray-200);
}

.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-count {
  background: var(--gray-200);
  color: var(--gray-600);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

/* ── Forms & Inputs ─────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--gray-800);
  background: var(--white);
  transition: var(--transition);
  outline: none;
  direction: rtl;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,180,216,.15);
}

.form-control:disabled,
.form-control[readonly] {
  background: var(--gray-100);
  color: var(--gray-600);
  cursor: not-allowed;
}

select.form-control { cursor: pointer; }

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-control.readonly-result {
  background: var(--gray-100);
  font-weight: 700;
  cursor: default;
}

.form-control.positive-variance { background: #d1fae5; color: #065f46; font-weight: 700; }
.form-control.negative-variance { background: #fee2e2; color: #991b1b; font-weight: 700; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary   { background: var(--accent);        color: var(--white); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-success   { background: var(--success);       color: var(--white); }
.btn-success:hover { background: var(--success-dark); }
.btn-danger    { background: var(--danger);        color: var(--white); }
.btn-danger:hover  { background: var(--danger-dark); }
.btn-warning   { background: var(--warning);       color: var(--white); }
.btn-warning:hover { background: var(--warning-dark); }
.btn-outline   { background: transparent; border: 1.5px solid var(--gray-400); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-200); }
.btn-ghost     { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-200); }

.btn-full { width: 100%; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── FAB ────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--tab-height) + 16px);
  left: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: var(--white);
  font-size: 1.6rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,180,216,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  z-index: 90;
}

.fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0,180,216,.5);
}

/* ── Modal / Bottom Sheet ───────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: none;
  align-items: flex-end;
  animation: fadeIn .2s ease;
}

.overlay.open { display: flex; }

.sheet {
  background: var(--white);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  animation: slideUp .3s ease;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--gray-300);
  border-radius: var(--radius-full);
  margin: 0 auto 1.25rem;
}

.sheet-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gray-800);
  margin-bottom: 1.25rem;
  text-align: center;
}

/* ── Toast Notifications ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  left: 1rem;
  right: 1rem;
  padding: 14px 16px 14px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  animation: toastIn .35s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

/* Draining progress bar at bottom */
.toast::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(255,255,255,.4);
  transform-origin: left;
  animation: toastDrain var(--toast-dur, 3.5s) linear forwards;
}

.toast-icon    { font-size: 1.25rem; flex-shrink: 0; }
.toast-message { flex: 1; line-height: 1.4; }
.toast-close {
  background: none; border: none;
  color: inherit; opacity: .7;
  cursor: pointer; font-size: 1rem;
  padding: 2px 4px; flex-shrink: 0;
  border-radius: 4px; transition: opacity .15s;
  font-family: var(--font);
}
.toast-close:hover { opacity: 1; background: rgba(255,255,255,.15); }

.toast-success { background: #1a9e57; color: white; }
.toast-error   { background: #c0392b; color: white; }
.toast-info    { background: #2471a3; color: white; }
.toast-warning { background: #d68910; color: white; }

@keyframes toastIn    { from { opacity:0; transform: translateY(-20px) scale(.95); } to { opacity:1; transform: translateY(0) scale(1); } }
@keyframes toastDrain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ── Login Page ─────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-light) 40%, #0e5070 100%);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
  color: var(--white);
}

.login-logo .logo-icon {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 0.5rem;
  filter: drop-shadow(0 4px 12px rgba(0,180,216,.4));
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--white);
}

.login-logo p {
  font-size: 0.85rem;
  color: rgba(255,255,255,.7);
  margin-top: 4px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
  display: none;
}

/* ── Search Bar ─────────────────────────────────────────────────────────── */
.search-bar {
  position: relative;
  margin-bottom: 1rem;
}

.search-bar input {
  width: 100%;
  padding: 10px 40px 10px 12px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-full);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition);
  background: var(--white);
  direction: rtl;
}

.search-bar input:focus { border-color: var(--accent); }

.search-bar .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-500);
  font-size: 1rem;
}

/* ── Filter Chips ───────────────────────────────────────────────────────── */
.filter-chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 1rem;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--gray-300);
  background: var(--white);
  color: var(--gray-600);
  white-space: nowrap;
  transition: var(--transition);
}

.chip.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* ── Budget & Revenue Tables ────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-300);
  margin-bottom: 1rem;
}

.data-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th {
  background: var(--gray-200);
  color: var(--gray-700);
  font-weight: 700;
  padding: 10px 8px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 2px solid var(--gray-300);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--gray-200);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tfoot td,
.data-table tfoot th {
  background: var(--gray-100);
  font-weight: 700;
  padding: 10px 8px;
  border-top: 2px solid var(--gray-300);
}

.data-table input,
.data-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.82rem;
  background: var(--white);
  direction: rtl;
  outline: none;
  min-width: 70px;
}

.data-table input:focus,
.data-table select:focus { border-color: var(--accent); }

.data-table input[readonly] {
  background: var(--gray-100);
  font-weight: 700;
  cursor: default;
}

.data-table .del-row-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: var(--transition);
}

.data-table .del-row-btn:hover { background: #fee2e2; }

/* ── KPI Summary Cards ──────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  border-right: 4px solid var(--gray-300);
}

.kpi-card.kpi-revenue  { border-color: var(--success); }
.kpi-card.kpi-cost     { border-color: var(--danger); }
.kpi-card.kpi-profit   { border-color: var(--accent); }
.kpi-card.kpi-variance { border-color: var(--warning); }

.kpi-label {
  font-size: 0.72rem;
  color: var(--gray-500);
  font-weight: 600;
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 1rem;
  font-weight: 800;
  color: var(--gray-800);
  word-break: break-word;
}

.kpi-value.positive { color: var(--success-dark); }
.kpi-value.negative { color: var(--danger); }

/* ── Action Menu ────────────────────────────────────────────────────────── */
.action-menu {
  position: absolute;
  top: calc(var(--topbar-height) + 4px);
  left: 8px;
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 150;
  overflow: hidden;
  display: none;
  animation: fadeInDown .15s ease;
}

.action-menu.open { display: block; }

.action-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: right;
  font-family: var(--font);
}

.action-menu-item:hover { background: var(--gray-100); }
.action-menu-item.danger { color: var(--danger); }
.action-menu-item.success { color: var(--success-dark); }
.action-menu-item + .action-menu-item { border-top: 1px solid var(--gray-200); }

/* ── Role Badge (in top bar) ────────────────────────────────────────────── */
.role-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-top: 2px;
}

.role-badge-admin   { background: rgba(231,76,60,.25);  color: #ffd5d0; }
.role-badge-manager { background: rgba(0,180,216,.25); color: #b3f0ff; }
.role-badge-ceo     { background: rgba(155,89,182,.25); color: #ecd9f5; }

/* ── User Avatar ────────────────────────────────────────────────────────── */
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  gap: 0;
  line-height: 1;
}

.user-avatar span:first-child {
  font-size: 0.95rem;
}

/* ── Admin Panel ────────────────────────────────────────────────────────── */
.user-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--gray-200);
}

.user-list-item:last-child { border-bottom: none; }

.user-avatar-sm {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 700; font-size: 0.9rem; }
.user-meta { font-size: 0.75rem; color: var(--gray-500); }

/* ── Spinner / Loading ──────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

.page-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  gap: 1rem;
  color: var(--gray-500);
}

.page-loader .big-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--gray-300);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-500);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* ── Divider ────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--gray-200);
  margin: 1rem 0;
}

/* ── Tab Content Panels ─────────────────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn      { from { opacity: 0; }           to { opacity: 1; } }
@keyframes fadeInDown  { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp     { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDown   { from { transform: translateY(-100%); opacity:0; } to { transform: translateY(0); opacity:1; } }
@keyframes spin        { to { transform: rotate(360deg); } }

/* ── Utility ────────────────────────────────────────────────────────────── */
.flex          { display: flex; }
.flex-center   { display: flex; align-items: center; justify-content: center; }
.gap-sm        { gap: 0.5rem; }
.gap-md        { gap: 1rem; }
.mt-sm         { margin-top: 0.5rem; }
.mt-md         { margin-top: 1rem; }
.mb-md         { margin-bottom: 1rem; }
.text-sm       { font-size: 0.8rem; }
.text-xs       { font-size: 0.72rem; }
.text-muted    { color: var(--gray-500); }
.font-bold     { font-weight: 700; }
.text-center   { text-align: center; }
.text-danger   { color: var(--danger); }
.text-success  { color: var(--success-dark); }
.hidden        { display: none !important; }
