/* United Bank of Egypt - Microfinance LOS - Trusted IT */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-lighter: #60a5fa;
  --bg: #ffffff;
  --surface: #f8fafc;
  --surface-blue: #eff6ff;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --text: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(15,23,42,0.06);
  --shadow-lg: 0 12px 32px rgba(30,64,175,0.10);
  --radius: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Cairo', 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
}
body[dir="ltr"] { font-family: 'Inter', 'Cairo', system-ui, sans-serif; }

a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
img { max-width: 100%; display: block; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============ TOP HEADER ============ */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; max-width: 1600px; margin: 0 auto;
  gap: 16px; flex-wrap: wrap;
}
.brand-left, .brand-right {
  display: flex; align-items: center; gap: 12px; flex: 1 1 0; min-width: 0;
}
.brand-left  { justify-content: flex-start; }
.brand-right { justify-content: flex-end; }
/* The logo asset is a full bilingual wordmark ("The United Bank / المصرف المتحد"),
   so we render it at its natural width rather than squashing it into a square. */
.brand-logo-link { display: inline-flex; align-items: center; }
.brand-left img.bank-logo {
  height: 42px; width: auto; max-width: 220px; object-fit: contain;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text .en { font-size: 18px; color: var(--primary); font-weight: 700; font-family: 'Inter', sans-serif; }
.brand-text .ar { font-size: 14px; color: var(--text-secondary); }

.partner-icon { font-size: 30px; color: var(--primary-light); }
.partner-text { display: flex; flex-direction: column; line-height: 1.2; text-align: end; }
.partner-text .name { font-size: 16px; font-weight: 700; color: var(--text); font-family: 'Inter', sans-serif; }
.partner-text .role { font-size: 12px; color: var(--text-secondary); }

/* ---- Header: notification bell + panel ---- */
.icon-btn {
  position: relative; width: 42px; height: 42px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-blue); color: var(--primary); font-size: 18px;
  border: 1px solid var(--border); transition: all 0.15s;
}
.icon-btn:hover { background: var(--primary); color: #fff; }
.notif-wrap, .user-wrap { position: relative; }
.notif-badge {
  position: absolute; top: -6px; inset-inline-end: -6px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--error); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
.notif-panel, .user-menu {
  position: absolute; top: calc(100% + 10px); inset-inline-end: 0; z-index: 200;
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.notif-panel[hidden], .user-menu[hidden] { display: none; }
.notif-panel { width: 340px; max-width: 92vw; overflow: hidden; }
.notif-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700;
}
.notif-head .notif-count {
  background: var(--surface-blue); color: var(--primary);
  border-radius: 20px; padding: 1px 10px; font-size: 12px;
}
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
.notif-item:hover { background: var(--surface-blue); }
.notif-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.notif-item-sub { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 13px; }
.notif-empty { padding: 28px 16px; text-align: center; color: var(--text-secondary); }
.notif-empty i { display: block; font-size: 26px; color: var(--success); margin-bottom: 8px; }
.notif-foot { padding: 10px 16px; text-align: center; }
.notif-foot a { font-weight: 600; font-size: 13px; }

/* ---- Header: user button + logout menu ---- */
.user-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 12px; border: 1px solid transparent;
  transition: all 0.15s;
}
.user-btn:hover { background: var(--surface-blue); border-color: var(--border); }
.user-caret { font-size: 12px; color: var(--text-secondary); transition: transform 0.15s; }
.user-btn[aria-expanded="true"] .user-caret { transform: rotate(180deg); }
.user-menu { min-width: 200px; padding: 6px; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; color: var(--text); font-weight: 500;
}
.user-menu-item i { width: 18px; text-align: center; color: var(--primary-light); }
.user-menu-item:hover { background: var(--surface-blue); color: var(--primary); }

