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

:root {
  /* Dark Mode Palette (Default) */
  --bg-primary: #0a0c10;
  --bg-secondary: #121620;
  --bg-card: rgba(20, 26, 38, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --accent-color: #6366f1; /* Indigo */
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.6);
  --backdrop-blur: 16px;
  --sidebar-width: 260px;
}

/* Light Mode Overrides */
body.light-theme {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.8);
  --border-color: rgba(0, 0, 0, 0.08);
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent-color: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --accent-glow: rgba(79, 70, 229, 0.15);
  --success-color: #059669;
  --warning-color: #d97706;
  --danger-color: #dc2626;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08);
  --backdrop-blur: 10px;
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

/* Layout Architecture */
.app-container {
  display: flex;
  width: 100vw;
  min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 2rem;
}

.brand-logo {
  width: 38px;
  height: 38px;
  background: var(--accent-gradient);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: 0 0 15px var(--accent-glow);
}

.brand-name {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-grow: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.04);
}

body.light-theme .nav-link:hover, body.light-theme .nav-link.active {
  background-color: rgba(0, 0, 0, 0.03);
}

.nav-link.active {
  background: var(--accent-gradient) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-primary);
  border: 2px solid var(--accent-color);
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Main Content Area */
.main-content {
  margin-left: var(--sidebar-width);
  flex-grow: 1;
  padding: 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Theme Toggle Switch */
.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  transform: scale(1.05);
  border-color: var(--accent-color);
}

/* Premium Card Styles (Glassmorphism) */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(var(--backdrop-blur));
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  margin-bottom: 2rem;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Table Design */
.premium-table-container {
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid var(--border-color);
}

.premium-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
}

.premium-table th {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 1rem 1.25rem;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
}

.premium-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.premium-table tbody tr {
  transition: background-color 0.2s ease;
}

.premium-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

body.light-theme .premium-table tbody tr:hover {
  background-color: rgba(0, 0, 0, 0.01);
}

/* Custom Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-active {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-suspended {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--danger-color);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-warning {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--warning-color);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Action Buttons */
.btn-premium {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.btn-premium-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-premium-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.btn-premium-secondary {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-premium-secondary:hover {
  background-color: rgba(255, 255, 255, 0.04);
  border-color: var(--text-secondary);
}

body.light-theme .btn-premium-secondary:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.btn-premium-danger {
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}

.btn-premium-danger:hover {
  background-color: var(--danger-color);
  color: #fff;
}

.btn-icon-only {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
}

/* Form Styling */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control-premium {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.25s ease;
}

body.light-theme .form-control-premium {
  background-color: rgba(255, 255, 255, 0.5);
}

.form-control-premium:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background-color: rgba(0, 0, 0, 0.3);
}

body.light-theme .form-control-premium:focus {
  background-color: #ffffff;
}

.form-select-premium {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1.25rem;
  padding-right: 2.5rem;
}

/* Switch UI */
.switch-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.switch-label {
  font-size: 0.9rem;
  font-weight: 500;
}

/* Modern Login Screen Specifics */
.login-body {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
              radial-gradient(circle at 90% 80%, rgba(168, 85, 247, 0.15) 0%, transparent 40%),
              var(--bg-primary);
}

.login-card {
  width: 100%;
  max-width: 440px;
  padding: 3rem 2.5rem;
  margin: 1.5rem;
}

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

/* Responsive adjustments */
@media (max-width: 992px) {
  .sidebar {
    width: 70px;
    padding: 1rem 0.5rem;
  }
  .sidebar .brand-name,
  .sidebar .nav-link span,
  .sidebar .user-info,
  .sidebar .sidebar-footer {
    display: none;
  }
  .sidebar .brand-section {
    justify-content: center;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
  }
  .sidebar .nav-link {
    justify-content: center;
    padding: 0.75rem;
  }
  .main-content {
    margin-left: 70px;
    padding: 1.5rem;
  }
}

@media (max-width: 576px) {
  .content-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .main-content {
    padding: 1rem;
  }
  .glass-card {
    padding: 1.25rem;
  }
}

/* Dashboard & Financial Module Specifics */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-gradient);
}

.stat-card.premium::before {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
}

.stat-card.budget::before {
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
}

.stat-card.revenue::before {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
}

