/* ==========================================================================
   BookkeepingWeb design system
   Built on Bootstrap 5.3 (CSS variables + utilities) — this file supplies
   tokens and the handful of components Bootstrap doesn't: sidebar/header
   shell, stat cards, empty states, status badges, and auth pages.
   ========================================================================== */

:root {
  --bw-primary: #4f46e5;
  --bw-primary-dark: #4338ca;
  --bw-primary-light: #eef2ff;
  --bw-sidebar-bg: #111827;
  --bw-sidebar-bg-active: #1f2937;
  --bw-sidebar-text: #cbd5e1;
  --bw-sidebar-text-muted: #7c8698;
  --bw-surface: #f6f7fb;
  --bw-card-bg: #ffffff;
  --bw-border: #e5e7eb;
  --bw-text: #1f2937;
  --bw-text-muted: #6b7280;
  --bw-success: #16a34a;
  --bw-warning: #d97706;
  --bw-danger: #dc2626;
  --bw-info: #7c3aed;

  --bw-radius-sm: 0.375rem;
  --bw-radius: 0.625rem;
  --bw-radius-lg: 0.875rem;
  --bw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --bw-shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --bw-shadow-lg: 0 10px 24px rgba(16, 24, 40, 0.10);

  --bw-sidebar-width: 264px;
  --bw-header-height: 64px;
}

* { box-sizing: border-box; }

.icon { width: 1.1em; height: 1.1em; vertical-align: -0.15em; flex-shrink: 0; }
.icon-lg { width: 1.5rem; height: 1.5rem; }
.icon-xl { width: 1.75rem; height: 1.75rem; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  background: var(--bw-surface);
  color: var(--bw-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

h1, h2, h3, h4, h5, h6 { font-weight: 600; color: var(--bw-text); letter-spacing: -0.01em; }

a { color: var(--bw-primary); }
a:hover { color: var(--bw-primary-dark); }

::selection { background: var(--bw-primary-light); color: var(--bw-primary-dark); }

/* Accessible focus ring, consistent across controls */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--bw-primary);
  outline-offset: 2px;
}
.btn:focus, .form-control:focus, .form-select:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.18);
  border-color: var(--bw-primary);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--bw-primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 var(--bw-radius-sm) 0;
  z-index: 2000;
}
.skip-link:focus { left: 0; }

/* ==========================================================================
   App shell: sidebar + header + content
   ========================================================================== */

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

