:root {
  --app-primary: #3b82f6;
  --app-primary-dark: #1d4ed8;
  --app-primary-light: #93c5fd;
  --app-success: #10b981;
  --app-danger: #ef4444;
  --app-warning: #f59e0b;
  --app-info: #06b6d4;
  --app-bg: #f8fafc;
  --app-card-bg: #ffffff;
  --app-text: #1e293b;
  --app-text-muted: #64748b;
  --app-border: #e2e8f0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--app-bg);
  color: var(--app-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 0 auto;
}

/* App Layout & Sidebar */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.app-sidebar {
  width: 260px;
  min-width: 260px;
  background-color: #0f172a !important; /* Slate 900 */
  border-right: 1px solid #1e293b;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1030;
  display: flex;
  flex-direction: column;
}

/* Custom scrollbar for sidebar */
.app-sidebar::-webkit-scrollbar {
  width: 5px;
}
.app-sidebar::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

.app-main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--app-bg);
}

.sidebar-nav .nav-link {
  color: #94a3b8;
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  margin-bottom: 3px;
  transition: all 0.15s ease-in-out;
}

.sidebar-nav .nav-link i {
  font-size: 1.15rem;
  margin-right: 0.75rem;
}

.sidebar-nav .nav-link:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.08);
}

.sidebar-nav .nav-link.active {
  color: #ffffff;
  background-color: var(--app-primary);
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

/* Firm switcher inside sidebar */
.sidebar-firm-card {
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

/* Mobile Sidebar Behavior */
@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    min-width: 280px;
    z-index: 1060;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }

  .app-sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
  }

  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(2px);
    z-index: 1050;
    display: none;
  }

  .sidebar-backdrop.show {
    display: block;
  }
}

/* Brand Badge */
.brand-badge {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  font-size: 1.15rem;
}

.text-primary-light {
  color: var(--app-primary-light);
}

/* Elevated Cards */
.card {
  border: 1px solid var(--app-border);
  border-radius: 12px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  background-color: var(--app-card-bg);
}

.card-header {
  background-color: transparent;
  border-bottom: 1px solid var(--app-border);
  padding: 1rem 1.25rem;
  font-weight: 600;
}

.card-hover:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  transform: translateY(-2px);
}

/* KPI Summary Cards */
.kpi-card-link {
  text-decoration: none;
  color: inherit;
  display: block;
  height: 100%;
}

.kpi-card {
  border-left: 4px solid var(--app-primary);
  border-radius: 12px;
  background: #ffffff;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: pointer;
}

.kpi-card-link:hover .kpi-card {
  transform: translateY(-3px);
  box-shadow: 0 10px 20px -3px rgba(0, 0, 0, 0.09), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
}

