/* ==========================================================================
   UI COMPONENTS
   Cards, Buttons, Status Pills, Modals, Toasts, Skeletons
   ========================================================================== */

/* ==========================================================================
   CARDS & PANELS
   ========================================================================== */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
  position: relative;
  overflow: hidden;
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--text-primary);
  color: var(--text-inverse);
  box-shadow: 0 1px 3px rgba(23, 23, 23, 0.15);
}

.btn-primary:hover {
  background-color: #2b2b2b;
  box-shadow: 0 4px 12px rgba(23, 23, 23, 0.2);
}

.btn-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background-color: var(--bg-surface-secondary);
  border-color: var(--border-medium);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--bg-surface-secondary);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 0.95rem;
  border-radius: var(--radius-md);
}

.btn-accent-green {
  background-color: var(--status-success);
  color: #FFFFFF;
}

.btn-accent-green:hover {
  background-color: #26684c;
}

/* ==========================================================================
   STATUS BADGES & PILLS
   ========================================================================== */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background-color: var(--bg-surface-secondary);
  color: var(--text-secondary);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
}

.status-operational {
  background-color: var(--status-success-bg);
  color: var(--status-success);
}

.status-degraded {
  background-color: var(--status-warning-bg);
  color: var(--status-warning);
}

.status-maintenance {
  background-color: var(--status-danger-bg);
  color: var(--status-danger);
}

.trend-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.trend-positive {
  background-color: var(--status-success-bg);
  color: var(--status-success);
}

.trend-negative {
  background-color: var(--status-danger-bg);
  color: var(--status-danger);
}

.industry-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-surface-secondary);
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

/* ==========================================================================
   INPUTS & DROPDOWNS
   ========================================================================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(23, 23, 23, 0.06);
}

.select-custom {
  padding: 8px 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.select-custom:focus, .select-custom:hover {
  border-color: var(--border-medium);
}

/* ==========================================================================
   MODAL & BACKDROP
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-box {
  width: 90%;
  max-width: 620px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-float);
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-smooth);
  overflow: hidden;
}

.modal-backdrop.open .modal-box {
  transform: scale(1) translateY(0);
}

.report-recipient-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 12px;
  margin-top: 10px;
}

.report-recipient-chip,
.report-recipient-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: var(--bg-canvas-alt);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: .78rem;
}

.report-recipient-chip button {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.report-recipient-history {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas-alt);
  padding: 10px 12px;
}

.report-recipient-history summary {
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
}

.report-recipient-options {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.report-recipient-option {
  cursor: pointer;
}

/* ==========================================================================
   NOTIFICATION DRAWER
   ========================================================================== */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background-color: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xl);
  z-index: 500;
  transform: translateX(100%);
  transition: transform var(--transition-smooth);
  display: none;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
}

