/* ==========================================================================
   Borbolla Control — Corporate Stylesheet
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  --topbar-bg: #1e293b;
  --topbar-height: 56px;
  --sidebar-width: 240px;
  --sidebar-bg: #f8f9fa;
  --sidebar-border: #dee2e6;
  --sidebar-active-bg: #e2e6ea;
  --sidebar-active-color: #1e293b;
  --sidebar-link-color: #495057;
  --sidebar-link-hover-bg: #e9ecef;
  --body-bg: #f0f2f5;
  --card-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  --card-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
  --corporate-blue: #1e3a8a;
  --corporate-accent: #3b82f6;
}

/* --------------------------------------------------------------------------
   Base / Layout
   -------------------------------------------------------------------------- */
html, body {
  height: 100%;
}

body {
  background: var(--body-bg);
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Top Navigation Bar
   -------------------------------------------------------------------------- */
#topbar,
.topbar {
  background-color: var(--topbar-bg) !important;
  height: var(--topbar-height);
  z-index: 1030;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* --------------------------------------------------------------------------
   Sidebar — Desktop
   -------------------------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1020;
}

.sidebar-link {
  color: var(--sidebar-link-color);
  padding: 0.55rem 1.25rem;
  border-radius: 0;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  transition: background 0.15s ease;
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--sidebar-link-hover-bg);
  color: var(--sidebar-active-color);
}

.sidebar-link.active,
.sidebar-link.active:hover {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-color);
  font-weight: 600;
  border-left: 3px solid var(--corporate-accent);
}

.sidebar-divider {
  border-color: var(--sidebar-border);
  margin: 0.5rem 1rem;
}

/* --------------------------------------------------------------------------
   Main Content Area
   -------------------------------------------------------------------------- */
.main-content {
  margin-top: var(--topbar-height);
  padding-left: 0;
}

@media (min-width: 992px) {
  .main-content {
    margin-left: var(--sidebar-width);
  }
}

/* --------------------------------------------------------------------------
   KPI / Stat Cards
   -------------------------------------------------------------------------- */
.card {
  border: 1px solid #e9ecef;
  box-shadow: var(--card-shadow);
  border-radius: 8px;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--card-shadow-hover);
}

.kpi-card {
  border-left: 4px solid var(--corporate-accent);
}

.kpi-card .kpi-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--corporate-blue);
}

.kpi-card .kpi-label {
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
}

.kpi-card .kpi-icon {
  font-size: 2.25rem;
  opacity: 0.15;
}

