/* ==========================================================================
   MASTER DESIGN SYSTEM (frontend/css/base.css)
   Soft Gray, Seamless Flat Architecture (Zero Floating White Cards)
   ========================================================================== */

:root {
  /* Core Gray Palette & Monochromatic Canvas */
  --bg-main: #EEF2F6;            /* Unified matte gray canvas */
  --bg-surface: #F8FAFC;         /* Low-contrast flat pane */
  --bg-inset: #E7ECF2;           /* Subdued gray inputs / badges */
  --bg-hover: #E2E8F0;           /* Subtle hover feedback */

  /* Text & Typography */
  --text-primary: #0F172A;       /* High-contrast slate */
  --text-secondary: #5A6C88;     /* Muted metadata */
  --text-tertiary: #94A3B8;      /* Structural tags */

  /* Hairlines & Architectural Dividers (No Thick Drop Shadows) */
  --border-color: #DFE5ED;
  --border-light: #E8EDF4;
  --border-active: #BFD5F2;

  /* Accent Tones */
  --blue-primary: #2563EB;
  --blue-hover: #1D4ED8;
  --blue-light: #EBF2FA;
  --blue-glow: transparent;

  /* Semantic State Tokens */
  --danger: #DC2626;
  --danger-bg: #FEE2E2;
  --success: #059669;
  --success-bg: #D1FAE5;
  --warning: #D97706;
  --warning-bg: #FEF3C7;
  --purple: #7C3AED;
  --purple-bg: #EDE9FE;

  /* Layout Spacing */
  --sidebar-w: 240px;
  --topbar-h: 60px;

  /* Typography Stacks */
  --font-stack: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;

  /* Geometry (Flat, Minimal Shadows) */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: 0 12px 30px rgba(15, 23, 42, 0.08);
}

/* ==========================================================================
   CSS RESET & CORE SMOOTHING
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-stack);
  background: var(--bg-main);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
  letter-spacing: -0.015em;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
  outline: none;
  transition: all 0.15s ease;
}

input, select, textarea {
  font-family: inherit;
}

a {
  text-decoration: none;
  color: inherit;
  transition: color 0.15s ease;
}

ul {
  list-style: none;
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */
.flex { display: flex; } 
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; } 
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; } 
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.wrap { flex-wrap: wrap; }
.w-full { width: 100%; }
.text-secondary { color: var(--text-secondary); } 
.text-tertiary { color: var(--text-tertiary); }
.hidden { display: none !important; }

/* ==========================================================================
   APPLICATION SHELL (Flat Monochromatic Seamless Layout)
   ========================================================================== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-main);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #2563EB 0%, #7C3AED 100%);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
}

.brand-title {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

.brand-subtitle {
  font-size: 9px;
  color: var(--text-secondary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

.sidebar-nav {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 14px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12.5px;
}

.nav-item svg {
  width: 17px;
  height: 17px;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.nav-item.active {
  background: #FFFFFF;
  color: var(--blue-primary);
  border: 1px solid var(--border-color);
  font-weight: 700;
}

.nav-item.active svg {
  opacity: 1;
  color: var(--blue-primary);
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
  background: var(--bg-main);
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  background: var(--bg-main);
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  width: 320px;
  transition: all 0.15s ease;
}

.search-box:focus-within {
  border-color: var(--blue-primary);
  background: #FFFFFF;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 12.5px;
  color: var(--text-primary);
}

.env-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-surface);
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}

.env-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  flex-shrink: 0;
}

.content-area {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-main);
}

h1.page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.035em;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.page-sub {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.4;
}

.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

/* ==========================================================================
   SEAMLESS PANES (Replaces Floating Boxed Cards)
   ========================================================================== */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: none;
}

.card-header {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Flat Monochromatic KPI System */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: none;
}

.kpi-label {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.035em;
  font-family: var(--font-mono);
}

/* ==========================================================================
   BUTTONS & FORM ELEMENTS
   ========================================================================== */
.btn-primary {
  background: var(--blue-primary);
  color: #fff;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.btn-primary:hover {
  background: var(--blue-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: var(--bg-surface);
  border-color: #CBD5E1;
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 12.5px;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
}

.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.btn-icon:hover {
  background: var(--bg-inset);
  color: var(--danger);
}

/* Seamless Forms */
.form-group {
  margin-bottom: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-label {
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}

.form-input {
  width: 100%;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  font-size: 13px;
  transition: border-color 0.15s ease;
}

.form-input:focus {
  border-color: var(--blue-primary);
}

.form-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ==========================================================================
   BADGES & CHIPS
   ========================================================================== */
.badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.badge-hot { color: var(--danger); background: var(--danger-bg); border: 1px solid rgba(220, 38, 38, 0.2); }
.badge-warning { color: #B45309; background: var(--warning-bg); border: 1px solid rgba(217, 119, 6, 0.2); }
.badge-cold { color: var(--text-secondary); background: var(--bg-inset); border: 1px solid var(--border-color); }
.badge-stage { color: var(--blue-primary); background: var(--blue-light); border: 1px solid var(--border-active); }
.badge-success { color: var(--success); background: var(--success-bg); border: 1px solid rgba(5, 150, 105, 0.2); }
.badge-ai { color: var(--purple); background: var(--purple-bg); border: 1px solid rgba(124, 58, 237, 0.2); }

/* ==========================================================================
   TABLES (Flat Seamless Data Grid)
   ========================================================================== */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #FFFFFF;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

th {
  text-align: left;
  font-size: 10.5px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  font-weight: 700;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr.row-clickable:hover {
  background: var(--blue-light);
  cursor: pointer;
}

/* ==========================================================================
   MODALS & DRAWERS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(2px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  display: flex;
  opacity: 1;
}

.modal {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  width: 520px;
  max-width: 92vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal.modal-lg {
  width: 720px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 15px;
  flex-shrink: 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: var(--radius-lg);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: #0F172A; border-left: 3px solid var(--success); }

/* ==========================================================================
   EMPTY & LOADING STATES
   ========================================================================== */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state-title {
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-size: 14.5px;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-inset) 25%, var(--bg-surface) 37%, var(--bg-inset) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: 4px;
}

@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ==========================================================================
   CUSTOM THIN SCROLLBARS
   ========================================================================== */
* {
  scrollbar-width: thin;
  scrollbar-color: #CBD5E1 transparent;
}

*::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    left: -240px;
    z-index: 500;
    transition: left 0.25s ease;
  }
  .sidebar.mobile-open {
    left: 0;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .modal {
    width: 96vw;
  }
  .topbar {
    padding: 0 14px;
  }
  .search-box {
    width: 160px;
  }
}