@import url('../fonts/fonts.css');

/* ============ Design tokens ============ */
:root,
[data-bs-theme="light"] {
  --bs-primary: #059669;
  --bs-primary-rgb: 5, 150, 105;
  --bs-success: #059669;
  --bs-success-rgb: 5, 150, 105;
  --bs-danger: #e11d48;
  --bs-danger-rgb: 225, 29, 72;
  --bs-warning: #d97706;
  --bs-warning-rgb: 217, 119, 6;
  --bs-info: #2563eb;
  --bs-info-rgb: 37, 99, 235;
  --bs-secondary: #64748b;
  --bs-secondary-rgb: 100, 116, 139;
  --bs-body-bg: #f5f7fa;
  --bs-body-color: #161b22;
  --bs-border-color: #e4e8ee;
  --bs-link-color: var(--bs-primary);
  --bs-link-hover-color: #047857;
  --bs-body-font-family: "Noto Kufi Arabic", "Plus Jakarta Sans", "Segoe UI", Tahoma, sans-serif;

  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-sidebar: #ffffff;
  --surface-sidebar-2: #ffffff;
  --sidebar-border: #e4e8ee;
  --sidebar-text: #4b5567;
  --sidebar-text-muted: #97a1b0;
  --sidebar-active-bg: rgba(5, 150, 105, .1);
  --topbar-bg: #ffffff;
  --text-strong: #0b0f14;
  --text-muted: #667085;
  --shadow-sm: 0 1px 2px rgba(20, 24, 31, .06);
  --shadow-md: 0 8px 24px rgba(20, 24, 31, .08);
  --shadow-lg: 0 16px 40px rgba(20, 24, 31, .12);
  --brand-gradient: linear-gradient(135deg, #059669 0%, #10b981 45%, #34d399 100%);
  --accent-violet: #7c3aed;
  --accent-amber: #d97706;
  --ring: rgba(5, 150, 105, .25);
  --radius-lg: 1rem;
  --radius-md: .75rem;
}

[data-bs-theme="dark"] {
  --bs-primary: #34d399;
  --bs-primary-rgb: 52, 211, 153;
  --bs-success: #34d399;
  --bs-success-rgb: 52, 211, 153;
  --bs-danger: #fb7185;
  --bs-danger-rgb: 251, 113, 133;
  --bs-warning: #fbbf24;
  --bs-warning-rgb: 251, 191, 36;
  --bs-info: #60a5fa;
  --bs-info-rgb: 96, 165, 250;
  --bs-secondary: #94a3b8;
  --bs-secondary-rgb: 148, 163, 184;
  --bs-body-bg: #0b0f14;
  --bs-body-color: #e7ebf0;
  --bs-border-color: #232a34;
  --bs-link-color: var(--bs-primary);
  --bs-link-hover-color: #6ee7b7;

  --surface: #12161c;
  --surface-2: #1a1f27;
  --surface-sidebar: #0e1217;
  --surface-sidebar-2: #0e1217;
  --sidebar-border: #232a34;
  --sidebar-text: #b7c0cc;
  --sidebar-text-muted: #5b6472;
  --sidebar-active-bg: rgba(52, 211, 153, .12);
  --topbar-bg: #12161c;
  --text-strong: #f4f6f8;
  --text-muted: #8b96a5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, .55);
  --brand-gradient: linear-gradient(135deg, #047857 0%, #059669 45%, #34d399 100%);
  --accent-violet: #a78bfa;
  --accent-amber: #fbbf24;
  --ring: rgba(52, 211, 153, .3);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  transition: background-color .25s ease, color .25s ease;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ============ Bootstrap component re-skin ============ */
.btn {
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: transform .15s ease, box-shadow .2s ease, filter .2s ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { box-shadow: 0 0 0 .2rem var(--ring); }

.btn-success {
  --bs-btn-bg: #059669;
  --bs-btn-border-color: #059669;
  --bs-btn-hover-bg: #047857;
  --bs-btn-hover-border-color: #047857;
  --bs-btn-active-bg: #036c52;
  --bs-btn-active-border-color: #036c52;
  --bs-btn-focus-shadow-rgb: 5, 150, 105;
  background-image: var(--brand-gradient);
  border: none;
  box-shadow: var(--shadow-sm);
}
.btn-success:hover { filter: brightness(1.06); box-shadow: var(--shadow-md); }

.btn-danger {
  --bs-btn-bg: #e11d48;
  --bs-btn-border-color: #e11d48;
  --bs-btn-hover-bg: #be123c;
  --bs-btn-hover-border-color: #be123c;
  --bs-btn-active-bg: #9f1239;
  --bs-btn-active-border-color: #9f1239;
}

.btn-outline-success { --bs-btn-color: #059669; --bs-btn-border-color: #059669; --bs-btn-hover-bg: #059669; --bs-btn-hover-border-color: #059669; }
.btn-outline-primary { --bs-btn-color: #059669; --bs-btn-border-color: #059669; --bs-btn-hover-bg: #059669; --bs-btn-hover-border-color: #059669; }
.btn-outline-danger { --bs-btn-color: #e11d48; --bs-btn-border-color: #e11d48; --bs-btn-hover-bg: #e11d48; --bs-btn-hover-border-color: #e11d48; }
.btn-outline-secondary { --bs-btn-color: var(--text-muted); --bs-btn-border-color: var(--bs-border-color); --bs-btn-hover-bg: var(--bs-secondary); --bs-btn-hover-border-color: var(--bs-secondary); }

[data-bs-theme="dark"] .btn-outline-secondary { --bs-btn-hover-color: #0b0f14; }

.form-control, .form-select {
  border-radius: var(--radius-md);
  background-color: var(--surface);
  border-color: var(--bs-border-color);
  color: var(--bs-body-color);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 .2rem var(--ring);
}

.alert { border-radius: var(--radius-md); border: 1px solid transparent; }
.alert-danger { background-color: rgba(var(--bs-danger-rgb), .1); color: var(--bs-danger); border-color: rgba(var(--bs-danger-rgb), .25); }
.alert-success { background-color: rgba(var(--bs-success-rgb), .1); color: var(--bs-success); border-color: rgba(var(--bs-success-rgb), .25); }
.alert-info { background-color: rgba(var(--bs-info-rgb), .1); color: var(--bs-info); border-color: rgba(var(--bs-info-rgb), .25); }

.badge { font-weight: 600; border-radius: 999px; padding: .4em .75em; }

.dropdown-menu, .modal-content, .offcanvas {
  border-radius: var(--radius-lg);
  border-color: var(--bs-border-color);
  box-shadow: var(--shadow-lg);
}

/* ============ App shell ============ */
.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 72px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  min-height: 100vh;
}

/* ---- Topbar: clean surface bar, not the old gradient ---- */
.app-topbar {
  grid-area: topbar;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--bs-border-color);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding-inline: 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-topbar .page-heading {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--text-strong);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -.01em;
}
.app-topbar .page-heading .page-heading-icon {
  width: 38px;
  height: 38px;
  border-radius: .7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-active-bg);
  color: var(--bs-primary);
  font-size: 1.1rem;
}
.app-topbar .mobile-brand {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
}

.theme-toggle {
  --bs-btn-color: var(--text-strong);
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text-strong);
  transition: background .2s ease, transform .3s ease;
}
.theme-toggle:hover { background: var(--bs-border-color); }
.theme-toggle i { transition: transform .4s cubic-bezier(.4,0,.2,1), opacity .3s ease; color: var(--text-strong); }
.theme-toggle .bi-moon-stars-fill { display: none; }
[data-bs-theme="dark"] .theme-toggle .bi-sun-fill { display: none; }
[data-bs-theme="dark"] .theme-toggle .bi-moon-stars-fill { display: inline-block; }

.user-chip {
  display: flex;
  align-items: center;
  gap: .55rem;
  border: 1px solid var(--bs-border-color);
  background: var(--surface-2);
  border-radius: 999px;
  padding: .3rem .9rem .3rem .3rem;
  color: var(--text-strong) !important;
  font-weight: 600;
}
[dir="rtl"] .user-chip { padding: .3rem .3rem .3rem .9rem; }
.user-chip:hover { background: var(--bs-border-color); }
.user-chip .user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .85rem;
  flex-shrink: 0;
}
.user-chip::after { display: none; }

/* ---- Sidebar: light card-style, logo header + grouped nav ---- */
.app-sidebar {
  grid-area: sidebar;
  background: var(--surface-sidebar);
  border-inline-end: 1px solid var(--sidebar-border);
  width: 280px;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.1rem;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-header .sidebar-logo {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.sidebar-header .sidebar-app-name {
  font-weight: 800;
  font-size: .95rem;
  line-height: 1.3;
  color: var(--text-strong);
}
.sidebar-header .sidebar-app-tagline {
  font-size: .72rem;
  color: var(--text-muted);
}

.app-content {
  grid-area: content;
  padding: 1.75rem;
  animation: fadeInUp .5s ease both;
}

@media (max-width: 991.98px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "content";
  }
  .app-topbar .mobile-brand { display: inline-block; }
}

@media (max-width: 575.98px) {
  .app-content { padding: 1rem; }
}

/* ============ Sidebar collapse (desktop only) ============ */
@media (min-width: 992px) {
  .app-shell {
    transition: grid-template-columns .2s ease;
  }
  .app-sidebar {
    transition: width .2s ease;
  }

  html[data-sidebar="collapsed"] .app-shell {
    grid-template-columns: 84px 1fr;
  }
  html[data-sidebar="collapsed"] .app-sidebar {
    width: 84px;
  }
  html[data-sidebar="collapsed"] .sidebar-header {
    justify-content: center;
    padding-inline: .5rem;
  }
  html[data-sidebar="collapsed"] .sidebar-app-name,
  html[data-sidebar="collapsed"] .sidebar-app-tagline,
  html[data-sidebar="collapsed"] .sidebar-link-text,
  html[data-sidebar="collapsed"] .sidebar-section-label {
    display: none;
  }
  html[data-sidebar="collapsed"] .sidebar-link {
    justify-content: center;
    padding-inline: 0;
  }
}

#sidebarToggle .icon-collapsed { display: none; }
html[data-sidebar="collapsed"] #sidebarToggle .icon-expanded { display: none; }
html[data-sidebar="collapsed"] #sidebarToggle .icon-collapsed { display: inline-block; }

/* ============ Sidebar nav ============ */
.sidebar-nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 1rem;
}

.sidebar-section-label {
  padding: 1.1rem 1.25rem .4rem;
  color: var(--sidebar-text-muted);
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.sidebar-link {
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  gap: .7rem;
  border-radius: .65rem;
  padding: .6rem .85rem;
  font-weight: 500;
  position: relative;
  transition: color .2s ease, background-color .2s ease;
}
.sidebar-link i {
  font-size: 1.05rem;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: .55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  transition: background-color .2s ease, color .2s ease;
  flex-shrink: 0;
}

.sidebar-link:hover {
  color: var(--text-strong);
  background-color: var(--surface-2);
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--bs-primary);
  font-weight: 700;
}
.sidebar-link.active i {
  background: var(--bs-primary);
  color: #fff;
}

/* ============ Cards ============ */
.card-stat, .table-responsive-card {
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform .2s ease, box-shadow .2s ease;
  animation: fadeInUp .5s ease both;
}

.card-stat {
  border: none;
  position: relative;
  overflow: hidden;
}
.card-stat::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--brand-gradient);
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.card-stat:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.card-stat .stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--text-strong);
  letter-spacing: -.02em;
}