.stat-card.overdue::before {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -1px;
  margin-top: 0.5rem;
  background: var(--text-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Custom CSS Bar Chart */
.chart-container {
  display: flex;
  flex-direction: column;
  height: 300px;
  margin: 2rem 0;
}

.chart-bars {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  height: 250px;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  gap: 0.5rem;
}

.chart-bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}

.chart-bar-pair {
  display: flex;
  align-items: flex-end;
  width: 100%;
  max-width: 40px;
  height: 100%;
  gap: 4px;
}

.bar-expected, .bar-received {
  flex: 1;
  border-radius: 4px 4px 0 0;
  position: relative;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.bar-expected {
  background: linear-gradient(to top, rgba(99, 102, 241, 0.2), var(--accent-color));
}

.bar-received {
  background: linear-gradient(to top, rgba(16, 185, 129, 0.2), #10b981);
}

.bar-expected:hover, .bar-received:hover {
  transform: scaleY(1.05);
  opacity: 0.9;
}

.bar-tooltip {
  visibility: hidden;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  z-index: 10;
  margin-bottom: 8px;
}

.bar-expected:hover .bar-tooltip, .bar-received:hover .bar-tooltip {
  visibility: visible;
}

.chart-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-weight: 500;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 6px;
}

/* Month Payment Grid */
.month-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.month-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.02);
  transition: all 0.2s ease;
  cursor: pointer;
}

.month-card:hover {
  transform: scale(1.03);
}

.month-card.month-paid {
  border-color: rgba(16, 185, 129, 0.3);
  background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.08), transparent 70%);
}

.month-card.month-open {
  border-color: rgba(239, 68, 68, 0.3);
  background: radial-gradient(circle at top right, rgba(239, 68, 68, 0.08), transparent 70%);
}

.month-name {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.month-status {
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
}

.month-paid .month-status {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.month-open .month-status {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.month-date {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

/* Mobile-first safeguards layered over the desktop design. */
html,
body {
  max-width: 100%;
}

img,
svg,
canvas,
video,
iframe {
  max-width: 100%;
}

.main-content,
.glass-card,
.premium-table-container,
.content-header,
.header-actions,
form {
  min-width: 0;
}

.premium-table-container {
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.premium-table {
  min-width: 760px;
}

@media (max-width: 768px) {
  body {
    display: block;
    overflow-x: hidden;
  }

  .app-container {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
    z-index: 200;
  }

  .brand-section {
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    justify-content: flex-start;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
    font-size: 1rem;
    flex: 0 0 auto;
  }

  .brand-name {
    display: block;
    font-size: 1.05rem;
  }

  .nav-menu {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
  }

  .nav-menu::-webkit-scrollbar {
    display: none;
  }

  .nav-menu li {
    flex: 0 0 auto;
  }

  .nav-link {
    gap: 0.5rem;
    padding: 0.7rem 0.85rem;
    white-space: nowrap;
    border: 1px solid var(--border-color);
  }

  .nav-link svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 1rem;
  }

  .content-header {
    align-items: stretch;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .content-header,
  .header-actions {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    align-items: stretch;
  }

  .header-actions .btn-premium,
  .header-actions button,
  .header-actions a {
    width: 100%;
  }

  .theme-toggle {
    width: 42px !important;
    min-width: 42px;
    align-self: flex-end;
  }

  .page-title {
    font-size: clamp(1.45rem, 7vw, 1.9rem);
    line-height: 1.1;
    overflow-wrap: anywhere;
  }

  .glass-card {
    width: 100% !important;
    max-width: 100% !important;
    padding: 1rem !important;
    border-radius: 16px;
    margin-bottom: 1rem;
  }

  .glass-card [style*="display: grid"] {
    grid-template-columns: 1fr !important;
    gap: 0.9rem !important;
  }

  .glass-card [style*="display: flex"] {
    flex-wrap: wrap;
  }

  .glass-card > [style*="display: flex"],
  .glass-card form[style*="display: flex"],
  .glass-card div[style*="justify-content: space-between"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .glass-card [style*="width: 120px"],
  .glass-card [style*="width: 100px"],
  .glass-card [style*="width: 80px"] {
    width: 100% !important;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .stat-value {
    font-size: 1.8rem;
  }

  .premium-table-container {
    border-radius: 14px;
  }

  .premium-table {
    font-size: 0.86rem;
  }

  .premium-table th,
  .premium-table td {
    padding: 0.8rem 0.9rem;
  }

  .btn-premium {
    width: 100%;
    min-height: 44px;
  }

  .btn-icon-only {
    width: 44px;
    min-width: 44px;
  }

  .form-control-premium {
    min-height: 44px;
    font-size: 1rem;
  }

  .switch-container {
    align-items: flex-start;
  }

  .chart-container {
    height: auto;
    overflow-x: auto;
    padding-bottom: 0.5rem;
  }

  .chart-bars {
    min-width: 620px;
    height: 230px;
  }

  .chart-legend {
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
  }

  .month-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .main-content {
    padding: 0.75rem;
  }

  .sidebar {
    padding: 0.65rem;
  }

  .nav-link {
    font-size: 0.85rem;
    padding: 0.65rem 0.75rem;
  }

  .glass-card {
    padding: 0.85rem !important;
  }

  .premium-table {
    min-width: 680px;
  }

  .month-grid {
    grid-template-columns: 1fr;
  }
}