/* Color variants for KPI borders */
.kpi-card.kpi-success { border-left-color: #22c55e; }
.kpi-card.kpi-warning { border-left-color: #f59e0b; }
.kpi-card.kpi-danger  { border-left-color: #ef4444; }
.kpi-card.kpi-info    { border-left-color: #06b6d4; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table {
  font-size: 0.875rem;
}

.table thead th {
  background: #f8f9fa;
  border-bottom: 2px solid #dee2e6;
  font-weight: 600;
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6c757d;
  white-space: nowrap;
}

.table-hover tbody tr:hover {
  background: #f1f5f9;
}

.table-clickable tbody tr {
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-control,
.form-select {
  font-size: 0.875rem;
  border-radius: 6px;
  border-color: #ced4da;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.form-label {
  font-weight: 500;
  font-size: 0.8125rem;
  color: #374151;
  margin-bottom: 0.3rem;
}

.form-text {
  font-size: 0.75rem;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  font-size: 0.875rem;
  border-radius: 6px;
  font-weight: 500;
}

.btn-sm {
  font-size: 0.8rem;
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  border-radius: 8px;
  font-size: 0.875rem;
}

/* --------------------------------------------------------------------------
   Status Badges — Invoice / Document states
   -------------------------------------------------------------------------- */
.badge-draft     { background-color: #6c757d; }
.badge-pending   { background-color: #f59e0b; color: #1f2937; }
.badge-stamped   { background-color: #22c55e; color: #fff; }
.badge-cancelled { background-color: #ef4444; }
.badge-error     { background-color: #ef4444; }

/* Bootstrap-compatible status badge utility */
.status-badge {
  font-size: 0.75rem;
  padding: 0.25em 0.65em;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-draft     { background: #e5e7eb; color: #374151; }
.status-pending   { background: #fef3c7; color: #92400e; }
.status-stamped   { background: #d1fae5; color: #065f46; }
.status-cancelled { background: #fee2e2; color: #991b1b; }
.status-error     { background: #fee2e2; color: #991b1b; }

/* --------------------------------------------------------------------------
   Environment Badge (FacturAPI mode)
   -------------------------------------------------------------------------- */
.env-test { background: #cffafe; color: #164e63; }
.env-live { background: #fee2e2; color: #991b1b; }

/* --------------------------------------------------------------------------
   Page Header
   -------------------------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e9ecef;
}

.page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
  color: #1e293b;
}

/* --------------------------------------------------------------------------
   Empty State
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #9ca3af;
}

.empty-state i {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 1rem;
}

/* --------------------------------------------------------------------------
   HTMX Loading Indicator
   -------------------------------------------------------------------------- */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* --------------------------------------------------------------------------
   Responsive adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
  .main-content {
    margin-left: 0;
  }
}

@media (max-width: 575.98px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .table-responsive {
    font-size: 0.8rem;
  }
}

/* --------------------------------------------------------------------------
   Utility helpers
   -------------------------------------------------------------------------- */
.cursor-pointer { cursor: pointer; }
.font-monospace { font-family: 'Courier New', Courier, monospace; font-size: 0.85em; }
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Header Account Menu (<details> dropdown)
   -------------------------------------------------------------------------- */
.header-menu {
  position: relative;
  display: inline-block;
  margin: 0;
}

.header-menu__summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 36px;
  padding: 0.3rem 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font-size: 0.875rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.header-menu__summary::-webkit-details-marker {
  display: none;
}

.header-menu__summary:hover,
.header-menu[open] .header-menu__summary {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

.header-menu__summary-icon {
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0.9;
}

.header-menu__summary-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.header-menu__summary-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  opacity: 0.7;
}

.header-menu__summary-name {
  font-size: 0.8rem;
  font-weight: 500;
}

.header-menu__chevron {
  opacity: 0.6;
  font-size: 0.65rem;
  transition: transform 0.15s ease;
}

.header-menu[open] .header-menu__chevron {
  transform: rotate(180deg);
}

/* Popover panel */
.header-menu__popover {
  display: none;
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  min-width: 260px;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  z-index: 1100;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.header-menu[open] .header-menu__popover {
  display: block;
}

.header-menu__header {
  padding: 0.75rem 0.9rem;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
}

.header-menu__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #1e293b;
  margin: 0;
}

.header-menu__subtitle {
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: #6c757d;
}

.header-menu .dropdown-divider {
  margin: 0;
  border-top-color: #e9ecef;
}

.header-menu .dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.6rem 0.9rem;
  text-decoration: none;
  color: #212529;
  background: #fff;
  border: 0;
  font-size: 0.85rem;
}

.header-menu .dropdown-item:hover {
  background: #f1f5f9;
}

.header-menu form {
  margin: 0;
}

.header-menu--tenant .header-menu__popover {
  min-width: 320px;
}

.tenant-switcher__list {
  padding: 0.35rem;
}

.tenant-switcher__form + .tenant-switcher__form {
  margin-top: 0.35rem;
}

.tenant-switcher__item {
  justify-content: space-between;
  gap: 0.85rem;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.75rem 0.8rem;
}

.tenant-switcher__item-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.tenant-switcher__item-name {
  font-weight: 600;
  color: #1e293b;
}

.tenant-switcher__item-meta {
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: #6c757d;
}

.tenant-switcher__state {
  flex-shrink: 0;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.72rem;
  font-weight: 600;
}

.tenant-switcher__item--active {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.tenant-switcher__item--active:hover {
  background: #dbeafe;
}
/* --------------------------------------------------------------------------
   Auth Pages (Login) — phi-based proportions
   phi = 1.618 | 1/phi = 0.618 | 1/phi² = 0.382
   -------------------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(15, 23, 42, 0.10), transparent 24%),
    var(--body-bg);
  padding: 1.5rem;
}

.auth-shell {
  width: 100%;
  max-width: 460px;                         /* card width */
}

.auth-card {
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.14);
}

/* Brand header — stacked layout so the wide logo can breathe */
.auth-card__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  /* phi spacing: top 2rem, bottom 2rem/phi ≈ 1.236rem */
  padding: 2rem 1.75rem 1.25rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 58%, #334155 100%);
}

/* Logo: width = 61.8% of card (phi ratio), height auto from native aspect */
.auth-card__logo {
  width: 61.8%;                             /* 460 × 0.618 ≈ 284px → ~54px tall */
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
  margin-bottom: 1rem;
}

.auth-card__eyebrow {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.auth-card__brand h1 {
  margin: 0.2rem 0 0.35rem;
  color: #fff;
  font-size: 1.55rem;
  font-weight: 700;
}

.auth-card__brand p {
  margin: 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.92rem;
}

.auth-card__body {
  padding: 1.75rem;
  background: #fff;
}

.auth-btn {
  background: #1e293b;
  border-color: #1e293b;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.auth-btn:hover,
.auth-btn:focus {
  background: #334155;
  border-color: #334155;
}

.auth-page__footer {
  margin: 1rem 0 0;
  text-align: center;
  color: #64748b;
  font-size: 0.8rem;
}