.table-responsive-card {
  padding: 1.25rem;
}
.table-responsive-card:hover { box-shadow: var(--shadow-md); }

/* ============ Dashboard ============ */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  height: 100%;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  animation: fadeInUp .5s ease both;
  transition: transform .2s ease, box-shadow .2s ease;
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
.stat-icon {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
}
.stat-icon.icon-amber   { background: rgba(var(--bs-warning-rgb), .12); color: var(--bs-warning); }
.stat-icon.icon-emerald { background: rgba(var(--bs-success-rgb), .12); color: var(--bs-success); }
.stat-icon.icon-blue    { background: rgba(var(--bs-info-rgb), .12);    color: var(--bs-info); }
.stat-icon.icon-rose    { background: rgba(var(--bs-danger-rgb), .12);  color: var(--bs-danger); }

.stat-body { flex: 1; min-width: 0; }
.stat-label { color: var(--text-muted); font-size: .82rem; margin-bottom: .3rem; }
.stat-value { font-size: 1.55rem; font-weight: 800; color: var(--text-strong); letter-spacing: -.02em; line-height: 1.2; }
.stat-value .stat-value-muted { font-size: .95rem; color: var(--text-muted); font-weight: 600; }
.stat-sub {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .6rem;
  font-size: .76rem;
  color: var(--text-muted);
  margin-top: .4rem;
  min-height: 1.1rem;
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  animation: fadeInUp .5s ease both;
  transition: box-shadow .2s ease;
}
.dashboard-card:hover { box-shadow: var(--shadow-md); }
.dashboard-card-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1rem;
}
.dashboard-card-header .dashboard-card-icon {
  width: 34px;
  height: 34px;
  border-radius: .6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(var(--bs-primary-rgb), .12);
  color: var(--bs-primary);
  font-size: 1rem;
  flex: none;
}
.dashboard-card-header h6 { margin: 0; font-weight: 700; }
.dashboard-card-header .card-link { margin-inline-start: auto; font-size: .78rem; white-space: nowrap; }

