:root {
  --brand: #1e5f74;
  --brand-dark: #123540;
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

body {
  background: #f4f6f8;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  background: var(--brand-dark);
  position: sticky;
  top: 0;
  z-index: 1040;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--brand-dark);
  color: #fff;
  position: fixed;
  top: var(--topbar-height);
  bottom: 0;
  left: calc(-1 * var(--sidebar-width));
  transition: left 0.2s ease;
  z-index: 1050;
  overflow-y: auto;
}

.sidebar.show {
  left: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1045;
}

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

.sidebar-inner {
  padding: 1rem 0.75rem;
}

.sidebar-brand {
  align-items: center;
  color: #fff;
  font-weight: 600;
  padding: 0.5rem 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 0.5rem;
}

.sidebar-nav .nav-link {
  color: rgba(255,255,255,0.85);
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 2px;
  font-size: 0.95rem;
}

.sidebar-nav .nav-link i {
  width: 20px;
  display: inline-block;
  margin-right: 6px;
}

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

.sidebar-nav .nav-link.active {
  background: var(--brand);
  color: #fff;
}

.nav-section {
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  padding: 0.9rem 0.75rem 0.25rem;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.nav-group-toggle .bi-chevron-down {
  transition: transform 0.2s ease;
  font-size: 0.75rem;
}

.nav-group-toggle[aria-expanded="true"] .bi-chevron-down {
  transform: rotate(180deg);
}

.sub-link {
  padding-left: 2.1rem !important;
  font-size: 0.88rem;
}

.sub-link.small-link {
  opacity: 0.75;
  font-size: 0.82rem;
}

.sidebar-user {
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 0.75rem;
  padding: 0.75rem;
  color: rgba(255,255,255,0.85);
}

.main-content {
  flex: 1;
  min-width: 0;
}

@media (min-width: 992px) {
  .sidebar {
    left: 0;
    position: sticky;
    top: var(--topbar-height);
    height: calc(100vh - var(--topbar-height));
  }
  .main-content {
    margin-left: 0;
  }
}

.card {
  border: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.table-responsive {
  border-radius: 8px;
}

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

.status-badge {
  font-size: 0.75rem;
  padding: 0.35em 0.65em;
}

.invoice-letterhead {
  border: 1px solid #2e7d32;
  border-radius: 4px;
  padding: 0.75rem 1rem;
  text-align: center;
}

.invoice-letterhead-name {
  color: #e65100;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
  border-bottom: 1px solid #2e7d32;
  padding-bottom: 0.4rem;
  margin-bottom: 0.4rem;
}

.invoice-letterhead-address {
  font-size: 0.85rem;
}

.invoice-letterhead-contact {
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.invoice-letterhead-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: 0.5rem;
  letter-spacing: 0.03em;
}

.invoice-info-block {
  font-size: 0.85rem;
}

.invoice-meta-table {
  height: 100%;
}

.invoice-meta-table td {
  padding: 0.35rem 0.5rem;
}

.invoice-meta-table td:first-child {
  width: 45%;
  background: #f8f9fa;
}

.invoice-totals-table td {
  padding: 0.3rem 0.6rem;
}

@media print {
  .no-print { display: none !important; }
  .sidebar, .topbar, .sidebar-backdrop { display: none !important; }
  .main-content { margin: 0 !important; }

  @page { size: A4; margin: 0; }

  html, body { height: auto !important; }
  body { margin: 8mm !important; }

  .invoice-sheet {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    font-size: 0.78rem;
  }
  .invoice-sheet .table { font-size: 0.78rem; }
  .invoice-sheet .table-sm td, .invoice-sheet .table-sm th { padding: 0.25rem 0.4rem; }
  .invoice-sheet .invoice-letterhead-name { font-size: 1.2rem; }
  .invoice-sheet h6 { font-size: 0.82rem; margin-bottom: 0.3rem; }
  .invoice-sheet .mt-4 { margin-top: 0.6rem !important; }
  .invoice-sheet .mt-3 { margin-top: 0.45rem !important; }
  .invoice-sheet .mb-5 { margin-bottom: 1.5rem !important; }
  .container-fluid { padding: 0 !important; }

  /* Force the same side-by-side layout as the on-screen preview: Bootstrap's
     col-md-* breakpoints are min-width based and can collapse to a narrow
     single-column stack when the print page width falls under 768px. */
  .invoice-sheet .row { display: flex !important; flex-wrap: nowrap !important; }
  .invoice-sheet .row > [class*="col-"] { flex: 0 0 auto !important; }
  .invoice-sheet .row > .col-md-6 { width: 50% !important; max-width: 50% !important; }
  .invoice-sheet .row > .col-md-5 { width: 41.6667% !important; max-width: 41.6667% !important; }
  .invoice-sheet .row > .col-md-7 { width: 58.3333% !important; max-width: 58.3333% !important; }
  .invoice-sheet .row.g-0 { margin: 0 !important; }
  .invoice-sheet .text-md-end { text-align: right !important; }
  .invoice-sheet .mt-md-0 { margin-top: 0 !important; }
}

@media (max-width: 575.98px) {
  .table-mobile-stack thead { display: none; }
  .table-mobile-stack, .table-mobile-stack tbody, .table-mobile-stack tr, .table-mobile-stack td {
    display: block;
    width: 100%;
  }
  .table-mobile-stack tr {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
  }
  .table-mobile-stack td {
    border: none;
    padding: 0.35rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
  }
  .table-mobile-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
  }
}
