:root {
  --bg-dark: #0f172a;
  --bg-glass: rgba(30, 41, 59, 0.7);
  --border-glass: rgba(255, 255, 255, 0.1);
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --secondary: #8b5cf6;
  --secondary-hover: #7c3aed;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --glow-orange: rgba(249, 115, 22, 0.2);
  --glow-green: rgba(34, 197, 94, 0.2);
  --glow-red: rgba(239, 68, 68, 0.2);
  --gradient-bg: linear-gradient(135deg, #0f172a 0%, #171131 100%);
  --input-bg: rgba(15, 23, 42, 0.6);
  --input-color: white;
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: var(--gradient-bg);
  color: var(--text-main);
  min-height: 100vh;
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
}

.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 8px 32px 0 rgba(0, 0, 0, 0.22);
}

.glass-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.4rem;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-glass);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.glass-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  background: linear-gradient(to right, #60a5fa, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.1;
}

.fee-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.fee-brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, #14b8a6, #3b82f6);
  box-shadow: 0 12px 26px rgba(20, 184, 166, 0.22);
  flex: 0 0 auto;
}

.fee-brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fee-brand span {
  display: block;
  max-width: min(56vw, 620px);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-chip {
  text-decoration: none;
  white-space: nowrap;
  border-radius: 999px;
  padding: 0.65rem 1rem;
}

.user-profile .avatar {
  background: var(--border-glass);
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.dashboard-content {
  padding: 1rem 1.4rem 2rem;
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.controls {
  padding: 0;
  overflow: hidden;
}

.filter-panel-toggle {
  width: 100%;
  padding: 1rem 1.15rem;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--text-main);
  text-align: left;
  background:
    linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(20, 184, 166, 0.12)),
    rgba(15, 23, 42, 0.34);
  border-bottom: 1px solid var(--border-glass);
}

.filter-panel-toggle strong {
  display: block;
  font-size: 1rem;
}

.filter-panel-toggle small {
  display: block;
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.filter-panel-toggle > i {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #bfdbfe;
  font-size: 1rem;
  transition: transform 0.2s ease;
}

.controls.is-collapsed .filter-panel-toggle > i {
  transform: rotate(180deg);
}

.filter-panel-body {
  padding: 0.95rem;
}

.controls.is-collapsed .filter-panel-toggle {
  border-radius: 12px;
}

.controls.is-collapsed .filter-panel-body {
  display: none;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.052), rgba(255, 255, 255, 0.018)),
    rgba(15, 23, 42, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.filter-grid > .input-group:nth-child(3n + 1) {
  border-color: rgba(59, 130, 246, 0.2);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.11), rgba(255, 255, 255, 0.02));
}

.filter-grid > .input-group:nth-child(3n + 2) {
  border-color: rgba(20, 184, 166, 0.19);
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.1), rgba(255, 255, 255, 0.02));
}

.filter-grid > .input-group:nth-child(3n) {
  border-color: rgba(245, 158, 11, 0.18);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.08), rgba(255, 255, 255, 0.02));
}

.input-group label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.receipt-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
}

.btn-mini-search {
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.18);
}

.btn-mini-search:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-main) !important;
  cursor: pointer;
}

.inline-check input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--primary);
}

.date-filter-toggle small {
  color: var(--text-muted);
  line-height: 1.45;
}

.date-range-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(240px, 1.2fr) repeat(2, minmax(190px, 1fr));
  align-items: end;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid rgba(96, 165, 250, 0.28);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(59, 130, 246, 0.13), rgba(20, 184, 166, 0.08)),
    rgba(15, 23, 42, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: opacity 0.2s ease, filter 0.2s ease, border-color 0.2s ease;
}

.date-range-row.is-disabled {
  opacity: 0.55;
  filter: saturate(0.65);
  border-color: rgba(148, 163, 184, 0.18);
}

.date-range-row.is-disabled input {
  cursor: not-allowed;
}

.date-range-row input[type="date"] {
  min-height: 46px;
}

.optional-date-row {
  border-color: rgba(20, 184, 166, 0.24);
  background:
    linear-gradient(135deg, rgba(20, 184, 166, 0.12), rgba(59, 130, 246, 0.08)),
    rgba(15, 23, 42, 0.18);
}

select, input:not([type="radio"]) {
  background: var(--input-bg);
  border: 1px solid var(--border-glass);
  color: var(--input-color);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}

select {
  appearance: none;
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 256 256' fill='%2394a3b8'%3E%3Cpath d='M213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80A8 8 0 0 1 48 88h160a8 8 0 0 1 5.66 13.66z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 1rem;
}

input[type="checkbox"] {
  padding: 0;
  border-radius: 4px;
}