.kpi-card.kpi-sales { border-left-color: #10b981; }
.kpi-card.kpi-purchase { border-left-color: #6366f1; }
.kpi-card.kpi-receivable { border-left-color: #f59e0b; }
.kpi-card.kpi-payable { border-left-color: #ef4444; }

.kpi-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

/* Status Badges */
.badge-status {
  padding: 0.35em 0.75em;
  font-weight: 600;
  font-size: 0.75rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-status-paid {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-status-partial {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-status-unpaid {
  background-color: #fee2e2;
  color: #991b1b;
}

/* Tables */
.table {
  vertical-align: middle;
}

.table th {
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--app-text-muted);
  background-color: #f8fafc;
  border-top: none;
  padding: 0.85rem 1rem;
}

.table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--app-border);
}

/* Form Controls */
.form-control, .form-select {
  border-radius: 8px;
  border-color: #cbd5e1;
  padding: 0.55rem 0.85rem;
  font-size: 0.95rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-label {
  font-weight: 500;
  font-size: 0.875rem;
  color: #334155;
  margin-bottom: 0.35rem;
}

/* Invoice Dynamic Line Items Table (Compact & Space-Optimized) */
.invoice-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--app-border);
  border-radius: 10px;
  background-color: #ffffff;
}

.invoice-items-table {
  width: 100%;
  margin-bottom: 0;
}

.invoice-items-table th {
  white-space: nowrap;
  font-size: 0.76rem;
  padding: 0.4rem 0.35rem;
  background-color: #f8fafc;
  color: #475569;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.invoice-items-table td {
  padding: 0.25rem 0.3rem;
  vertical-align: middle;
}

.invoice-items-table input.form-control-sm,
.invoice-items-table select.form-select-sm {
  padding: 0.25rem 0.35rem;
  font-size: 0.82rem;
  height: 31px;
  border-radius: 6px;
  border-color: #cbd5e1;
}

/* Fix Unit & Tax Rate Select Dropdown Text Visibility */
.invoice-items-table select.row-unit {
  padding-left: 0.35rem;
  padding-right: 1.15rem;
  background-position: right 0.25rem center;
  background-size: 10px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  min-width: 72px;
}

.invoice-items-table select.row-tax-rate {
  padding-left: 0.35rem;
  padding-right: 1.15rem;
  background-position: right 0.25rem center;
  background-size: 10px 8px;
  font-size: 0.78rem;
  min-width: 78px;
}

/* Fix Qty Number Input Visibility & Spinner Arrows */
.invoice-items-table input.row-qty::-webkit-outer-spin-button,
.invoice-items-table input.row-qty::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.invoice-items-table input.row-qty {
  -moz-appearance: textfield;
  font-weight: 600;
  text-align: right;
  padding-left: 0.35rem;
  padding-right: 0.45rem;
}

/* Fix Line Item Discount Input (Disc %) */
.invoice-items-table input.row-discount-pct::-webkit-outer-spin-button,
.invoice-items-table input.row-discount-pct::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.invoice-items-table input.row-discount-pct {
  -moz-appearance: textfield;
  font-weight: 500;
  text-align: right;
  padding-left: 0.25rem;
  padding-right: 0.35rem;
}

.invoice-items-table .btn-remove-row {
  line-height: 1;
  padding: 0.25rem 0.35rem;
  font-size: 0.9rem;
}

/* Fix Overall Discount Type Select & Input Vertical Height */
#discountTypeSelect {
  padding-left: 0.45rem !important;
  padding-right: 1.35rem !important;
  padding-top: 0.38rem !important;
  padding-bottom: 0.38rem !important;
  background-position: right 0.35rem center !important;
  background-size: 10px 8px !important;
  font-size: 0.82rem !important;
  height: 38px !important;
  min-width: 130px !important;
  border-radius: 7px !important;
}

#discountValueInput {
  height: 38px !important;
  padding-top: 0.38rem !important;
  padding-bottom: 0.38rem !important;
  font-size: 0.88rem !important;
  border-radius: 7px !important;
}

/* Settings Interactive Radio Cards */
.setting-radio-card {
  cursor: pointer;
  border: 1.5px solid var(--app-border, #cbd5e1);
  background-color: #ffffff;
  transition: all 0.15s ease-in-out;
  border-radius: 10px;
}

.setting-radio-card:hover {
  border-color: #94a3b8;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

.setting-radio-card.active,
.setting-radio-card:has(input[type="radio"]:checked) {
  border-color: var(--app-primary, #2563eb) !important;
  background-color: #eff6ff !important;
  box-shadow: 0 0 0 1px var(--app-primary, #2563eb);
}

.setting-radio-card .form-check-input {
  cursor: pointer;
}

.setting-radio-card .form-check-label {
  cursor: pointer;
}

/* Auth Cards */
.auth-card {
  max-width: 460px;
  margin: 2.5rem auto;
  border-radius: 16px;
}

/* Google Sign-in Button */
.btn-google {
  background-color: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  transition: background-color 0.2s;
}

.btn-google:hover {
  background-color: #f3f4f6;
  color: #111827;
  border-color: #9ca3af;
}

/* -------------------------------------------------------------
   SETTINGS INTERACTIVE CARDS & TOGGLE BOXES (No Hover Jitter)
------------------------------------------------------------- */
.setting-toggle-box,
.setting-radio-card {
  cursor: pointer;
  user-select: none;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  background-color: #ffffff;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  transform: none !important;
  box-shadow: none !important;
}

/* Grounded Button Feel - Explicitly disable any hover movement or elevation */
.setting-toggle-box:hover,
.setting-radio-card:hover {
  transform: none !important;
  box-shadow: none !important;
}

/* Active / Checked States */
.setting-toggle-box.active,
.setting-toggle-box:has(input[type="checkbox"]:checked) {
  border-color: #059669 !important;
  background-color: #ecfdf5 !important;
}

#salesDiscountToggleBox.active,
#salesDiscountToggleBox:has(input[type="checkbox"]:checked) {
  border-color: #2563eb !important;
  background-color: #eff6ff !important;
}

.setting-radio-card.active,
.setting-radio-card:has(input[type="radio"]:checked) {
  border-color: #2563eb !important;
  background-color: #eff6ff !important;
}

/* -------------------------------------------------------------
   PRINT A4 STYLES (Clean Standard Tax Invoice Template)
------------------------------------------------------------- */
@page {
  size: A4 portrait;
  margin: 10mm 12mm;
}

@media print {
  nav, footer, .app-sidebar, .btn-print-toolbar, .btn, .no-print, .alert {
    display: none !important;
  }

  body {
    background-color: #ffffff !important;
    color: #000000 !important;
    font-size: 12px !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .invoice-print-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid #000000 !important;
  }

  .invoice-print-container table {
    width: 100% !important;
    border-collapse: collapse !important;
  }

  .invoice-print-container th,
  .invoice-print-container td {
    border: 1px solid #333333 !important;
    padding: 4px 6px !important;
    font-size: 11px !important;
  }

  .invoice-print-container th {
    background-color: #f0f0f0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color: #000 !important;
  }

  .print-border-bottom {
    border-bottom: 1px solid #000 !important;
  }

  .print-border-top {
    border-top: 1px solid #000 !important;
  }

  .print-bg-light {
    background-color: #f9f9f9 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
