/* =====================================================
   Wohler CFO Platform — Main Stylesheet
   Version: 1.0
   ===================================================== */

:root {
  --primary: #1a2332;
  --primary-light: #243447;
  --accent: #00d4aa;
  --accent-hover: #00b894;
  --accent-warning: #f39c12;
  --accent-danger: #e74c3c;
  --accent-info: #3498db;
  --accent-purple: #9b59b6;
  --text-primary: #e8edf4;
  --text-secondary: #8fa3b8;
  --text-muted: #5c7a96;
  --border: rgba(255,255,255,0.08);
  --border-accent: rgba(0,212,170,0.3);
  --card-bg: rgba(255,255,255,0.04);
  --card-bg-hover: rgba(255,255,255,0.07);
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.4);
  --transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* ===================== LAYOUT ===================== */
#app { display: flex; height: 100vh; }

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-width);
  background: rgba(0,0,0,0.25);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: var(--transition);
  overflow: hidden;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-height);
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), #00a885);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800;
  color: var(--primary);
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-size: 15px; font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.sidebar-logo .logo-sub {
  font-size: 11px; color: var(--text-muted);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.nav-section {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
}

.nav-item:hover {
  background: var(--card-bg);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(0,212,170,0.12);
  color: var(--accent);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
  width: 18px; height: 18px;
  font-size: 15px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--accent-danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.nav-badge.warn { background: var(--accent-warning); }
.nav-badge.info { background: var(--accent-info); }
.nav-badge.ok { background: var(--accent); color: var(--primary); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.user-card:hover { background: var(--card-bg); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3498db, #9b59b6);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  color: white; flex-shrink: 0;
}

.user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ===================== MAIN CONTENT ===================== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ===================== HEADER ===================== */
.top-header {
  height: var(--header-height);
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.header-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  text-decoration: none;
}

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

.btn-ghost {
  background: var(--card-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--card-bg-hover); color: var(--text-primary); }

.btn-danger {
  background: rgba(231,76,60,0.15);
  color: var(--accent-danger);
  border: 1px solid rgba(231,76,60,0.3);
}
.btn-danger:hover { background: rgba(231,76,60,0.25); }

.btn-warn {
  background: rgba(243,156,18,0.15);
  color: var(--accent-warning);
  border: 1px solid rgba(243,156,18,0.3);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--card-bg);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
.status-dot.green { background: var(--accent); }
.status-dot.yellow { background: var(--accent-warning); }
.status-dot.red { background: var(--accent-danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===================== PAGE CONTENT ===================== */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ===================== CARDS ===================== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}

.card:hover { background: var(--card-bg-hover); }

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===================== KPI TILES ===================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.kpi-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}

.kpi-card.warn::before { background: var(--accent-warning); }
.kpi-card.danger::before { background: var(--accent-danger); }
.kpi-card.info::before { background: var(--accent-info); }
.kpi-card.purple::before { background: var(--accent-purple); }

.kpi-label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.kpi-value.large { font-size: 28px; }
.kpi-value.small { font-size: 18px; }

.kpi-change {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.kpi-change.up { color: var(--accent); }
.kpi-change.down { color: var(--accent-danger); }
.kpi-change.neutral { color: var(--text-muted); }

.kpi-icon {
  position: absolute;
  right: 16px; top: 50%;
  transform: translateY(-50%);
  font-size: 28px;
  opacity: 0.1;
}

/* ===================== GRIDS ===================== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: rgba(0,0,0,0.2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--card-bg-hover); }

tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

.td-muted { color: var(--text-muted); font-size: 12px; }
.td-money { font-variant-numeric: tabular-nums; font-weight: 600; }
.td-money.positive { color: var(--accent); }
.td-money.negative { color: var(--accent-danger); }

/* ===================== BADGES ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green { background: rgba(0,212,170,0.15); color: var(--accent); }
.badge-red { background: rgba(231,76,60,0.15); color: var(--accent-danger); }
.badge-yellow { background: rgba(243,156,18,0.15); color: var(--accent-warning); }
.badge-blue { background: rgba(52,152,219,0.15); color: var(--accent-info); }
.badge-purple { background: rgba(155,89,182,0.15); color: var(--accent-purple); }
.badge-gray { background: rgba(255,255,255,0.08); color: var(--text-muted); }

/* ===================== CHARTS ===================== */
.chart-container {
  position: relative;
  height: 240px;
  width: 100%;
}

.chart-container.tall { height: 320px; }
.chart-container.short { height: 160px; }

/* ===================== PROGRESS BARS ===================== */
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.8s cubic-bezier(0.4,0,0.2,1);
}

.progress-fill.warn { background: var(--accent-warning); }
.progress-fill.danger { background: var(--accent-danger); }
.progress-fill.info { background: var(--accent-info); }

/* ===================== ALERTS ===================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 13.5px;
  line-height: 1.5;
}

.alert-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-content {}
.alert-title { font-weight: 700; margin-bottom: 3px; }
.alert-text { color: var(--text-secondary); }

.alert-danger { background: rgba(231,76,60,0.1); border: 1px solid rgba(231,76,60,0.3); }
.alert-danger .alert-icon, .alert-danger .alert-title { color: var(--accent-danger); }

.alert-warning { background: rgba(243,156,18,0.1); border: 1px solid rgba(243,156,18,0.3); }
.alert-warning .alert-icon, .alert-warning .alert-title { color: var(--accent-warning); }

.alert-info { background: rgba(52,152,219,0.1); border: 1px solid rgba(52,152,219,0.3); }
.alert-info .alert-icon, .alert-info .alert-title { color: var(--accent-info); }

.alert-success { background: rgba(0,212,170,0.08); border: 1px solid rgba(0,212,170,0.25); }
.alert-success .alert-icon, .alert-success .alert-title { color: var(--accent); }

/* ===================== ENTITY CARDS ===================== */
.entity-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.entity-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.entity-card .entity-color-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.entity-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.entity-type { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }

.entity-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.entity-stat:last-child { border-bottom: none; }
.entity-stat-label { color: var(--text-muted); }
.entity-stat-value { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ===================== MODAL ===================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.open { display: flex; }

.modal {
  background: #1e2d3e;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 520px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  transition: var(--transition);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===================== FORM ELEMENTS ===================== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.form-input, .form-select {
  width: 100%;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
  font-family: inherit;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  background: rgba(0,0,0,0.3);
}

.form-input::placeholder { color: var(--text-muted); }

/* ===================== TIMELINE ===================== */
.timeline { position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 18px; top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
}

.timeline-item {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  position: relative;
}

.timeline-dot {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  z-index: 1;
}

.timeline-dot.green { background: rgba(0,212,170,0.15); color: var(--accent); border: 1px solid var(--border-accent); }
.timeline-dot.red { background: rgba(231,76,60,0.15); color: var(--accent-danger); }
.timeline-dot.yellow { background: rgba(243,156,18,0.15); color: var(--accent-warning); }
.timeline-dot.blue { background: rgba(52,152,219,0.15); color: var(--accent-info); }

.timeline-content {
  flex: 1;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.timeline-title { font-size: 13.5px; font-weight: 600; margin-bottom: 4px; }
.timeline-text { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.timeline-date { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

/* ===================== TABS ===================== */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-btn {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
  background: none;
  border-top: none; border-left: none; border-right: none;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

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

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

/* ===================== EMPTY STATE ===================== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 40px; margin-bottom: 16px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state-text { font-size: 13.5px; line-height: 1.6; }

/* ===================== AGENT INBOX ===================== */
.message-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: var(--transition);
  cursor: pointer;
}

.message-card:hover { border-color: var(--border-accent); }
.message-card.unread { border-left: 3px solid var(--accent); }

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

.message-from {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
}

.agent-avatar {
  width: 28px; height: 28px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

.message-subject { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.message-preview { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.message-time { font-size: 11px; color: var(--text-muted); }

/* ===================== SECTION HEADERS ===================== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 2px;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ===================== UTILITIES ===================== */
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-mono { font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 12px; }
