:root {
  --primary-color: #2c3e50;
  --secondary-color: #3498db;
  --accent-color: #e74c3c;
  --text-color: #2c3e50;
  --light-bg: #f8f9fa;
  --success-color: #2ecc71;
  --danger-color: #e74c3c;
  --warning-color: #f1c40f;
  --sidebar-width: 250px;
  --header-height: 60px;
  --transition-speed: 0.3s;

  /* responsive breakpoints */
  --bp-sm: 576px;
  --bp-md: 768px;
  --bp-lg: 992px;
  --bp-xl: 1200px;
}

/* Base / typography */
html {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
*,
*::before,
*::after {
  box-sizing: inherit;
}
body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f5f7fa;
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  font-size: 14px;
}

/* Dashboard Layout */
.dashboard-container {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
  gap: 20px;
  transition: all var(--transition-speed);
}

/* Sidebar Styles */
.sidebar {
  width: var(--sidebar-width);
  background: var(--primary-color);
  color: white;
  position: fixed;
  height: 100vh;
  transition: transform var(--transition-speed), opacity var(--transition-speed);
  z-index: 1000;
  left: 0;
  top: 0;
  padding-bottom: 40px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* When sidebar is toggled (JS can toggle 'active' class) */
.sidebar.hidden {
  transform: translateX(-105%);
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-header i {
  font-size: 24px;
  color: var(--secondary-color);
}

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

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav li {
  margin: 5px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  transition: background var(--transition-speed), color var(--transition-speed);
  border-radius: 8px;
  gap: 10px;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.sidebar-nav li.active a {
  background: var(--secondary-color);
  color: white;
}

.sidebar-nav i {
  margin-right: 10px;
  width: 20px;
  text-align: center;
}

/* Footer area inside sidebar (user info) */
.sidebar .sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.03);
}

/* Main Content Styles */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 20px;
  transition: margin-left var(--transition-speed);
  min-height: 100vh;
}

/* If sidebar is hidden, collapse main content margin on small screens via JS toggling of .sidebar.hidden */
@media (max-width: 992px) {
  .sidebar.hidden + .main-content,
  .main-content {
    margin-left: 0;
  }
}

/* Top Navigation */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0 20px 0;
  margin-bottom: 20px;
}

/* Use fluid search on small screens */
.search-bar {
  position: relative;
  width: 300px;
  min-width: 120px;
  transition: width var(--transition-speed);
}

.search-bar input {
  width: 100%;
  padding: 10px 15px 10px 40px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  transition: all var(--transition-speed);
  font-size: 0.95rem;
}

.search-bar i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #666;
  font-size: 0.95rem;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.notifications {
  position: relative;
  cursor: pointer;
}

.notifications .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger-color);
  color: white;
  border-radius: 50%;
  padding: 3px 6px;
  font-size: 12px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.user-profile img {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  object-fit: cover;
}

/* Card Styles */
.card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
  transition: transform var(--transition-speed),
    box-shadow var(--transition-speed);
}