select:focus, input:not([type="radio"]):focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
  background: rgba(30, 41, 59, 0.9);
}

.divider {
    border: none;
    border-top: 1px solid var(--border-glass);
    margin: 1.5rem 0;
}

.scope-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.control-box {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 240px;
    padding: 1rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(15, 23, 42, 0.2));
}

.control-box h3 {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.control-box label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text-main);
    transition: color 0.2s;
}

.control-box label:hover {
    color: var(--primary);
}

input[type="radio"] {
    accent-color: var(--primary);
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}

.actions {
  display: flex;
  gap: 1.5rem;
}

.report-generate-actions {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  z-index: 10000;
  width: auto;
  padding: 0.65rem;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: 0 18px 48px rgba(2, 6, 23, 0.34);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  pointer-events: auto;
}

.report-generate-actions .btn-primary {
  min-width: 190px;
  min-height: 48px;
  border-radius: 14px;
}

button {
  padding: 0.85rem 1.75rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.39);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px 0 rgba(59, 130, 246, 0.5);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-msg {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border-left: 4px solid #ef4444;
    border-radius: 4px;
    color: #fca5a5;
    font-size: 0.95rem;
}

.error-msg::before {
    content: "⚠";
    display: inline-block;
    margin-right: 0.5rem;
    color: #f87171;
    font-weight: 700;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.stat-card {
  padding: 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
}

.stat-card h3 {
  font-size: 1.1rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.stat-icon {
  display: inline-flex;
  margin-bottom: 0.85rem;
  font-size: 2rem;
  line-height: 1;
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  transition: opacity 0.25s ease;
}

.orange-glow { box-shadow: 0 0 40px var(--glow-orange) inset; }
.green-glow { box-shadow: 0 0 40px var(--glow-green) inset; }
.red-glow { box-shadow: 0 0 40px var(--glow-red) inset; }

.orange-glow .stat-icon,
.orange-glow .stat-value { color: #fb923c; }

.green-glow .stat-icon,
.green-glow .stat-value { color: #4ade80; }

.red-glow .stat-icon,
.red-glow .stat-value { color: #f87171; }

.grid-section {
  padding: 1.5rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.grid-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.btn-outline {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-main);
  padding: 0.6rem 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  white-space: nowrap;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.btn-outline i {
  font-size: 1rem;
  line-height: 1;
}

.btn-outline:hover {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
}

.btn-remind {
  border-color: rgba(34, 197, 94, 0.24);
}

.btn-remind:hover {
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.14);
}

.action-divider {
  width: 1px;
  align-self: stretch;
  min-height: 34px;
  background: rgba(255, 255, 255, 0.15);
}

.fee-report-grid {
  width: 100%;
  height: min(68vh, 760px);
  min-height: 500px;
}

/* Custom AG-Grid modifications */
.ag-theme-alpine-dark {
  --ag-background-color: transparent !important;
  --ag-header-background-color: rgba(15, 23, 42, 0.5) !important;
  --ag-border-color: rgba(255, 255, 255, 0.08) !important;
  --ag-row-border-color: rgba(255, 255, 255, 0.04) !important;
  --ag-data-color: #0f172a !important;
  --ag-font-family: inherit !important;
  --ag-header-foreground-color: #94a3b8 !important;
  border-radius: 8px;
  overflow: hidden;
}

.ag-theme-alpine-dark .ag-root-wrapper {
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ag-theme-alpine-dark .ag-row {
  background: #ffffff !important;
  color: #0f172a !important;
}

.ag-theme-alpine-dark .ag-row:nth-child(even) {
  background: #f8fafc !important;
}

.ag-theme-alpine-dark .ag-cell,
.ag-theme-alpine-dark .ag-cell-value {
  color: #0f172a !important;
  font-weight: 600;
}

.ag-theme-alpine-dark .ag-row-hover {
  background-color: rgba(59, 130, 246, 0.12) !important;
}

.ag-theme-alpine-dark .ag-row-hover .ag-cell,
.ag-theme-alpine-dark .ag-row-hover .ag-cell-value,
.ag-theme-alpine-dark .ag-row-selected .ag-cell,
.ag-theme-alpine-dark .ag-row-selected .ag-cell-value {
  color: #0f172a !important;
}

.ag-theme-alpine-dark .ag-cell[col-id="paidAmount"],
.ag-theme-alpine-dark .ag-cell[col-id="grandTotalPaid"] {
  color: #22c55e !important;
  font-weight: 700 !important;
}

.ag-theme-alpine-dark .ag-cell[col-id="remaining"],
.ag-theme-alpine-dark .ag-cell[col-id="grandRemaining"] {
  color: #ef4444 !important;
  font-weight: 700 !important;
}

.ag-theme-alpine-dark .ag-header-cell {
  font-weight: 600;
  font-size: 0.95rem;
}

.ag-theme-alpine-dark .ag-pinned-bottom-row {
  background: rgba(219, 234, 254, 0.96) !important;
  border-top: 1px solid rgba(37, 99, 235, 0.38) !important;
  font-weight: 800;
}

.ag-theme-alpine-dark .ag-pinned-bottom-row .ag-cell,
.ag-theme-alpine-dark .ag-pinned-bottom-row .ag-cell-value {
  color: #0f172a !important;
  font-weight: 800 !important;
}

.erp-grid-loading,
.erp-grid-empty {
  min-width: 260px;
  display: grid;
  justify-items: center;
  gap: 0.55rem;
  padding: 1.2rem 1.35rem;
  color: #475569;
  text-align: center;
}

.erp-grid-loading .erp-loading-skeleton {
  width: 220px;
  height: 12px;
}

.erp-grid-empty i {
  width: 56px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  font-size: 1.7rem;
}

.erp-grid-empty strong,
.erp-grid-loading strong {
  color: #0f172a;
  font-size: 0.98rem;
}

/* Multiple Themes */
body.theme-light {
  --bg-dark: #f8fafc;
  --bg-glass: rgba(255, 255, 255, 0.85);
  --border-glass: rgba(0, 0, 0, 0.1);
  --primary: #2563eb;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --gradient-bg: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  --input-bg: rgba(255, 255, 255, 0.8);
  --input-color: #1e293b;
}

body.theme-light .ag-theme-alpine-dark {
  --ag-header-background-color: rgba(241, 245, 249, 0.8) !important;
  --ag-header-foreground-color: #334155 !important;
  --ag-data-color: #1e293b !important;
  --ag-border-color: rgba(0, 0, 0, 0.1) !important;
  --ag-row-border-color: rgba(0, 0, 0, 0.05) !important;
  --ag-background-color: rgba(255, 255, 255, 0.4) !important;
  --ag-odd-row-background-color: rgba(241, 245, 249, 0.6) !important;
}
body.theme-light .ag-theme-alpine-dark .ag-row-hover {
  background-color: rgba(0, 0, 0, 0.03) !important;
}

body.theme-ocean {
  --bg-dark: #082f49;
  --bg-glass: rgba(12, 74, 110, 0.75);
  --border-glass: rgba(56, 189, 248, 0.2);
  --primary: #0ea5e9;
  --text-main: #f0f9ff;
  --text-muted: #bae6fd;
  --gradient-bg: linear-gradient(135deg, #0c4a6e 0%, #082f49 100%);
  --input-bg: rgba(8, 47, 73, 0.6);
  --input-color: #f0f9ff;
}

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

.theme-select {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: var(--bg-glass);
}

.theme-fab-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
}

.theme-fab-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(14, 165, 233, 0.9));
  color: white;
  box-shadow: 0 12px 24px rgba(14, 165, 233, 0.28);
}

.theme-fab-btn i {
  font-size: 1.2rem;
  color: #fff;
  line-height: 1;
}

.theme-fab-panel {
  position: absolute;
  right: 0;
  bottom: 60px;
  min-width: 180px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--border-glass);
  box-shadow: 0 18px 36px rgba(2, 6, 23, 0.3);
}

.theme-fab-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.theme-fab-panel.hidden {
  display: none;
}

@media (max-width: 768px) {
  body {
    padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }

  .dashboard-content {
    padding: 1rem;
  }

  .glass-header {
    padding: 0.75rem 1rem;
    align-items: flex-start;
    flex-direction: column;
  }

  .back-chip {
    width: 100%;
    text-align: center;
  }

  .date-range-row {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .btn-outline {
    flex: 1 1 150px;
  }

  .report-generate-actions {
    left: 0.85rem;
    right: 0.85rem;
    bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
    justify-content: center;
    padding: 0.55rem;
    border-radius: 18px;
  }

  .report-generate-actions .btn-primary {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    font-size: 1rem;
  }
}

/* Print Styles */
@media print {
  body {
    background: white;
    color: black;
  }
  .glass-header, .controls, .stats-row, hr, .header-actions {
    display: none !important;
  }
  .grid-section {
    padding: 0;
    box-shadow: none;
    border: none;
    background: transparent;
  }
  #myGrid {
    height: auto !important;
  }
  .ag-theme-alpine-dark {
    --ag-background-color: white !important;
    --ag-header-background-color: #f1f5f9 !important;
    --ag-header-foreground-color: black !important;
    --ag-data-color: black !important;
    --ag-border-color: #ccc !important;
    --ag-row-border-color: #eee !important;
  }
}