.header-center {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
}
.lang-toggle {
  background: var(--surface-blue); color: var(--primary);
  border: 1px solid var(--primary-lighter);
  padding: 8px 14px; border-radius: 10px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 96px; height: 40px; flex: none; box-sizing: border-box; white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.lang-toggle:hover { background: var(--primary); color: #fff; }

/* Shell mount points: the shared shell injects <header>/<aside>/<footer> into
   these wrappers. display:contents makes the wrapper vanish from layout so the
   injected element is the real flex/sticky child. */
#app-header-mount, #app-sidebar-mount, #app-footer-mount { display: contents; }

/* ============ COLLAPSIBLE SIDEBAR ============ */
.sidebar-toggle {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-blue); color: var(--primary); border: 1px solid var(--border);
  cursor: pointer; font-size: 16px; transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover { background: var(--primary); color: #fff; }
.sidebar { transition: width 0.2s ease; }
body.sidebar-collapsed .sidebar { width: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; border-inline-end: none; }
body.sidebar-collapsed .main-content { max-width: 100%; }
/* department group accordions */
.sidebar .nav-title {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: none; cursor: pointer; font-family: inherit; text-align: start;
}
.sidebar .nav-title .nav-caret { margin-inline-start: auto; font-size: 10px; color: var(--text-secondary); transition: transform 0.2s; }
.sidebar .nav-group.collapsed .nav-items { display: none; }
.sidebar .nav-group.collapsed .nav-title .nav-caret { transform: rotate(-90deg); }

/* ============ LAYOUT WITH SIDEBAR ============ */
.app-shell { display: flex; min-height: calc(100vh - 73px); }
.sidebar {
  width: 260px; background: #fff; border-inline-end: 1px solid var(--border);
  padding: 16px 0; flex-shrink: 0;
  position: sticky; top: 73px; height: calc(100vh - 73px); overflow-y: auto;
}
.sidebar .nav-group { padding: 8px 16px; }
.sidebar .nav-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-secondary); padding: 12px 12px 6px; font-weight: 700;
}
.sidebar .nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; margin-bottom: 2px; border-radius: 10px;
  color: var(--text); font-weight: 500; transition: all 0.15s;
  font-size: 14px;
}
.sidebar .nav-item i { width: 20px; text-align: center; color: var(--primary-light); }
.sidebar .nav-item:hover { background: var(--surface-blue); color: var(--primary); }
.sidebar .nav-item.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff; box-shadow: var(--shadow);
}
.sidebar .nav-item.active i { color: #fff; }

.main-content {
  flex: 1; padding: 24px 32px; max-width: calc(100% - 260px);
  overflow-x: hidden;
}

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-title h1 {
  font-size: 26px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 12px;
}
.page-title h1 i { color: var(--primary-light); font-size: 24px; }
.page-title p { color: var(--text-secondary); margin-top: 4px; font-size: 14px; }

/* ============ CARDS ============ */
.card {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-title {
  font-size: 16px; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px; color: var(--text);
}
.card-title i { color: var(--primary-light); }

.glass-card {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(30,64,175,0.18);
}

/* ============ KPI CARDS ============ */
.kpi-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 24px;
}
.kpi-card {
  background: #fff; border-radius: var(--radius-lg); padding: 20px;
  border: 1px solid var(--border); position: relative; overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi-card::before {
  content: ''; position: absolute; top: 0; inset-inline-start: 0;
  width: 4px; height: 100%; background: var(--primary-light);
}
.kpi-card.success::before { background: var(--success); }
.kpi-card.warning::before { background: var(--warning); }
.kpi-card.error::before { background: var(--error); }
.kpi-card .kpi-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--surface-blue); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-bottom: 12px;
}
.kpi-card.success .kpi-icon { background: #dcfce7; color: var(--success); }
.kpi-card.warning .kpi-icon { background: #fef3c7; color: var(--warning); }
.kpi-card.error .kpi-icon { background: #fee2e2; color: var(--error); }
.kpi-card .kpi-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.kpi-card .kpi-value { font-size: 28px; font-weight: 700; color: var(--text); }
.kpi-card .kpi-trend { font-size: 12px; margin-top: 6px; color: var(--success); }
.kpi-card .kpi-trend.down { color: var(--error); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; font-weight: 600;
  transition: all 0.2s; font-size: 14px; border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff; box-shadow: var(--shadow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn-secondary { background: var(--surface-blue); color: var(--primary); border-color: var(--primary-lighter); }
.btn-secondary:hover { background: var(--primary-lighter); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary-light); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data-table th, table.data-table td {
  padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--border);
}
table.data-table th {
  background: var(--surface); font-weight: 700; color: var(--text-secondary);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
}
table.data-table tr:hover td { background: var(--surface-blue); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge.success { background: #dcfce7; color: #166534; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.error { background: #fee2e2; color: #991b1b; }
.badge.info { background: var(--surface-blue); color: var(--primary); }
.badge.muted { background: #f1f5f9; color: var(--text-secondary); }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text);
}
.form-control {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fff; transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.form-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ============ HERO / BANNER ============ */
.hero-banner {
  position: relative; border-radius: 20px; overflow: hidden;
  margin-bottom: 24px; min-height: 200px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff; padding: 32px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
.hero-banner .hero-text { z-index: 2; max-width: 600px; }
.hero-banner h2 { font-size: 26px; margin-bottom: 8px; font-weight: 700; }
.hero-banner p { font-size: 15px; opacity: 0.92; }
.hero-banner img.hero-img {
  width: 280px; height: 180px; object-fit: cover; border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

/* ============ TOAST ============ */
.toast-container {
  position: fixed; top: 90px; inset-inline-end: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: #fff; border-radius: 12px; padding: 14px 18px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.15); min-width: 280px;
  border-inline-start: 4px solid var(--primary-light);
  display: flex; align-items: center; gap: 12px;
  animation: slideIn 0.3s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
.toast.warning { border-color: var(--warning); }
.toast i { font-size: 20px; color: var(--primary); }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--error); }
.toast.warning i { color: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  z-index: 1000; display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-backdrop.active { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius-lg); width: min(560px, 92vw);
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,0.3); padding: 0;
}
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-body { padding: 22px; }
.modal-footer {
  padding: 16px 22px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ============ FOOTER ============ */
.app-footer {
  background: #fff; border-top: 1px solid var(--border);
  padding: 20px 24px; text-align: center; color: var(--text-secondary);
  font-size: 13px;
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
}
.app-footer img { width: 28px; height: 28px; object-fit: contain; }

/* ============ PROGRESS ============ */
.progress-bar {
  height: 8px; background: var(--surface-blue); border-radius: 999px;
  overflow: hidden; margin: 8px 0;
}
.progress-bar > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 999px;
  transition: width 0.6s ease;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .sidebar { position: fixed; transform: translateX(-100%); transition: transform 0.3s; z-index: 99; }
  body[dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { max-width: 100%; padding: 16px; }
  .mobile-toggle { display: inline-flex !important; }
}
.mobile-toggle {
  display: none; padding: 8px 12px; background: var(--surface-blue);
  color: var(--primary); border-radius: 10px;
}
@media (max-width: 640px) {
  .header-inner { padding: 10px 14px; }
  .brand-text .en { font-size: 15px; }
  .brand-right .partner-text .name { font-size: 16px; }
  .hero-banner img.hero-img { display: none; }
  .page-title h1 { font-size: 20px; }
}

/* utility */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ── Sub-group nav (User Management → Users, Roles) ── */
.nav-subgroup { }
.nav-subgroup .nav-subitems { display: flex; flex-direction: column; overflow: hidden; max-height: 500px; transition: max-height .2s ease; }
.nav-subgroup.collapsed .nav-subitems { max-height: 0; }
.nav-subgroup-toggle { width: 100%; text-align: start; background: none; border: none; cursor: pointer; }
.nav-subgroup-toggle .nav-sg-caret { margin-inline-start: auto; transition: transform .2s ease; font-size: .75em; opacity: .7; }
.nav-subgroup:not(.collapsed) .nav-sg-caret { transform: rotate(90deg); }
.nav-sub-item { padding-inline-start: 30px !important; font-size: .88em; opacity: .9; }
.nav-sub-item.active { opacity: 1; }

/* skeleton */
.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* confetti */
.confetti {
  position: fixed; width: 10px; height: 10px;
  pointer-events: none; z-index: 9998;
  animation: confetti-fall 3s ease-out forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
