/* =============================================================================
   BPM Command Center — Global Styles
   Shared across all command center pages.
   ============================================================================= */

/* =============================================================================
   CSS VARIABLES — design tokens used everywhere
   ============================================================================= */
:root {
  --color-primary:       #1e3a5f;
  --color-primary-light: #2a4f7c;
  --color-accent:        #3498db;
  --color-accent-hover:  #2980b9;
  --color-success:       #2ecc71;
  --color-warning:       #f39c12;
  --color-danger:        #e74c3c;
  --color-bg:            #f3f4f6;
  --color-surface:       #ffffff;
  --color-border:        #e1e4e8;
  --color-text:          #2c3e50;
  --color-text-muted:    #6c757d;
  --sidebar-width:       220px;
  --header-height:       60px;
}

/* =============================================================================
   RESET & BASE
   ============================================================================= */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* =============================================================================
   LAYOUT SHELL
   Header + sidebar + main content area.
   ============================================================================= */

/* Fixed top header bar */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--color-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.app-header-brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ffffff;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-header-user {
  font-size: 0.85rem;
  color: #93c5fd;
}

/* Fixed left sidebar */
.app-sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-primary);
  overflow-y: auto;
  z-index: 90;
  padding: 16px 0;
}

/* Main area — pushed right of sidebar and below header */
.app-main {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

.app-content {
  padding: 28px 32px;
  max-width: 1100px;
}

/* =============================================================================
   SIDEBAR NAVIGATION
   ============================================================================= */
.nav-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 16px 18px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: #cbd5e1;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.nav-link:hover {
  background: var(--color-primary-light);
  color: #ffffff;
  text-decoration: none;
}

.nav-link.active {
  background: var(--color-primary-light);
  color: #ffffff;
  border-left-color: var(--color-accent);
}

.nav-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 10px 18px;
}

/* External tool links — slightly muted to distinguish from internal nav */
.nav-link-external {
  opacity: 0.75;
  font-size: 0.82rem;
}

.nav-link-external:hover {
  opacity: 1;
}

/* =============================================================================
   CARDS
   ============================================================================= */
.card {
  background: var(--color-surface);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  border: 1px solid var(--color-border);
}

.card-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.card-value {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}

/* =============================================================================
   BUTTONS
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

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

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
  border-color: var(--color-danger);
}

.btn-danger:hover {
  background: #c0392b;
  border-color: #c0392b;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Header logout button — lighter style against dark header */
.btn-logout {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

/* =============================================================================
   BADGES
   ============================================================================= */
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffffff;
  white-space: nowrap;
}

/* Color variants */
.badge-blue   { background: var(--color-accent); }
.badge-green  { background: var(--color-success); }
.badge-yellow { background: var(--color-warning); }
.badge-red    { background: var(--color-danger); }
.badge-gray   { background: var(--color-text-muted); }
.badge-purple { background: #9b59b6; }

/* =============================================================================
   FORM ELEMENTS
   ============================================================================= */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 16px;
}

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

.form-input,
.form-select {
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-surface);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.form-input::placeholder {
  color: #adb5bd;
}

.form-hint {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.form-error {
  font-size: 0.8rem;
  color: var(--color-danger);
  display: none;
}

.form-error.visible {
  display: block;
}

/* =============================================================================
   DATA TABLE
   ============================================================================= */
.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--color-border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  font-size: 0.875rem;
}

.data-table th {
  background: #f8f9fa;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Striped rows */
.data-table tbody tr:nth-child(even) td {
  background: #fafbfc;
}

.data-table tbody tr:hover td {
  background: #f0f4f8;
}

/* =============================================================================
   PAGE HEADER (inside .app-content)
   ============================================================================= */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* =============================================================================
   SUMMARY CARD GRID
   ============================================================================= */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

/* =============================================================================
   ACTIVITY FEED
   ============================================================================= */
.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.activity-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.875rem;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-who {
  font-weight: 600;
  color: var(--color-text);
}

.activity-what {
  color: var(--color-text-muted);
}

.activity-when {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* =============================================================================
   ALERTS / NOTICES
   ============================================================================= */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.alert-info {
  background: #e8f4fd;
  border: 1px solid #bee3f8;
  color: #2c5282;
}

.alert-warning {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.alert-danger {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: #9b2c2c;
}

.alert-success {
  background: #f0fff4;
  border: 1px solid #9ae6b4;
  color: #22543d;
}

/* =============================================================================
   CODE SNIPPET BLOCK
   ============================================================================= */
.code-block {
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 14px 18px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
  margin: 10px 0;
}

/* =============================================================================
   LOADING SPINNER
   ============================================================================= */
.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
  color: var(--color-text-muted);
}

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */
.text-muted    { color: var(--color-text-muted); }
.text-center   { text-align: center; }
.text-right    { text-align: right; }

.flex          { display: flex; }
.flex-col      { flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap     { flex-wrap: wrap; }

.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }

.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.w-full { width: 100%; }

/* =============================================================================
   SECTION HEADINGS (within page content)
   ============================================================================= */
.section-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-border);
}

/* =============================================================================
   KPI DASHBOARD — Period filter, leaderboard, SLA bar
   ============================================================================= */

/* 4-column summary grid variant */
.summary-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* Section divider between Morning Pulse and Team Response */
.kpi-section-divider {
  height: 1px;
  background: var(--color-border);
  margin: 32px 0;
}

