/* CorePilotOS — Command Center Dashboard */

:root {
  --bg: #0a0a0f;
  --bg-elevated: #12121a;
  --bg-card: #16161f;
  --bg-hover: #1c1c28;
  --fg: #e8e8ed;
  --fg-muted: #8b8b9e;
  --fg-dim: #4a4a5e;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.12);
  --accent-glow-strong: rgba(99, 102, 241, 0.25);
  --gradient-start: #6366f1;
  --gradient-end: #a855f7;
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --status-discovery: #f59e0b;
  --status-building: #6366f1;
  --status-live: #10b981;
  --status-optimizing: #a855f7;

  --auto-active: #10b981;
  --auto-paused: #6b7280;
  --auto-error: #ef4444;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

h1, h2, h3, h4, .stat-value, .client-name {
  font-family: 'Space Grotesk', sans-serif;
}

/* ─── Layout ─── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* ─── Top Nav ─── */
.topnav {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topnav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.topnav-logo .logo-mark {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.topnav-logo .logo-text {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.topnav-logo .logo-sub {
  font-size: 11px;
  color: var(--fg-muted);
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-left: 4px;
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-add-client {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-add-client:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-add-client:active { transform: translateY(0); }

/* ─── Sidebar ─── */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 8px 20px 4px;
  margin-top: 8px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--fg-muted);
  text-decoration: none;
  border-radius: 0;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
}

.sidebar-item:hover { background: var(--bg-hover); color: var(--fg); }
.sidebar-item.active {
  background: var(--accent-glow);
  color: var(--accent-hover);
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.sidebar-item .icon { font-size: 16px; opacity: 0.8; }
.sidebar-item.active .icon { opacity: 1; }

/* ─── Main Content ─── */
.main-content {
  padding: 28px 32px;
  overflow-y: auto;
  min-width: 0;
}

/* ─── Page Header ─── */
.page-header {
  margin-bottom: 28px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--fg);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--fg-muted);
}

/* ─── Metric Cards Row ─── */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

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

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
  opacity: 0.5;
}

.metric-icon {
  font-size: 20px;
  margin-bottom: 12px;
  display: block;
}

.metric-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.04em;
  line-height: 1;
  margin-bottom: 6px;
}

.metric-label {
  font-size: 12px;
  color: var(--fg-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-sub {
  font-size: 12px;
  color: var(--accent);
  margin-top: 4px;
  font-weight: 500;
}

/* ─── Section Layout ─── */
.section-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

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

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.section-count {
  font-size: 12px;
  color: var(--fg-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 10px;
}

/* ─── Client Grid ─── */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.client-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
  position: relative;
  overflow: hidden;
}

.client-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-hover);
  transform: translateY(-2px);
}

.client-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 40% at 50% 0%, var(--accent-glow) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.client-card:hover::after { opacity: 1; }

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

.client-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
}

.client-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.client-company {
  font-size: 12px;
  color: var(--fg-muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 100px;
  flex-shrink: 0;
}

.status-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-discovery { background: rgba(245, 158, 11, 0.12); color: var(--status-discovery); }
.status-building  { background: rgba(99, 102, 241, 0.12); color: var(--status-building); }
.status-live      { background: rgba(16, 185, 129, 0.12); color: var(--status-live); }
.status-optimizing { background: rgba(168, 85, 247, 0.12); color: var(--status-optimizing); }

.client-stats {
  display: flex;
  gap: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.client-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.client-stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.03em;
}

.client-stat-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.client-mrr {
  margin-left: auto;
  text-align: right;
}

.client-mrr-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--status-live);
}

.client-mrr-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Upcoming Calls Panel ─── */
.calls-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.call-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: background 0.15s ease;
}

.call-item:last-child { border-bottom: none; }
.call-item:hover { background: var(--bg-hover); }

.call-avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.call-client-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 1px;
}

.call-date {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

.call-notes {
  font-size: 12px;
  color: var(--fg-muted);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.call-days {
  margin-left: auto;
  flex-shrink: 0;
  text-align: center;
}

.call-days-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.call-days-label {
  font-size: 10px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Urgent call highlight */
.call-item.call-soon .call-days-num { color: var(--status-discovery); }

/* ─── Empty State ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  color: var(--fg-muted);
  gap: 12px;
}

.empty-icon {
  font-size: 40px;
  opacity: 0.4;
  margin-bottom: 4px;
}

.empty-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg-muted);
}

.empty-sub {
  font-size: 13px;
  color: var(--fg-dim);
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

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

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

.modal-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.15s ease;
}

.modal-close:hover { color: var(--fg); }

/* ─── Form Elements ─── */
.form-row { margin-bottom: 16px; }

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

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  padding: 10px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  -webkit-appearance: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b8b9e' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-select option { background: var(--bg-card); color: var(--fg); }

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

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

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--fg); border-color: var(--border-hover); }

/* ─── Client Detail Panel ─── */
.detail-panel {
  display: none;
}

.detail-panel.open {
  display: block;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.detail-avatar {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 20px;
  color: white;
}

.detail-client-name {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 3px;
}

.detail-client-meta {
  font-size: 13px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  transition: color 0.15s ease, background 0.15s ease;
}

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

/* ─── Automations List ─── */
.automations-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.automation-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: border-color 0.2s ease;
}

.automation-row:hover { border-color: var(--border-hover); }

.automation-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.auto-active-dot  { background: var(--auto-active); box-shadow: 0 0 8px rgba(16,185,129,0.5); }
.auto-paused-dot  { background: var(--auto-paused); }
.auto-error-dot   { background: var(--auto-error); box-shadow: 0 0 8px rgba(239,68,68,0.5); }

.automation-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--fg);
  flex: 1;
}

.automation-desc {
  font-size: 12px;
  color: var(--fg-muted);
  margin-top: 1px;
}

.automation-metrics {
  display: flex;
  gap: 20px;
  flex-shrink: 0;
}

.auto-metric {
  text-align: right;
}

.auto-metric-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.auto-metric-label {
  font-size: 10px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Status Filter Tabs ─── */
.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}

.filter-tab {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--fg-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-tab:hover { color: var(--fg); background: var(--bg-hover); }
.filter-tab.active { background: var(--bg-card); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,0.3); }

.filter-tab .tab-count {
  background: var(--bg-elevated);
  color: var(--fg-muted);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 100px;
  border: 1px solid var(--border);
}

.filter-tab.active .tab-count {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(99,102,241,0.2);
}

/* ─── Loading Skeleton ─── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

/* ─── Toast Notification ─── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--fg);
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  max-width: 320px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-success { border-left: 3px solid var(--status-live); }
.toast-error   { border-left: 3px solid var(--auto-error); }

/* ─── Add Automation Button ─── */
.btn-add-small {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-add-small:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ─── Color Picker ─── */
.color-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: white; }

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .section-grid {
    grid-template-columns: 1fr;
  }
  .main-content {
    padding: 20px 16px;
  }
}