.card:hover {
  transform: translateY(-6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 16px;
}

/* Summary Cards */
.summary-cards .card {
  border: none;
  border-radius: 12px;
  overflow: hidden;
}

/* Icons */
.icon-box {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
}

.bg-primary {
  background: var(--primary-color);
}
.bg-success {
  background: var(--success-color);
}
.bg-danger {
  background: var(--danger-color);
}
.bg-info {
  background: var(--secondary-color);
}

/* Charts */
.charts-row .card {
  height: 400px;
  display: flex;
  flex-direction: column;
}

.chart-container {
  position: relative;
  height: 100%;
  width: 100%;
}

/* Table Styles (make tables horizontally scrollable on small screens) */
.table {
  margin: 0;
  width: 100%;
  display: table;
  border-collapse: collapse;
  table-layout: auto;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Adjust table text and spacing */
.table th {
  border-top: none;
  font-weight: 600;
  color: #666;
  white-space: nowrap;
  padding: 10px 12px;
}

.table td {
  vertical-align: middle;
  padding: 10px 12px;
  white-space: nowrap;
}

/* Badges */
.badge {
  padding: 5px 10px;
  border-radius: 20px;
  font-weight: 500;
  font-size: 0.85rem;
}

/* Modal Styles */
.modal-content {
  border-radius: 12px;
  border: none;
}

.modal-header {
  border-bottom: 1px solid #eee;
  padding: 14px 18px;
}

.modal-body {
  padding: 14px 18px;
}

/* Form Styles */
.form-control,
.form-select {
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  transition: all var(--transition-speed);
  font-size: 0.95rem;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 0 0.15rem rgba(52, 152, 219, 0.15);
}

/* Buttons */
.btn {
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 500;
  transition: all var(--transition-speed);
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--secondary-color);
  border-color: var(--secondary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-color);
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  animation: fadeIn 0.45s ease-out forwards;
}

/* Notification */
.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  padding: 15px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  animation: slideIn 0.3s ease-out;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.notification.alert-success {
  background-color: rgba(46, 204, 113, 0.95);
  color: white;
  border: none;
}
.notification.alert-error {
  background-color: rgba(231, 76, 60, 0.95);
  color: white;
  border: none;
}

.notification i {
  font-size: 18px;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}
.notification.hide {
  animation: slideOut 0.3s ease-out forwards;
}

/* Custom Scrollbar (subtle) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.18);
}

/* Mobile Toggle Button (JS can toggle .sidebar.hidden to control sidebar) */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 1100;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 6px;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

/* --- RESPONSIVE RULES --- */

/* Large tablets and down: reduce sidebar width and padding */
@media (max-width: 1200px) {
  :root {
    --sidebar-width: 220px;
  }
  .sidebar {
    width: var(--sidebar-width);
  }
  .main-content {
    margin-left: var(--sidebar-width);
  }
}

/* Laptops and smaller: refine layout */
@media (max-width: 992px) {
  :root {
    --sidebar-width: 200px;
  }

  /* Stack layout for small viewports: allow sidebar overlay */
  .dashboard-container {
    align-items: stretch;
  }

  /* Hide sidebar by default on small screens (JS should remove .hidden to open) */
  .sidebar {
    transform: translateX(-105%);
    opacity: 0;
    pointer-events: none;
    width: var(--sidebar-width);
  }
  .sidebar.active,
  .sidebar.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
  }

  /* Show mobile toggle */
  .mobile-toggle {
    display: flex;
  }

  /* main content occupies full width when sidebar hidden */
  .main-content {
    margin-left: 0;
    padding: 16px;
  }

  /* Make search smaller */
  .search-bar {
    width: 180px;
    min-width: 120px;
  }

  /* Chart heights reduce */
  .charts-row .card {
    height: auto;
    min-height: 260px;
  }

  /* make tables scroll horizontally on small screens */
  .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* reduce card padding slightly for compactness */
  .card-header {
    padding: 12px;
  }
  .card-body {
    padding: 12px;
  }
}

/* Tablets and mobile */
@media (max-width: 768px) {
  body {
    font-size: 13px;
  }

  /* Sidebar smaller and full-width overlay when active */
  .sidebar {
    width: 220px;
  }
  .sidebar.active,
  .sidebar.open {
    width: 80%;
    max-width: 320px;
  }

  /* Top nav: stack controls */
  .top-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .search-bar {
    display: none; /* optional: hide search on very small */
  }

  /* Summary card grid stack */
  .summary-cards .card {
    margin-bottom: 14px;
  }

  /* Chart card heights reduced for mobile */
  .charts-row .card {
    min-height: 220px;
  }

  /* make form controls and buttons larger for touch */
  .form-control,
  .form-select,
  .btn {
    font-size: 1rem;
    padding: 12px 14px;
  }

  /* tighten table padding */
  .table th,
  .table td {
    padding: 8px 10px;
    font-size: 0.95rem;
  }

  /* Ensure content within main-content is comfortable */
  .main-content {
    padding: 12px;
  }
}

/* Small phones */
@media (max-width: 576px) {
  html {
    font-size: 14px;
  }
  body {
    font-size: 13px;
  }

  /* make sidebar overlay nearly full-screen when open */
  .sidebar.active,
  .sidebar.open {
    width: 96%;
    max-width: 420px;
  }

  /* further reduce chart min-height */
  .charts-row .card {
    min-height: 180px;
  }

  /* Cards and controls full width */
  .card {
    border-radius: 10px;
  }
  .btn {
    width: auto;
    min-width: 44px;
  }

  /* Tables: make each row more compact on very small screens */
  .table th,
  .table td {
    padding: 6px 8px;
    font-size: 0.92rem;
  }

  .mobile-toggle {
    left: 12px;
    top: 12px;
    width: 42px;
    height: 42px;
  }
}

/* Accessibility / focus */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(52, 152, 219, 0.14);
  outline-offset: 2px;
}

/* Small helpers */
.muted {
  color: #6c737a;
  font-size: 0.95rem;
}
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Utility: horizontally center small content when table empty */
.empty-state {
  text-align: center;
  padding: 36px 12px;
  color: #7c868f;
}

/* Keep touch targets comfortable */
button,
.btn,
.mobile-toggle {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
}