.app-sidebar {
  width: var(--bw-sidebar-width);
  flex-shrink: 0;
  background: var(--bw-sidebar-bg);
  color: var(--bw-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  transition: transform 0.2s ease;
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0 1.25rem;
  height: var(--bw-header-height);
  flex-shrink: 0;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.app-sidebar__brand:hover { color: #fff; }
.app-sidebar__brand-mark {
  width: 32px; height: 32px;
  border-radius: var(--bw-radius-sm);
  background: linear-gradient(135deg, var(--bw-primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.app-sidebar__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.75rem 0.75rem 1rem;
}

.app-sidebar__section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bw-sidebar-text-muted);
  padding: 1rem 0.75rem 0.375rem;
}

.app-sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--bw-radius-sm);
  color: var(--bw-sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.125rem;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.app-sidebar__link svg { flex-shrink: 0; opacity: 0.85; }
.app-sidebar__link:hover { background: var(--bw-sidebar-bg-active); color: #fff; text-decoration: none; }
.app-sidebar__link[aria-current="page"] {
  background: var(--bw-primary);
  color: #fff;
}
.app-sidebar__link[aria-current="page"] svg { opacity: 1; }
.app-sidebar__link.is-disabled {
  color: var(--bw-sidebar-text-muted);
  cursor: default;
  pointer-events: none;
}

.app-sidebar__backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1030;
}

.app-main {
  flex: 1 1 auto;
  margin-left: var(--bw-sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-header {
  height: var(--bw-header-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  background: var(--bw-card-bg);
  border-bottom: 1px solid var(--bw-border);
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-header__title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header__toggle {
  display: none;
  border: 0;
  background: transparent;
  color: var(--bw-text);
  padding: 0.375rem;
  border-radius: var(--bw-radius-sm);
}
.app-header__toggle:hover { background: var(--bw-surface); }

.app-header__user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.85rem;
  color: var(--bw-text-muted);
  white-space: nowrap;
}
.app-header__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bw-primary-light);
  color: var(--bw-primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.app-content {
  flex: 1 1 auto;
  padding: 1.5rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.app-footer {
  padding: 1rem 1.5rem;
  color: var(--bw-text-muted);
  font-size: 0.8rem;
  text-align: center;
}

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open .app-sidebar__backdrop { display: block; }
  .app-main { margin-left: 0; }
  .app-header__toggle { display: inline-flex; align-items: center; justify-content: center; }
  .app-content { padding: 1rem; }
}

/* ==========================================================================
   Page header
   ========================================================================== */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-header h1 { font-size: 1.4rem; margin: 0 0 0.2rem; }
.page-header__subtitle { color: var(--bw-text-muted); font-size: 0.875rem; margin: 0; }
.page-header__actions { display: flex; gap: 0.5rem; flex-shrink: 0; flex-wrap: wrap; }

/* ==========================================================================
   Cards, panels
   ========================================================================== */

.panel {
  background: var(--bw-card-bg);
  border: 1px solid var(--bw-border);
  border-radius: var(--bw-radius-lg);
  box-shadow: var(--bw-shadow-sm);
}
.panel__header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bw-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.panel__header h2 { font-size: 1rem; margin: 0; }
.panel__body { padding: 1.25rem; }

.stat-card {
  background: var(--bw-card-bg);
  border: 1px solid var(--bw-border);
  border-radius: var(--bw-radius-lg);
  box-shadow: var(--bw-shadow-sm);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-card:hover { box-shadow: var(--bw-shadow); transform: translateY(-1px); color: inherit; }
.stat-card__icon {
  width: 44px; height: 44px;
  border-radius: var(--bw-radius);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  background: var(--bw-primary-light);
  color: var(--bw-primary);
}
.stat-card__value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-card__label { font-size: 0.8rem; color: var(--bw-text-muted); margin-top: 0.15rem; }

.quick-link-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  background: var(--bw-card-bg);
  border: 1px solid var(--bw-border);
  border-radius: var(--bw-radius);
  text-decoration: none;
  color: var(--bw-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.quick-link-card:hover { border-color: var(--bw-primary); box-shadow: var(--bw-shadow-sm); color: var(--bw-text); }
.quick-link-card__icon {
  width: 38px; height: 38px;
  border-radius: var(--bw-radius-sm);
  background: var(--bw-surface);
  color: var(--bw-primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.quick-link-card__title { font-weight: 600; font-size: 0.9rem; }
.quick-link-card__desc { font-size: 0.78rem; color: var(--bw-text-muted); }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-panel { overflow-x: auto; }
.table {
  margin-bottom: 0;
  --bs-table-hover-bg: var(--bw-primary-light);
}
.table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bw-text-muted);
  font-weight: 700;
  border-bottom: 1px solid var(--bw-border);
  padding: 0.7rem 1rem;
  white-space: nowrap;
}
.table tbody td {
  padding: 0.7rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--bw-border);
  font-size: 0.875rem;
}
.table tbody tr:last-child td { border-bottom: 0; }

.row-actions { display: inline-flex; gap: 0.25rem; }
.icon-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--bw-radius-sm);
  color: var(--bw-text-muted);
  background: transparent;
  border: 1px solid transparent;
  text-decoration: none;
}
.icon-action-btn:hover { background: var(--bw-primary-light); color: var(--bw-primary-dark); }
.icon-action-btn.icon-action-btn--danger:hover { background: #fee2e2; color: var(--bw-danger); }

/* ==========================================================================
   Badges (status)
   ========================================================================== */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-badge--success { background: #dcfce7; color: #15803d; }
.status-badge--warning { background: #fef3c7; color: #b45309; }
.status-badge--danger { background: #fee2e2; color: #b91c1c; }
.status-badge--info { background: #ede9fe; color: #6d28d9; }
.status-badge--neutral { background: #f1f5f9; color: #475569; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-label { font-weight: 600; font-size: 0.83rem; color: var(--bw-text); margin-bottom: 0.3rem; }
.form-control, .form-select {
  border-color: var(--bw-border);
  border-radius: var(--bw-radius-sm);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
}
.form-control::placeholder { color: #9ca3af; }
.form-text { font-size: 0.78rem; }
.form-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bw-text-muted);
  margin: 1.5rem 0 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--bw-border);
}
.form-section-title:first-child { margin-top: 0; padding-top: 0; border-top: 0; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  border-radius: var(--bw-radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn svg { flex-shrink: 0; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-primary { background: var(--bw-primary); border-color: var(--bw-primary); }
.btn-primary:hover, .btn-primary:active { background: var(--bw-primary-dark) !important; border-color: var(--bw-primary-dark) !important; }
.btn-outline-secondary { border-color: var(--bw-border); color: var(--bw-text); }
.btn-outline-secondary:hover { background: var(--bw-surface); color: var(--bw-text); border-color: var(--bw-border); }
.btn.is-loading { pointer-events: none; opacity: 0.75; }
.btn.is-loading .btn-spinner { display: inline-block; }
.btn-spinner {
  display: none;
  width: 0.85em; height: 0.85em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: bw-spin 0.6s linear infinite;
}
@keyframes bw-spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Alerts
   ========================================================================== */

.app-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  border-radius: var(--bw-radius);
  border: 1px solid transparent;
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}
.app-alert svg { flex-shrink: 0; margin-top: 0.1rem; }
.app-alert--success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.app-alert--danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.app-alert--warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.app-alert--info { background: var(--bw-primary-light); border-color: #c7d2fe; color: #3730a3; }
.app-alert__close {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: inherit;
  opacity: 0.6;
  line-height: 1;
  padding: 0.15rem;
}
.app-alert__close:hover { opacity: 1; }

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--bw-text-muted);
}
.empty-state__icon {
  width: 56px; height: 56px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: var(--bw-surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--bw-text-muted);
}
.empty-state__title { font-weight: 600; color: var(--bw-text); margin-bottom: 0.25rem; font-size: 0.95rem; }
.empty-state__desc { font-size: 0.85rem; margin-bottom: 1rem; }

/* ==========================================================================
   Auth pages (Login / Select Branch) — standalone, no sidebar
   ========================================================================== */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #111827 0%, #1e293b 45%, var(--bw-surface) 45%);
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bw-card-bg);
  border-radius: var(--bw-radius-lg);
  box-shadow: var(--bw-shadow-lg);
  padding: 2rem;
}
.auth-card__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}
.auth-card__brand-mark {
  width: 40px; height: 40px;
  border-radius: var(--bw-radius);
  background: linear-gradient(135deg, var(--bw-primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.auth-card h1 { font-size: 1.25rem; margin: 0 0 0.2rem; }
.auth-card__subtitle { color: var(--bw-text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }

/* ==========================================================================
   Error / status pages
   ========================================================================== */

.status-page {
  text-align: center;
  padding: 4rem 1.5rem;
  max-width: 480px;
  margin: 0 auto;
}
.status-page__code { font-size: 3.5rem; font-weight: 800; color: var(--bw-primary); line-height: 1; margin-bottom: 0.5rem; }
.status-page__title { font-size: 1.25rem; margin-bottom: 0.5rem; }
.status-page__desc { color: var(--bw-text-muted); margin-bottom: 1.5rem; }

/* ==========================================================================
   Printable report documents (ReportsController views) — the same content
   also drives the QuestPDF/ClosedXML exports, so keep this layout in sync
   with Services/Reports/* rather than treating it as purely decorative.
   ========================================================================== */

.report-doc { max-width: 900px; margin: 0 auto; }
.report-doc__toolbar { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.report-doc__paper {
  background: #fff;
  border: 1px solid var(--bw-border);
  border-radius: var(--bw-radius-lg);
  padding: 2rem;
  box-shadow: var(--bw-shadow-sm);
}
.report-doc__letterhead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--bw-text);
}
.report-doc__firm-name { font-size: 1.3rem; font-weight: 700; }
.report-doc__firm-meta { font-size: 0.8rem; color: var(--bw-text-muted); max-width: 340px; }
.report-doc__title { font-size: 1.1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; text-align: right; }
.report-doc__meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.25rem; font-size: 0.85rem; }
.report-doc__meta-grid dt { font-weight: 600; color: var(--bw-text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.report-doc__meta-grid dd { margin: 0 0 0.4rem; }
.report-doc table.table th, .report-doc table.table td { font-size: 0.8rem; }
.report-doc__totals { max-width: 320px; margin-left: auto; }
.report-doc__words { font-size: 0.82rem; font-style: italic; margin-top: 0.75rem; }
.report-doc__signature { display: flex; justify-content: flex-end; margin-top: 3.5rem; }
.report-doc__signature-line { border-top: 1px solid var(--bw-text); padding-top: 0.35rem; font-size: 0.8rem; min-width: 180px; text-align: center; }

@media print {
  .app-sidebar, .app-header, .app-footer, .report-doc__toolbar, .skip-link { display: none !important; }
  .app-main { margin-left: 0 !important; }
  .app-content { padding: 0 !important; max-width: none !important; }
  .report-doc__paper { border: 0; box-shadow: none; padding: 0; }
  body { background: #fff !important; }
}