.chart-card .chart-wrap {
  position: relative;
  flex: 1;
  min-height: 300px;
}
.chart-card .chart-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

.dashboard-list {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.dashboard-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .65rem 0;
  border-bottom: 1px solid var(--bs-border-color);
}
.dashboard-list-item:last-child { border-bottom: none; padding-bottom: 0; }
.dashboard-list-item .item-title { font-weight: 600; color: var(--text-strong); font-size: .88rem; }
.dashboard-list-item .item-date { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }
.dashboard-list-item .item-amount { font-weight: 700; font-size: .88rem; white-space: nowrap; }

.dashboard-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: .5rem;
  padding: 2rem 0;
  min-height: 120px;
}
.dashboard-empty i { font-size: 1.8rem; opacity: .5; }

.exchange-rate-chip {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  padding: .45rem 1rem;
  font-size: .82rem;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.welcome-hero {
  min-height: calc(100vh - 220px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem;
  animation: fadeInUp .5s ease both;
}
.welcome-logo {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  box-shadow: var(--shadow-md);
  animation: pulseGlow 2.6s ease-in-out infinite;
}
.welcome-hint {
  max-width: 480px;
  margin: 1.25rem auto 0;
  font-size: .88rem;
}
.welcome-footer {
  margin-top: 2.5rem;
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .82rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  padding: .5rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.welcome-footer a {
  font-weight: 700;
  text-decoration: none;
}

.table {
  color: var(--bs-body-color);
  --bs-table-bg: transparent;
}
.table > :not(caption) > * > * { border-bottom-color: var(--bs-border-color); }
.table th, .table td { text-align: center !important; }
.table-hover > tbody > tr:hover > * {
  background-color: rgba(var(--bs-primary-rgb), .06);
}

/* ============ Domain-specific chips ============ */
.debt-positive {
  color: var(--bs-danger);
  font-weight: 700;
}
.debt-settled {
  color: var(--bs-success);
  font-weight: 700;
}

.badge-currency-iqd {
  background-color: rgba(124, 58, 237, .12) !important;
  color: var(--accent-violet) !important;
  border: 1px solid rgba(124, 58, 237, .25);
}
.badge-currency-usd {
  background-color: rgba(37, 99, 235, .12) !important;
  color: var(--bs-info) !important;
  border: 1px solid rgba(37, 99, 235, .25);
}

/* ============ Motion ============ */
/* Opacity-only on purpose (no transform): a transform-based keyframe makes the animated
   element a containing block for position: fixed descendants for as long as the browser
   considers the animation "in effect" — which includes the held end state under
   fill-mode both/forwards, and the frozen starting frame while the tab is backgrounded
   (animations don't advance on hidden tabs). That trapped modals rendered inside
   .app-content/.card-stat/.table-responsive-card below the Bootstrap-appended
   .modal-backdrop, making every field in them unclickable. */
@keyframes fadeInUp {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes floatBlob {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(3%, -4%) scale(1.06); }
  66% { transform: translate(-3%, 3%) scale(.96); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--bs-primary-rgb), .35); }
  50% { box-shadow: 0 0 0 12px rgba(var(--bs-primary-rgb), 0); }
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bs-border-color); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