/* End of file */
/* === Mobile-only overrides (paste at end of style.css) === */
@media (max-width: 767px) {

  /* Prevent accidental horizontal scrolling */
  html, body {
    overflow-x: hidden !important;
  }

  /* Sidebar: off-canvas — hidden by default; add .open to show */
  .sidebar {
    transform: translateX(-110%);
    width: 90%;
    max-width: 340px;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1400;
    padding: 14px;
    transition: transform 260ms ease-in-out, box-shadow 260ms;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open,
  .sidebar.active {
    transform: translateX(0);
    box-shadow: 0 30px 60px rgba(0,0,0,0.45);
  }

  /* Hide desktop left margin — let main-content be full width on mobile */
  .main-content {
    margin-left: 0 !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Mobile header: make it compact and stack if needed */
  .top-nav {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
  }

  /* Hide the large search box on narrow phones (keeps header compact) */
  .search-bar { display: none !important; }

  /* Reduce global paddings and font sizes for mobile */
  body { font-size: 13px; }
  .card { padding: 10px; border-radius: 10px; }
  .card-header { padding: 10px 8px; }
  .card-body { padding: 8px; }

  /* Summary / stats: stack vertically and take full width */
  .summary-row { display: flex; flex-direction: column; gap: 8px; }
  .summary-col { width: 100%; min-width: 0; }

  /* Chart cards: constrain height so chart won't overflow the screen */
  .charts-row .card { min-height: 200px; max-height: 360px; overflow: hidden; }
  .chart-container, canvas { width: 100% !important; height: auto !important; max-height: 320px; }

  /* Transactions: ensure rows wrap and don't push width */
  .transactions-list { max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-right: 6px; }
  .transaction-row { flex-wrap: wrap; gap: 8px; align-items: flex-start; }

  /* Tables: switch to horizontal scroll inside container, do not force page width */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .table { min-width: 420px; } /* table will scroll inside .table-responsive */
  /* if your table is small, remove min-width with JS or additional class; this avoids breaking readability */
  .table th, .table td { padding: 8px 10px; font-size: 13px; white-space: nowrap; }

  /* Forms / inputs / buttons bigger for touch */
  .form-control, .form-select { padding: 10px 12px; font-size: 1rem; }
  .btn { min-height: 44px; padding: 10px 12px; }

  /* Mobile toggle button visible only on mobile */
  .mobile-toggle { display: inline-flex !important; position: fixed; top: 10px; left: 10px; z-index: 1500; }

  /* Notification adjust */
  .notification { right: 12px; left: 12px; max-width: calc(100% - 24px); }

  /* Final horizontal overflow safeguards */
  html, body, .dashboard-container, .main-content, .sidebar, .card, .transaction-row, .table-responsive {
    overflow-x: hidden !important;
    max-width: 100% !important;
  }
}

/* === Tiny extra step for very small phones (<= 420px) === */
@media (max-width: 420px) {
  .charts-row .card { min-height: 180px; }
  body { font-size: 12.8px; }
  .card { padding: 9px; }
  .mobile-toggle { width: 42px; height: 42px; top: 8px; left: 8px; }
  .table { min-width: 320px; } /* smaller min-width to reduce scrolling when possible */
}

.user-profile .dropdown:hover .dropdown-menu {
  display: block;
  margin-top: 0; /* Prevent jump */
}

/* Ensure transactions table scrolls on mobile */
@media (max-width: 768px) {
  .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .table-responsive table {
    min-width: 600px; /* ensure columns don't squish too much */
  }
}
/* +++++++++++++++++++++++ */

/* Limit Recent Transactions height and enable vertical scroll */
.transactions-scroll {
  max-height: 400px; /* adjust this height as you prefer */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ======================== */
/* ---------- Recent Transactions scroll behaviour ---------- */

/* Make the table area grow, then scroll when it reaches max height */
.recent-transactions-card {
  /* clip inner content to card rounded corners so scroll area visually merges */
  overflow: hidden;
  position: relative;
}

/* The actual scrollable area inside the card */
.transactions-scroll {
  max-height: calc(85vh - 320px); /* default - fine-tune below in JS for exact fit */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: transparent;   /* let the card show through */
  padding: 0;                /* remove internal extra padding so table aligns with card edges */
  margin: 0;
}

/* Ensure the table takes full width without extra spacing inside the scroll container */
.transactions-scroll .table {
  margin-bottom: 0;
  background: transparent;
  border-collapse: collapse;
}

/* Make the table header sticky inside the scrollable area so headers remain visible */
.transactions-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 6;               /* above rows */
  background: #fff;         /* match the card/table header color */
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}

/* small visual tweak so the bottom of card and table align perfectly */
.recent-transactions-card .card-header {
  z-index: 7;
  position: relative;
}

/* mobile-specific tuning */
@media (max-width: 992px) {
  .transactions-scroll {
    max-height: calc(100vh - 260px);
  }
}

/* fallback (small phone) */
@media (max-width: 576px) {
  .transactions-scroll {
    max-height: calc(100vh - 220px);
  }
}
