/* ================================================
   Finance Platform – Global Stylesheet
   Design: Light, clean, professional
   ================================================ */

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

/* ── CSS Variables ── */
:root {
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #EFF6FF;
  --accent: #0EA5E9;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #6366F1;

  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --border-dark: #CBD5E1;

  --text-1: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;

  --sidebar-w: 240px;
  --sidebar-bg: #0F172A;
  --sidebar-text: #CBD5E1;
  --sidebar-hover: rgba(255, 255, 255, 0.07);
  --sidebar-active: #2563EB;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow: 0 4px 16px rgba(0, 0, 0, .1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, .12);

  --transition: .18s ease;
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

.d-none {
  display: none !important;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: var(--transition);
  overflow: hidden;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-brand .brand-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
}

.sidebar-brand .brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
}

.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: .95rem;
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: .72rem;
  color: var(--text-3);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-section {
  padding: .4rem 1rem .2rem;
  font-size: .68rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 450;
  border-left: 3px solid transparent;
  transition: var(--transition);
  cursor: pointer;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-hover);
  border-left-color: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.nav-item .nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  opacity: .8;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding: 1rem 1.25rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: .82rem;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.logout-btn {
  color: var(--text-3);
  text-decoration: none;
  font-size: .85rem;
  transition: var(--transition);
  padding: .25rem;
}

.logout-btn:hover {
  color: var(--danger);
}

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .85rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-1);
}

.page-subtitle {
  font-size: .8rem;
  color: var(--text-2);
  margin-top: .1rem;
}

.topbar-actions {
  display: flex;
  gap: .75rem;
  align-items: center;
}

.content {
  padding: 1.75rem 2rem;
  flex: 1;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-1);
}

.card-body {
  padding: 1.25rem;
}

.card-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .82rem;
  color: var(--text-2);
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .3rem;
  transition: var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.kpi-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-1);
}

.kpi-sub {
  font-size: .78rem;
  color: var(--text-2);
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .75rem;
  font-weight: 600;
  border-radius: 99px;
  padding: .15rem .55rem;
}

.kpi-up {
  background: #D1FAE5;
  color: #065F46;
}

.kpi-down {
  background: #FEE2E2;
  color: #991B1B;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  line-height: 1.4;
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-1);
  border-color: var(--border-dark);
}

.btn-secondary:hover {
  background: var(--border);
}

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

.btn-danger:hover {
  background: #DC2626;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary-light);
}

.btn-sm {
  padding: .3rem .75rem;
  font-size: .78rem;
}

.btn-lg {
  padding: .7rem 1.6rem;
  font-size: .95rem;
}

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

/* ── Tables ── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

thead tr {
  background: var(--surface-2);
}

thead th {
  padding: .7rem 1rem;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-2);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-2);
}

tbody td {
  padding: .65rem 1rem;
  font-size: .85rem;
  color: var(--text-1);
  vertical-align: middle;
}

.td-muted {
  color: var(--text-2);
}

.td-mono {
  font-family: 'Courier New', monospace;
  font-size: .8rem;
}

.td-right {
  text-align: right;
}

.td-nowrap {
  white-space: nowrap;
}

/* DRE Table specific */
.dre-group-row td {
  font-weight: 700;
  background: #F0F4FF;
  color: var(--primary-dark);
  font-size: .88rem;
}

.dre-sub-row td {
  font-weight: 600;
  background: var(--surface-2);
  padding-left: 1.5rem !important;
  font-size: .85rem;
}

.dre-account-row td:first-child {
  padding-left: 2.25rem;
}

.dre-account-row td {
  font-size: .83rem;
}

.var-pos {
  color: var(--success);
  font-weight: 600;
}

.var-neg {
  color: var(--danger);
  font-weight: 600;
}

.val-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: .83rem;
}

.drill-btn {
  cursor: pointer;
  color: var(--primary);
  text-decoration: underline dotted;
  border: none;
  background: none;
  font-size: .83rem;
  padding: 0;
}

/* ── Forms ── */
.form-group {
  margin-bottom: 1.1rem;
}

.form-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: .35rem;
}

.form-control {
  width: 100%;
  padding: .55rem .85rem;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-size: .88rem;
  font-family: inherit;
  color: var(--text-1);
  background: var(--surface);
  transition: var(--transition);
  outline: none;
  -webkit-appearance: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%2394A3B8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 10px;
  padding-right: 2.2rem;
}

.form-hint {
  font-size: .75rem;
  color: var(--text-3);
  margin-top: .3rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

/* File upload zone */
.upload-zone {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-lg);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--surface-2);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone .upload-icon {
  font-size: 2.5rem;
  margin-bottom: .75rem;
  color: var(--text-3);
}

.upload-zone .upload-text {
  font-size: .9rem;
  color: var(--text-2);
}

.upload-zone .upload-sub {
  font-size: .78rem;
  color: var(--text-3);
  margin-top: .3rem;
}