/* =============================================================================
   PORTFOLIO PAGE
   ============================================================================= */

.portfolio-property-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.portfolio-property-row {
  display: grid;
  grid-template-columns: 1fr 260px 120px 120px;
  align-items: center;
  gap: 20px;
  padding: 14px 16px;
  border-radius: 6px;
  border-left: 4px solid var(--color-border);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  transition: background 0.1s;
}

.portfolio-property-row:hover {
  background: #f8f9fa;
}

.portfolio-property-row:first-child {
  border-top: none;
}

.portfolio-prop-name {
  min-width: 0;
}

.portfolio-occ-col {
  min-width: 0;
}

.portfolio-occ-bar-track {
  flex: 1;
  height: 6px;
  background: var(--color-bg);
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
}

.portfolio-occ-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.portfolio-money-col {
  text-align: right;
}

/* =============================================================================
   OWNER HEALTH DASHBOARD
   ============================================================================= */

/* Risk summary bar — three pills at the top */
.risk-summary-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.risk-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: default;
  min-width: 130px;
}

.risk-pill-red    { background: #fff5f5; border-color: #fed7d7; }
.risk-pill-yellow { background: #fffbeb; border-color: #fcd34d; }
.risk-pill-green  { background: #f0fff4; border-color: #9ae6b4; }

.risk-pill-active.risk-pill-red    { border-color: var(--color-danger); }
.risk-pill-active.risk-pill-yellow { border-color: var(--color-warning); }
.risk-pill-active.risk-pill-green  { border-color: var(--color-success); }

.risk-pill-count {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
}

.risk-pill-red    .risk-pill-count { color: var(--color-danger); }
.risk-pill-yellow .risk-pill-count { color: var(--color-warning); }
.risk-pill-green  .risk-pill-count { color: var(--color-success); }

.risk-pill-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

/* All-clear banner */
.all-clear-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f0fff4;
  border: 1px solid #9ae6b4;
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.all-clear-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-success);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.all-clear-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #22543d;
}

/* Owner list — card per owner */
.owner-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.owner-card {
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border);
  border-left-width: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  overflow: hidden;
}

.owner-risk-red    { border-left-color: var(--color-danger); }
.owner-risk-yellow { border-left-color: var(--color-warning); }
.owner-risk-green  { border-left-color: var(--color-success); }

.owner-card-main {
  display: grid;
  grid-template-columns: 90px 1fr 70px 140px 140px 100px 100px 90px;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
}

/* Score column */
.owner-score-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.owner-score-number {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
}

.owner-score-bar-track {
  width: 64px;
  height: 4px;
  background: var(--color-bg);
  border-radius: 2px;
  overflow: hidden;
}

.owner-score-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.owner-name-col {
  min-width: 0;
}

.owner-metric-col {
  font-size: 0.875rem;
  line-height: 1.4;
}

.owner-metric-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.owner-metric-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.owner-action-col {
  display: flex;
  justify-content: flex-end;
}

/* Alert chips below main row */
.owner-alerts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 20px 12px;
}

.owner-alert-chip {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #fff5f5;
  color: #9b2c2c;
  border: 1px solid #fed7d7;
}

/* Period filter toggle group */
.period-filter {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
}

.period-btn {
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--color-surface);
  color: var(--color-text-muted);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}

.period-btn + .period-btn {
  border-left: 1px solid var(--color-border);
}

.period-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.period-btn.active {
  background: var(--color-accent);
  color: #ffffff;
}

/* Value color helpers */
.kpi-danger  { color: var(--color-danger); }
.kpi-warning { color: var(--color-warning); }
.kpi-success { color: var(--color-success); }

/* Avatar circle */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffffff;
  flex-shrink: 0;
}

/* Leaderboard table specifics */
.leaderboard-table .leaderboard-rank {
  color: var(--color-text-muted);
  font-weight: 700;
  font-size: 0.8rem;
  width: 48px;
}

.leaderboard-table .leaderboard-name {
  font-weight: 600;
}

.leaderboard-table .leaderboard-avg {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
}

/* SLA status badge on leaderboard rows */
.sla-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.sla-badge-green  { background: #d1fae5; color: #065f46; }
.sla-badge-yellow { background: #fef3c7; color: #92400e; }
.sla-badge-red    { background: #fee2e2; color: #991b1b; }

/* Mini count chips in the Breakdown column */
.sla-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 20px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
}

.sla-mini-green  { background: #d1fae5; color: #065f46; }
.sla-mini-yellow { background: #fef3c7; color: #92400e; }
.sla-mini-red    { background: #fee2e2; color: #991b1b; }

/* SLA stacked bar */
.sla-bar-row {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  gap: 2px;
  background: var(--color-bg);
  margin-bottom: 8px;
}

.sla-bar-segment {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
  min-width: 0;
}

.sla-green  { background: var(--color-success); }
.sla-yellow { background: var(--color-warning); }
.sla-red    { background: var(--color-danger); }

.sla-bar-legend {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.sla-legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.sla-green-dot  { background: var(--color-success); }
.sla-yellow-dot { background: var(--color-warning); }
.sla-red-dot    { background: var(--color-danger); }

/* =============================================================================
   RESPONSIVE — mobile (< 768px): collapse sidebar
   ============================================================================= */
@media (max-width: 767px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s;
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

  .app-content {
    padding: 20px 16px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }
}
