@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Vibrant Clean Modern Palette */
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --bg-hover: #E2E8F0;

  /* Clean Light Sidebar */
  --bg-sidebar: #FFFFFF;
  --bg-sidebar-hover: #F0FDFA;
  --bg-sidebar-active: #CCFBF1;

  /* Typography */
  --text-primary: #0F172A;
  --text-secondary: #334155;
  --text-muted: #64748B;

  /* Primary Energetic Modern Teal & Cyan Gradient */
  --primary: #0D9488;
  --primary-hover: #0F766E;
  --primary-active: #115E59;
  --primary-light: #CCFBF1;
  --primary-subtle: #F0FDFA;
  --primary-gradient: linear-gradient(135deg, #0D9488 0%, #14B8A6 100%);
  --primary-gradient-hover: linear-gradient(135deg, #0F766E 0%, #0D9488 100%);

  /* Vivid Accents */
  --accent-blue: #4F46E5;
  --accent-blue-hover: #4338CA;
  --accent-blue-light: #EEF2FF;
  --accent-blue-border: #C7D2FE;

  --accent-amber: #D97706;
  --accent-amber-light: #FFFBEB;
  --accent-amber-border: #FDE68A;

  --accent-red: #E11D48;
  --accent-red-hover: #BE123C;
  --accent-red-light: #FFF1F2;
  --accent-red-border: #FECDD3;

  --accent-green: #059669;
  --accent-green-hover: #047857;
  --accent-green-light: #ECFDF5;
  --accent-green-border: #A7F3D0;

  --accent-purple: #7C3AED;
  --accent-purple-light: #F5F3FF;
  --accent-purple-border: #DDD6FE;

  /* Borders & Radii */
  --border-color: #E2E8F0;
  --border-strong: #CBD5E1;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* Soft Elevation Shadows with subtle vibrant ambient reflection */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 14px -1px rgba(15, 23, 42, 0.07), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 16px 36px -4px rgba(15, 23, 42, 0.1), 0 6px 12px -2px rgba(15, 23, 42, 0.04);
  --shadow-hover: 0 10px 25px -3px rgba(15, 23, 42, 0.09), 0 4px 10px -2px rgba(15, 23, 42, 0.05);
  --shadow-primary: 0 6px 18px rgba(13, 148, 136, 0.28);
  --shadow-primary-hover: 0 8px 26px rgba(13, 148, 136, 0.4);

  --sidebar-width: 265px;
  --header-height: 64px;
  --font-sans: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Cairo, Tahoma, 'Noto Sans Arabic', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  width: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================================
   PAGE & ELEMENT ANIMATIONS (LIVELY PHYSICS)
   ============================================================================ */
@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPop {
  0% {
    opacity: 0;
    transform: scale(0.94) translateY(14px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes toastSpring {
  0% {
    opacity: 0;
    transform: translateY(22px) scale(0.92);
  }
  60% {
    transform: translateY(-4px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes logoGlow {
  0%, 100% {
    box-shadow: 0 4px 14px rgba(13, 148, 136, 0.3);
  }
  50% {
    box-shadow: 0 6px 22px rgba(20, 184, 166, 0.55);
  }
}

@keyframes pulseSubtle {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.06);
    opacity: 0.9;
  }
}

/* ============================================================================
   LOGIN SCREEN
   ============================================================================ */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 10% 20%, #F0FDFA 0%, #F8FAFC 55%, #EEF2FF 100%);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 38px 34px;
  animation: modalPop 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-card:hover {
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
  transform: translateY(-2px);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.auth-brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  box-shadow: var(--shadow-primary);
  animation: logoGlow 4s infinite ease-in-out;
}

.auth-brand-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.auth-brand-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ============================================================================
   MAIN APP LAYOUT (SIDEBAR + CONTENT)
   ============================================================================ */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 100dvh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-app);
}

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-app);
  color: var(--text-primary);
  border-inline-end: 1px solid var(--border-color);
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.26s cubic-bezier(0.16, 1, 0.3, 1), padding 0.26s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

.app-shell.sidebar-collapsed .sidebar {
  width: 0;
  padding-inline: 0;
  border-inline-end-width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-restore-btn {
  display: none !important;
  position: fixed;
  top: 20px;
  inset-inline-start: 20px;
  z-index: 150;
  box-shadow: var(--shadow-md);
}

.app-shell.sidebar-collapsed .sidebar-restore-btn {
  display: inline-flex !important;
}

.app-shell.sidebar-collapsed .toolbar {
  padding-inline-start: 92px;
}

.sidebar-inner {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100vh - 20px);
  height: fit-content;
  transition: box-shadow 0.25s ease;
}

.sidebar-inner:hover {
  box-shadow: var(--shadow-md);
}

.sidebar-header {
  height: 48px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(180deg, #FFFFFF 0%, #FAFCFD 100%);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.sidebar-logo-badge {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-primary);
  animation: logoGlow 4s infinite ease-in-out;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.sidebar-logo:hover .sidebar-logo-badge {
  transform: rotate(-10deg) scale(1.12);
}

.sidebar-nav {
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}

.nav-group-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 6px 10px 2px;
  font-weight: 700;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6.5px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: inherit;
  flex-shrink: 0;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-item:hover {
  background: linear-gradient(90deg, #F0FDFA 0%, #FFFFFF 100%);
  color: var(--primary);
  transform: translateX(-4px);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.08);
}

[dir="ltr"] .nav-item:hover {
  transform: translateX(4px);
}

.nav-item:active {
  transform: scale(0.97) !important;
}

.nav-item-icon {
  width: 20px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-item:hover .nav-item-icon {
  transform: scale(1.22) rotate(-8deg);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(13, 148, 136, 0.12) 0%, rgba(20, 184, 166, 0.05) 100%);
  color: var(--primary);
  font-weight: 700;
  border-color: rgba(13, 148, 136, 0.22);
  border-inline-start: 3.5px solid var(--primary);
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.08);
  transform: none;
}

.nav-item.active .nav-item-icon {
  transform: scale(1.12);
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background-color: var(--bg-app);
}

.mobile-top-bar {
  display: none;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  justify-content: space-between;
}

.mobile-menu-btn {
  display: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  transition: all 0.2s;
}

.mobile-menu-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

.user-pill:hover {
  background: #E2E8F0;
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13.5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.page-content {
  flex: 1;
  padding: 24px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  animation: pageFadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.page-content-anim {
  animation: pageFadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* ============================================================================
   CARDS, GRIDS & METRICS
   ============================================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  inset-inline-start: 0;
  inset-inline-end: 0;
  height: 3px;
  background: transparent;
  transition: background 0.25s ease;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: #CBD5E1;
}

.stat-card:hover::before {
  background: var(--primary-gradient);
}

.stat-card-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-card-value {
  font-size: 23px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.4px;
}

.stat-card-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.card:hover {
  box-shadow: var(--shadow-hover);
  border-color: #CBD5E1;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: linear-gradient(180deg, #FFFFFF 0%, #FAFCFD 100%);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-body {
  padding: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* ============================================================================
   BUTTONS, INPUTS, FILTERS & TABS (TACTILE INTERACTIONS)
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  position: relative;
  overflow: hidden;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(1px) scale(0.97) !important;
  transition-duration: 0.08s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
  background: var(--primary-gradient-hover);
  box-shadow: var(--shadow-primary-hover);
  filter: brightness(1.04);
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--text-secondary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background: #F8FAFC;
  color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.14);
}

.btn-danger {
  background: var(--accent-red-light);
  color: var(--accent-red);
  border-color: var(--accent-red-border);
}

.btn-danger:hover {
  background: var(--accent-red);
  color: #FFFFFF;
  border-color: var(--accent-red);
  box-shadow: 0 6px 18px rgba(225, 29, 72, 0.32);
}

.btn-success {
  background: linear-gradient(135deg, #059669 0%, #10B981 100%);
  color: #fff;
  border: none;
  box-shadow: 0 6px 18px rgba(5, 150, 105, 0.26);
}

.btn-success:hover {
  background: linear-gradient(135deg, #047857 0%, #059669 100%);
  box-shadow: 0 8px 24px rgba(5, 150, 105, 0.38);
  filter: brightness(1.04);
}

.btn-expense {
  background: #FFF1F2;
  color: #BE123C;
  border-color: #FDA4AF;
  box-shadow: var(--shadow-sm);
}

.btn-expense:hover {
  background: #E11D48;
  color: #FFFFFF;
  border-color: #E11D48;
  box-shadow: 0 6px 18px rgba(225, 29, 72, 0.28);
}

.btn-copied {
  background: #ECFDF5 !important;
  color: #059669 !important;
  border-color: #A7F3D0 !important;
  transform: scale(1.05) !important;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 6px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.filters-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--bg-surface);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.form-control:hover {
  border-color: #94A3B8;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(13, 148, 136, 0.16), 0 2px 8px rgba(13, 148, 136, 0.08);
  background: #FFFFFF;
  transform: translateY(-1px);
}

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

.code-textarea {
  font-family: var(--font-mono);
  direction: ltr;
  text-align: left;
  font-size: 13px;
  background: #0F172A;
  color: #E2E8F0;
  min-height: 160px;
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Password field wrapper with show/hide toggle */
.password-field-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.password-field-wrapper .form-control {
  padding-inline-end: 42px;
}

.password-toggle-btn {
  position: absolute;
  inset-inline-end: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 19px !important;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s, transform 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#login-submit-btn {
  min-height: 48px !important;
  padding: 12px 20px !important;
  font-size: 15px !important;
  font-weight: 700 !important;
}

.password-toggle-btn:hover {
  opacity: 0.8;
  transform: scale(1.05);
}

.tabs-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 1px;
}

.tab-btn {
  padding: 9px 18px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-btn:hover {
  color: var(--primary);
  background: rgba(13, 148, 136, 0.05);
  transform: translateY(-1.5px);
}

.tab-btn:active {
  transform: scale(0.97);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: rgba(13, 148, 136, 0.07);
  transform: none;
}

/* ============================================================================
   TABLES & BADGES
   ============================================================================ */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  text-align: inherit;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12.5px;
  white-space: nowrap;
}

.data-table tbody tr {
  transition: all 0.18s ease;
}

.data-table tbody tr:hover {
  background-color: #F8FAFC;
  transform: scale(1.002);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.03);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: all 0.18s ease;
}

.badge-teal {
  background: var(--primary-light);
  color: var(--primary-hover);
  border-color: #99F6E4;
}

.badge-green {
  background: var(--accent-green-light);
  color: var(--accent-green);
  border-color: var(--accent-green-border);
}

.badge-amber {
  background: var(--accent-amber-light);
  color: var(--accent-amber);
  border-color: var(--accent-amber-border);
}

.badge-red {
  background: var(--accent-red-light);
  color: var(--accent-red);
  border-color: var(--accent-red-border);
}

.badge-blue {
  background: var(--accent-blue-light);
  color: var(--accent-blue);
  border-color: var(--accent-blue-border);
}

.badge-purple {
  background: var(--accent-purple-light);
  color: var(--accent-purple);
  border-color: var(--accent-purple-border);
}

.badge-slate {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.badge-pulse {
  animation: pulseSubtle 2.2s infinite ease-in-out;
}

/* ============================================================================
   KANBAN BOARD & PROGRESS BARS
   ============================================================================ */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(5, minmax(240px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.kanban-col {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 360px;
}

.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.kanban-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 13px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: grab;
}

.kanban-card:hover {
  transform: translateY(-3px) scale(1.01);
  box-shadow: var(--shadow-hover);
  border-color: #94A3B8;
}

.kanban-card:active {
  cursor: grabbing;
  transform: scale(0.99);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary-gradient);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ============================================================================
   CODE BLOCKS & CALENDAR
   ============================================================================ */
.code-block {
  background: #0F172A;
  color: #F8FAFC;
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr;
  text-align: left;
  line-height: 1.55;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

.prompt-block {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 14px;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  font-size: 13.5px;
  line-height: 1.65;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 8px;
}

.calendar-day-cell {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  min-height: 105px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s ease;
}

.calendar-day-cell:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.calendar-day-cell.today {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.calendar-day-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.calendar-event-pill {
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  transition: transform 0.15s ease;
}

.calendar-event-pill:hover {
  transform: scale(1.02);
}

/* ============================================================================
   MODALS, EMPTY STATES & TOASTS (SPRING PHYSICS)
   ============================================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalPop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid var(--border-color);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #FFFFFF 0%, #FAFCFD 100%);
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.toast-container {
  position: fixed;
  bottom: 24px;
  inset-inline-end: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: #0F172A;
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 10px 25px -4px rgba(15, 23, 42, 0.25);
  border-inline-start: 4px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastSpring 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: all 0.25s ease;
}

.toast.toast-exit {
  opacity: 0;
  transform: translateY(12px) scale(0.9);
}

.toast.error {
  border-inline-start-color: var(--accent-red);
  background: #1E1B2E;
}

.toast-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.toast.error .toast-icon {
  background: var(--accent-red);
}

/* ============================================================================
   ENHANCED UX COMPONENTS (SEARCH, STICKY TABLES, DROPDOWNS, KANBAN DRAG)
   ============================================================================ */
.search-box-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-box-wrap .form-control {
  padding-inline-end: 30px;
}

.search-clear-btn {
  position: absolute;
  inset-inline-end: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  padding: 0;
  line-height: 1;
}

.search-clear-btn.visible {
  display: inline-flex;
}

.search-clear-btn:hover {
  background: var(--accent-red-light);
  color: var(--accent-red);
  border-color: var(--accent-red-border);
}

.docs-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
}

.data-table.sticky-first th:first-child,
.data-table.sticky-first td:first-child {
  position: sticky;
  inset-inline-start: 0;
  z-index: 2;
  background: var(--bg-surface);
  box-shadow: -2px 0 6px rgba(15, 23, 42, 0.04);
}

[dir="ltr"] .data-table.sticky-first th:first-child,
[dir="ltr"] .data-table.sticky-first td:first-child {
  box-shadow: 2px 0 6px rgba(15, 23, 42, 0.04);
}

.data-table.sticky-first th:first-child {
  background: var(--bg-subtle);
  z-index: 3;
}

.data-table.sticky-first tbody tr:hover td:first-child {
  background: #F8FAFC;
}

.kanban-col.drag-over {
  background: var(--primary-subtle);
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px rgba(13, 148, 136, 0.25);
}

.kanban-card.dragging {
  opacity: 0.45;
  transform: scale(0.96);
}

.row-actions-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.row-actions-dropdown {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 4px);
  min-width: 175px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 1200;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.row-actions-dropdown.open {
  display: flex;
  animation: fadeIn 0.15s ease-out;
}

.row-action-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  text-align: start;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.row-action-item:hover {
  background: var(--bg-subtle);
  color: var(--primary);
}

.row-action-item.danger {
  color: var(--accent-red);
}

.row-action-item.danger:hover {
  background: var(--accent-red-light);
}

.empty-state-icon {
  font-size: 34px;
  margin-bottom: 10px;
  opacity: 0.85;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(2px);
  z-index: 95;
  animation: fadeIn 0.2s ease;
}

/* ============================================================================
   RESPONSIVE DESIGN SYSTEM (MOBILE, TABLET & DESKTOP ADAPTATION)
   ============================================================================ */

/* Base components for drawer footer & bottom navigation */
.sidebar-user-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mobile-close-drawer-btn {
  display: none;
}

.mobile-bottom-nav {
  display: none;
}

/* ----------------------------------------------------------------------------
   TABLET & MOBILE BREAKPOINT (<= 992px)
   ---------------------------------------------------------------------------- */
@media (max-width: 992px) {
  /* Grids collapse cleanly to single column */
  .grid-2, .grid-3, .grid-4, .docs-layout {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Cards have optimized mobile padding */
  .card {
    margin-bottom: 14px !important;
    border-radius: var(--radius-sm) !important;
  }

  .card-header {
    padding: 12px 14px !important;
    gap: 8px !important;
  }

  .card-title {
    font-size: 14.5px !important;
  }

  .card-body {
    padding: 14px 12px !important;
  }

  /* Top bar on mobile */
  .mobile-top-bar {
    display: flex !important;
    padding: 10px 16px !important;
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-bottom: 1px solid var(--border-color) !important;
    align-items: center !important;
    justify-content: space-between !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 85 !important;
  }

  .mobile-menu-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 6px 12px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    border-radius: var(--radius-sm) !important;
    background: var(--bg-app) !important;
    border: 1px solid var(--border-color) !important;
  }

  .mobile-close-drawer-btn {
    display: inline-flex !important;
  }

  .sidebar-collapse-btn {
    display: none !important;
  }

  /* Sidebar transformed into smooth mobile drawer */
  .sidebar-backdrop.open {
    display: block !important;
  }

  .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    inset-inline-start: 0 !important;
    width: min(310px, 85vw) !important;
    height: 100vh !important;
    height: 100dvh !important;
    padding: 0 !important;
    background: var(--bg-surface) !important;
    box-shadow: -8px 0 32px rgba(15, 23, 42, 0.28) !important;
    transform: translateX(100%) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s !important;
    z-index: 100 !important;
    visibility: hidden;
    pointer-events: none;
  }

  [dir="ltr"] .sidebar {
    transform: translateX(-100%) !important;
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.28) !important;
  }

  .sidebar.open {
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .sidebar-inner {
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    height: 100% !important;
    max-height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .sidebar-header {
    height: 56px !important;
    padding: 0 16px !important;
  }

  .sidebar-nav {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 10px 10px 20px 10px !important;
  }

  .sidebar-nav .nav-item {
    padding: 11px 14px !important;
    font-size: 14px !important;
    border-radius: var(--radius-sm) !important;
    min-height: 42px !important;
  }

  /* Mobile Bottom Navigation Bar */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(58px + env(safe-area-inset-bottom, 0px)) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    border-top: 1px solid var(--border-color) !important;
    box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08) !important;
    z-index: 90 !important;
    justify-content: space-around !important;
    align-items: stretch !important;
  }

  .bottom-nav-item {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    background: transparent !important;
    border: none !important;
    padding: 4px 2px !important;
    color: var(--text-muted) !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: color 0.18s ease, transform 0.18s ease !important;
    user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
  }

  .bottom-nav-item .bottom-nav-icon {
    font-size: 18px !important;
    line-height: 1.2 !important;
    margin-bottom: 2px !important;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  .bottom-nav-item.active {
    color: var(--primary) !important;
  }

  .bottom-nav-item.active .bottom-nav-icon {
    transform: scale(1.15) !important;
  }

  /* Page content mobile bottom padding */
  .page-content {
    padding: 14px 14px calc(80px + env(safe-area-inset-bottom, 20px)) 14px !important;
  }

  /* Toolbars and filters layout */
  .toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    margin-bottom: 14px !important;
  }

  .toolbar h2 {
    font-size: 18px !important;
    margin: 0 !important;
  }

  .filters-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    gap: 8px !important;
  }

  .toolbar .search-box-wrap {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 100% !important;
  }

  .toolbar .filters-bar .form-control {
    flex: 1 1 calc(50% - 6px) !important;
    min-width: 130px !important;
    width: auto !important;
  }

  .toolbar .filters-bar .btn {
    flex: 1 1 auto !important;
    min-height: 38px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 13px !important;
    white-space: nowrap !important;
  }

  /* Single-line horizontal scrollable tabs */
  .tabs-bar {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 6px !important;
    padding-bottom: 6px !important;
    margin-bottom: 14px !important;
    scrollbar-width: none !important;
  }

  .tabs-bar::-webkit-scrollbar {
    display: none !important;
  }

  .tab-btn {
    flex-shrink: 0 !important;
    padding: 8px 14px !important;
    font-size: 13px !important;
    min-height: 38px !important;
  }

  /* Responsive data tables */
  .table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 12px !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: inset -8px 0 10px -6px rgba(15, 23, 42, 0.08) !important;
  }

  .data-table {
    min-width: 660px !important;
    width: 100% !important;
  }

  .data-table th,
  .data-table td {
    padding: 10px 12px !important;
    font-size: 13px !important;
    white-space: nowrap !important;
  }

  .data-table td:nth-child(2) {
    white-space: normal !important;
    min-width: 140px !important;
  }

  /* Kanban mobile swipe */
  .kanban-board {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 12px !important;
    padding-bottom: 12px !important;
    scroll-snap-type: x mandatory !important;
  }

  .kanban-col {
    min-width: 270px !important;
    width: 270px !important;
    flex-shrink: 0 !important;
    scroll-snap-align: start !important;
  }
}

/* ----------------------------------------------------------------------------
   SMARTPHONE VIEWPORT BREAKPOINT (<= 640px)
   ---------------------------------------------------------------------------- */
@media (max-width: 640px) {
  /* Metrics grid: 2 clean columns side-by-side */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
  }

  .stat-card {
    padding: 12px 14px !important;
    gap: 4px !important;
  }

  .stat-card .stat-value {
    font-size: 18px !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
  }

  .stat-card .stat-label {
    font-size: 11.5px !important;
  }

  .stat-card .stat-meta {
    font-size: 10.5px !important;
  }

  /* Modals: bottom-sheet appearance */
  .modal-backdrop {
    padding: 0 !important;
    align-items: flex-end !important;
    background: rgba(15, 23, 42, 0.6) !important;
  }

  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92dvh !important;
    margin-bottom: 0 !important;
    animation: slideUpModal 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  .modal-header {
    padding: 14px 16px !important;
  }

  .modal-title {
    font-size: 15px !important;
  }

  .modal-body {
    padding: 16px 14px !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .modal-footer {
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 12px)) 14px !important;
    background: var(--bg-surface) !important;
    border-top: 1px solid var(--border-color) !important;
    display: flex !important;
    gap: 8px !important;
  }

  .modal-footer .btn {
    flex: 1 !important;
    min-height: 42px !important;
    font-size: 14px !important;
  }

  /* Auth Card on mobile phones */
  .auth-wrapper {
    padding: 16px !important;
  }

  .auth-card {
    padding: 24px 18px !important;
    border-radius: 16px !important;
  }

  .auth-brand {
    gap: 10px !important;
    margin-bottom: 18px !important;
  }

  .auth-brand-title {
    font-size: 18px !important;
  }

  .auth-brand-subtitle {
    font-size: 12px !important;
  }

  .form-control {
    font-size: 15px !important;
    padding: 10px 12px !important;
  }

  #login-submit-btn {
    min-height: 48px !important;
    font-size: 15px !important;
    font-weight: 700 !important;
  }

  /* Balanced 2-row layout for finance action buttons */
  .finance-action-buttons {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .finance-action-buttons > button:last-child:nth-child(odd) {
    grid-column: span 2 !important;
  }

  .finance-action-buttons .btn {
    min-height: 42px !important;
    font-size: 13.5px !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Horizontal swipeable period chips */
  .period-filters-bar {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 6px !important;
    align-items: center !important;
    scrollbar-width: none !important;
    padding-bottom: 4px !important;
    width: 100% !important;
  }

  .period-filters-bar::-webkit-scrollbar {
    display: none !important;
  }

  .period-filters-bar .btn {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    min-height: 36px !important;
    padding: 6px 12px !important;
  }

  /* Vault password row stacks vertically on mobile */
  .vault-pwd-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .vault-pwd-row .btn {
    width: 100% !important;
    min-height: 42px !important;
  }
}

@keyframes slideUpModal {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Very narrow devices (<= 360px) */
@media (max-width: 360px) {
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .toolbar .filters-bar .form-control {
    flex: 1 1 100% !important;
  }
}

/* ---------------------------------------------------------------------------
   Network Connection & Offline Sync Status Badges
   --------------------------------------------------------------------------- */
.network-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.network-status-badge.online {
  background: #ECFDF5;
  color: #059669;
  border: 1px solid #A7F3D0;
}

.network-status-badge.online:hover {
  background: #D1FAE5;
}

.network-status-badge.offline {
  background: #FEF3C7;
  color: #B45309;
  border: 1px solid #FCD34D;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.2);
}

.network-status-badge.offline:hover {
  background: #FDE68A;
}

.network-status-badge.syncing {
  background: #EFF6FF;
  color: #2563EB;
  border: 1px solid #BFDBFE;
}

.network-badge-dot {
  font-size: 9px;
  line-height: 1;
}

.network-badge-dot.pulse {
  display: inline-block;
  animation: badgePulse 1.6s infinite ease-in-out;
}

.network-badge-dot.spin {
  display: inline-block;
  animation: badgeSpin 1s infinite linear;
  font-size: 12px;
}

@keyframes badgePulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.2);
  }
}

@keyframes badgeSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Fixed Copy Button on Library Cards */
.lib-fixed-copy-btn {
  min-width: 90px !important;
  height: 34px !important;
  font-size: 12.5px !important;
  font-weight: 700 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 5px !important;
  flex-shrink: 0 !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.2) !important;
}

/* ============================================================================
   CLICKABLE STAT CARDS, CUSTOM SYSTEM DIALOGS, FILTER DRAWER & FX EXCHANGE
   ============================================================================ */
.stat-card.clickable,
.card.clickable {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.stat-card.clickable:hover,
.card.clickable:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 8px 20px -6px rgba(15, 118, 110, 0.18);
}

.stat-card.clickable:active,
.card.clickable:active {
  transform: scale(0.99);
}

/* Stacked Custom System Confirmation Dialog */
.system-dialog-backdrop {
  z-index: 1600 !important;
  background: rgba(15, 23, 42, 0.58) !important;
}

.system-dialog-box {
  max-width: 460px !important;
}

.system-dialog-header.danger {
  background: linear-gradient(180deg, #FFF5F5 0%, #FFFFFF 100%);
  border-bottom-color: #FECACA;
}

.system-dialog-header.warning {
  background: linear-gradient(180deg, #FFFBEB 0%, #FFFFFF 100%);
  border-bottom-color: #FDE68A;
}

.btn-warning-confirm {
  background: #D97706;
  color: #fff;
  border: 1px solid #B45309;
}

.btn-warning-confirm:hover {
  background: #B45309;
  color: #fff;
}

/* Collapsible Filter Drawer & Active Highlight */
.filter-toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.filter-btn-active {
  background: #FEF3C7 !important;
  color: #92400E !important;
  border: 1.5px solid #F59E0B !important;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18) !important;
  font-weight: 700 !important;
}

.filter-btn-active:hover {
  background: #FDE68A !important;
}

.filter-active-badge {
  background: #D97706;
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
}

.filter-drawer {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.18s ease-out;
}

.filter-drawer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 8px;
}

/* Currency Exchange Preview Components */
.fx-balance-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.fx-preview-box {
  background: rgba(13, 148, 136, 0.06);
  border: 1px solid rgba(13, 148, 136, 0.25);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}

/* Reverted Activity Log Row */
.activity-row-reverted {
  background: rgba(239, 68, 68, 0.04) !important;
}

.activity-row-reverted td {
  color: var(--text-secondary);
}

/* ============================================================================
   MOBILE CARD-STACK TABLE TRANSFORMATION (<= 768px — ZERO HORIZONTAL SCROLL)
   ============================================================================ */
@media (max-width: 768px) {
  .table-responsive {
    overflow-x: visible !important;
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .data-table:not(.keep-table) {
    min-width: 0 !important;
    width: 100% !important;
    display: block !important;
    border: none !important;
  }

  .data-table:not(.keep-table) thead {
    display: none !important;
  }

  .data-table:not(.keep-table) tbody {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .data-table:not(.keep-table) tbody tr {
    display: block !important;
    width: 100% !important;
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 12px !important;
    padding: 12px 14px !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05) !important;
  }

  .data-table:not(.keep-table) tbody tr:hover {
    transform: none !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05) !important;
  }

  .data-table:not(.keep-table) tbody tr:hover td:first-child {
    background: transparent !important;
  }

  .data-table:not(.keep-table) tbody td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    gap: 10px !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 7px 0 !important;
    border: none !important;
    border-bottom: 1px dashed var(--border-color) !important;
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    text-align: end !important;
    font-size: 13px !important;
  }

  .data-table:not(.keep-table) tbody td .badge {
    white-space: normal !important;
    text-align: start !important;
    line-height: 1.45 !important;
    max-width: 100% !important;
    word-break: break-word !important;
  }

  .data-table:not(.keep-table) tbody td > div {
    max-width: 100% !important;
    flex-wrap: wrap !important;
    justify-content: flex-end !important;
  }

  .data-table:not(.keep-table) tbody td:first-child > div {
    justify-content: flex-start !important;
  }

  .data-table:not(.keep-table) tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-muted);
    text-align: start;
    flex-shrink: 0;
    max-width: 44%;
  }

  .data-table:not(.keep-table) tbody td:first-child {
    position: static !important;
    inset-inline-start: auto !important;
    z-index: auto !important;
    box-shadow: none !important;
    background: transparent !important;
    border-bottom: 1.5px solid var(--border-color) !important;
    padding: 0 0 9px 0 !important;
    margin-bottom: 3px !important;
    font-size: 14px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: start !important;
  }

  .data-table:not(.keep-table) tbody td:first-child::before {
    font-size: 10.5px;
    margin-bottom: 2px;
    max-width: 100%;
  }

  .data-table:not(.keep-table) tbody td:last-child {
    border-bottom: none !important;
    padding-bottom: 0 !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] {
    border-bottom: none !important;
    padding: 10px 0 0 0 !important;
    justify-content: flex-start !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    text-align: start !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"]::before {
    display: none !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] > .btn {
    flex: 1 1 auto;
    min-height: 38px;
    justify-content: center;
  }

  /* On mobile cards, expand row-actions-menu inline as direct touchable buttons (never clipped by card overflow) */
  .data-table:not(.keep-table) tbody td[data-is-actions="true"] > div {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: stretch !important;
    gap: 8px !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] .row-actions-menu {
    width: 100% !important;
    display: flex !important;
    position: static !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] .row-actions-menu > .btn {
    display: none !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] .row-actions-dropdown {
    display: flex !important;
    position: static !important;
    inset: auto !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    width: 100% !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    animation: none !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] .row-action-item {
    flex: 1 1 calc(50% - 4px) !important;
    width: auto !important;
    min-height: 38px !important;
    justify-content: center !important;
    text-align: center !important;
    padding: 8px 10px !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 8px !important;
    background: var(--bg-surface) !important;
    box-shadow: var(--shadow-sm) !important;
    font-size: 12.5px !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-actions="true"] .row-action-item.danger {
    background: var(--accent-red-light) !important;
    border-color: var(--accent-red-border) !important;
    color: var(--accent-red) !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-empty="true"] {
    display: block !important;
    text-align: center !important;
    border-bottom: none !important;
  }

  .data-table:not(.keep-table) tbody td[data-is-empty="true"]::before {
    display: none !important;
  }

  .fx-balance-strip {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}