.drawer.open {
  display: flex;
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

@media (max-width: 420px) {
  .drawer { width: 100vw; }
  .header-right > .status-pill,
  .header-right > a { display: none; }
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notif-card {
  padding: 14px;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface-secondary);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.notif-card:hover {
  background-color: #ECEAE3;
  border-color: var(--border-medium);
}

.notif-card.unread {
  background-color: var(--bg-surface);
  border-left: 3px solid var(--text-primary);
}

.notif-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.notif-message {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.notif-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

/* ==========================================================================
   SKELETON LOADERS
   ========================================================================== */
.skeleton {
  background: linear-gradient(90deg, #F0EFEB 25%, #FAFAF8 50%, #F0EFEB 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s infinite ease-in-out;
  border-radius: var(--radius-xs);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 14px;
  margin-bottom: 6px;
  border-radius: 4px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
  border-radius: 6px;
}

.skeleton-card {
  height: 220px;
  border-radius: var(--radius-lg);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background-color: var(--text-primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-xl);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: toast-in 0.3s var(--ease-out-expo) forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==========================================================================
   Business Impact Report document
   Mirrors backend/app/utils/export.py section for section, so the on-screen
   report, the browser print output and the downloaded PDF agree.
   ========================================================================== */

.report-doc {
  max-width: 980px;
  margin: 0 auto;
}

.report-actionbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.report-actionbar-spacer { flex: 1; }

.report-jumpnav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 0;
  margin-bottom: 14px;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-subtle);
}

.report-jumplink {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.report-jumplink:hover { background: var(--bg-canvas-alt); }

.report-jumplink.is-active {
  background: var(--report-accent);
  color: #fff;
}

.report-sheet {
  background: var(--bg-surface, #fff);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 40px 44px 32px;
}

.report-masthead { margin-bottom: 26px; }

.report-doc-title {
  font-size: 1.65rem;
  line-height: 1.25;
  font-weight: 700;
  color: var(--report-accent);
  margin: 0 0 10px;
}

.report-doc-period {
  font-size: 1rem;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.report-doc-meta {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin: 0;
}

.report-section { margin-bottom: 34px; }

.report-section-title {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--report-accent);
  margin: 0 0 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--report-accent);
}

.report-callout {
  border-left: 4px solid var(--report-accent);
  background: color-mix(in srgb, var(--report-accent) 7%, transparent);
  padding: 16px 18px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.report-callout p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.report-prose {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-primary);
  margin: 0 0 12px;
}

.report-kpi-grid,
.report-lead-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 20px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.report-kpi,
.report-lead-tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 16px 18px;
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.report-lead-grid { background: color-mix(in srgb, var(--report-accent) 5%, transparent); }

.report-outcome-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.report-outcome-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}

.report-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.report-mini-table th,
.report-mini-table td {
  padding: 7px 0;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.report-mini-table th { color: var(--text-secondary); font-weight: 600; }
.report-mini-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.report-mini-table tr:last-child td { border-bottom: 0; }

.report-kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--report-accent);
}

.report-kpi-label {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.report-lead-caps {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--report-accent);
  margin-bottom: 4px;
}

.report-chart-wrap {
  margin-top: 20px;
  padding: 16px 18px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.report-chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.report-chart-note {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

/* Chart.js runs with maintainAspectRatio:false so it fills its parent. Without
   a height here the canvas grows without bound on every responsive resize,
   which is what made this chart render full-screen. */
.report-chart-canvas {
  position: relative;
  height: 170px;
}

.report-card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 16px;
}

.report-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}

.report-card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--report-accent);
  margin: 0 0 6px;
}

.report-card p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 6px;
}

.report-chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.report-chip:hover { background: var(--bg-canvas-alt); }

.report-chip.is-active {
  background: var(--report-accent);
  border-color: var(--report-accent);
  color: #fff;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.84rem;
}

.report-table th {
  background: var(--report-accent);
  color: #fff;
  font-weight: 700;
  text-align: left;
  padding: 9px 12px;
}

.report-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  color: var(--text-primary);
}

.report-table tbody tr:nth-child(even) td { background: var(--bg-canvas-alt); }

/* A measured zero is real data, so it stays legible, just quieter. */
.report-table tbody tr.is-zero td { color: var(--text-secondary); }

.report-table .is-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.report-table th.is-num { text-align: right; }

.report-impact {
  color: var(--text-secondary);
  line-height: 1.5;
}

.report-empty {
  font-size: 0.84rem;
  color: var(--text-tertiary);
  padding: 14px 0;
}

.report-doc-footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  color: var(--text-tertiary);
}

@media (max-width: 860px) {
  .report-sheet { padding: 24px 20px; }
  .report-chart-canvas { height: 140px; }
  .report-kpi-grid,
  .report-lead-grid,
  .report-card-grid,
  .report-outcome-grid { grid-template-columns: 1fr; }
  .report-table { display: block; overflow-x: auto; }
}

/* --- Print: the browser output should match the downloaded PDF ----------- */
@media print {
  .no-print,
  .sidebar,
  .topnav,
  #threejs-bg-canvas,
  .toast-container { display: none !important; }

  .app-container,
  .main-wrapper,
  .content-container { display: block; margin: 0; padding: 0; }

  .report-doc { max-width: none; }

  .report-sheet {
    border: 0;
    border-radius: 0;
    padding: 0;
  }

  .report-section { break-inside: avoid-page; }
  .report-section-title { break-after: avoid-page; }
  .report-table { break-inside: auto; font-size: 9pt; }
  .report-table thead { display: table-header-group; }
  .report-table tr { break-inside: avoid; }
  .report-callout,
  .report-card { break-inside: avoid; }

  .report-table th,
  .report-kpi-value,
  .report-section-title,
  .report-doc-title {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