.upload-zone input[type="file"] {
  display: none;
}

.file-selected {
  margin-top: .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: center;
  font-size: .85rem;
  color: var(--primary);
  font-weight: 600;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .6rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
}

.badge-success {
  background: #D1FAE5;
  color: #065F46;
}

.badge-danger {
  background: #FEE2E2;
  color: #991B1B;
}

.badge-warning {
  background: #FEF3C7;
  color: #92400E;
}

.badge-info {
  background: #E0E7FF;
  color: #3730A3;
}

.badge-neutral {
  background: var(--surface-2);
  color: var(--text-2);
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ── Alerts ── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .85rem 1rem;
  border-radius: var(--radius);
  font-size: .85rem;
  border: 1px solid;
  margin-bottom: 1rem;
}

.alert-success {
  background: #F0FDF4;
  border-color: #86EFAC;
  color: #166534;
}

.alert-danger {
  background: #FEF2F2;
  border-color: #FCA5A5;
  color: #991B1B;
}

.alert-warning {
  background: #FFFBEB;
  border-color: #FCD34D;
  color: #92400E;
}

.alert-info {
  background: #EFF6FF;
  border-color: #93C5FD;
  color: #1E40AF;
}

/* ── Filters Bar ── */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: .85rem 1.1rem;
  margin-bottom: 1.5rem;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.filter-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.filter-control {
  padding: .4rem .75rem;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  font-size: .84rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-1);
  outline: none;
  cursor: pointer;
}

.filter-control:focus {
  border-color: var(--primary);
}

.toggle-pill {
  display: flex;
  border: 1px solid var(--border-dark);
  border-radius: 99px;
  overflow: hidden;
}

.toggle-pill label {
  padding: .3rem .85rem;
  font-size: .8rem;
  cursor: pointer;
  color: var(--text-2);
  font-weight: 500;
  transition: var(--transition);
}

.toggle-pill input[type=radio]:checked+label {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.toggle-pill input[type=radio] {
  display: none;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  animation: fadeIn .18s ease;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 95%;
  padding: 2rem;
  animation: slideUp .2s ease;
}

.modal-icon {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: .75rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: .5rem;
  text-align: center;
}

.modal-text {
  font-size: .87rem;
  color: var(--text-2);
  text-align: center;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
}

@keyframes fadeIn {
  from {
    opacity: 0
  }

  to {
    opacity: 1
  }
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0
  }

  to {
    transform: translateY(0);
    opacity: 1
  }
}

/* ── Login Page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #0F172A 0%, #1E3A5F 60%, #0F172A 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .logo-icon {
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto .75rem;
  box-shadow: 0 4px 16px rgba(37, 99, 235, .4);
}

.login-logo h1 {
  font-size: 1.3rem;
  font-weight: 800;
}

.login-logo p {
  font-size: .82rem;
  color: var(--text-2);
}

.login-card .btn {
  width: 100%;
  justify-content: center;
  padding: .7rem;
}

/* ── Chart containers ── */
.chart-container {
  position: relative;
  height: 240px;
}

.chart-lg {
  height: 300px;
}

/* ── Preview table ── */
.preview-scroll {
  max-height: 320px;
  overflow-y: auto;
}

/* ── Processing log ── */
.process-log {
  background: #0F172A;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  max-height: 220px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: .8rem;
  color: #94A3B8;
}

.process-log .log-ok {
  color: #4ADE80;
}

.process-log .log-error {
  color: #F87171;
}

.process-log .log-info {
  color: #60A5FA;
}

/* ── Utilities ── */
.mt-1 {
  margin-top: .5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.mt-3 {
  margin-top: 1.5rem;
}

.mb-1 {
  margin-bottom: .5rem;
}

.mb-2 {
  margin-bottom: 1rem;
}

.mb-3 {
  margin-bottom: 1.5rem;
}

.gap-1 {
  gap: .5rem;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.wrap {
  flex-wrap: wrap;
}

.w-full {
  width: 100%;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.text-sm {
  font-size: .82rem;
}

.text-muted {
  color: var(--text-2);
}

.text-xs {
  font-size: .75rem;
  color: var(--text-3);
}

.font-bold {
  font-weight: 700;
}

.font-mono {
  font-family: monospace;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 1.25rem 0;
}

.section-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  margin-bottom: .75rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    width: 0;
    overflow: hidden;
  }

  .sidebar.open {
    width: var(--sidebar-w);
  }

  .main-content {
    margin-left: 0;
  }

  .content {
    padding: 1rem;
  }

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

  .form-row {
    flex-direction: column;
  }

  .filters-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ── Loading Overlay ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  z-index: 9999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  backdrop-filter: blur(3px);
  animation: fadeIn .2s ease;
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid rgba(255, 255, 255, .2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

.loading-text {
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.loading-sub {
  color: rgba(255, 255, 255, .6);
  font-size: .82rem;
  margin-top: -.5rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}