/**
 * Savage Design System - Theme CSS
 * Centralized styling for all frontend tools
 */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Backgrounds */
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #141414;
  --bg-input: #0a0a0a;
  
  /* Text */
  --text-primary: #ffffff;
  --text-secondary: #e5e5e5;
  --text-muted: #a3a3a3;
  --text-dim: #737373;
  
  /* Borders */
  --border-primary: #1f1f1f;
  --border-secondary: #262626;
  --border-input: #333333;
  --border-hover: #525252;
  
  /* Accents */
  --accent-success: #22c55e;
  --accent-danger: #ef4444;
  --accent-info: #3b82f6;
  --accent-warning: #f59e0b;
  --accent-purple: #8b5cf6;
  --accent-cyan: #06b6d4;
  
  /* Header (deprecated — kept for backward compat) */
  --header-height: 48px;
  --header-bg: #0a0a0a;
  --header-border: #1f1f1f;
  
  /* Layout */
  --content-max-width: 1200px;
  --content-padding: 24px;
  --border-radius: 8px;
  --border-radius-lg: 14px;
  --border-radius-sm: 6px;
  
  /* Sidebar Layout (primary layout system) */
  --sidebar-width-collapsed: 48px;
  --sidebar-width-expanded: 240px;
  --topbar-height: 48px;
  
  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-secondary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── DEPRECATED: Old top-header styles (kept for backward compat) ── */
/* These are overridden by layout.css when the sidebar layout is active */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--content-padding);
  z-index: 100;
}

.header-inner {
  width: 100%;
  max-width: var(--content-max-width);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  height: 112px;
  width: auto;
  display: block;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 32px;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  padding-bottom: 4px;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.nav-link:hover {
  color: var(--text-secondary);
}

.nav-link.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
}

/* Mode Toggle (deprecated) */
.mode-toggle {
  display: none;
}

.mode-toggle-btn {
  display: none;
}

/* Submenu (deprecated) */
:root {
  --submenu-height: 48px;
}

.submenu {
  display: none;
}

/* Main Content — works with both old and new layout */
.main {
  min-height: 100vh;
  padding: var(--content-padding);
}

/* When in app-shell (new layout), .main has no extra top padding */
.app-shell .main {
  padding-top: 0;
  min-height: auto;
}

.container {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.header-badge {
  padding: 8px 16px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.header-badge.blue {
  background: linear-gradient(135deg, var(--accent-info), var(--accent-purple));
  color: var(--bg-primary);
}

.header-badge.green {
  background: linear-gradient(135deg, var(--accent-success), var(--accent-cyan));
  color: var(--bg-primary);
}

.header-badge.orange {
  background: linear-gradient(135deg, var(--accent-warning), var(--accent-danger));
  color: var(--bg-primary);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius-lg);
  padding: 24px;
}

.card-header {
  margin-bottom: 20px;
}

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

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

/* Form Elements */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input, .form-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-family: var(--font-family);
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

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

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23737373'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
  padding-right: 40px;
}

.form-select option {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: var(--border-radius);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: none;
}

.btn-primary {
  width: 100%;
  background: var(--text-primary);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background: var(--text-secondary);
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-input);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.btn-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(10, 10, 10, 0.3);
  border-top-color: var(--bg-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Status Messages */
.status {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  font-size: 0.85rem;
  margin-bottom: 20px;
  display: none;
}

.status.active {
  display: block;
}

.status.success {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: var(--accent-success);
}

.status.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--accent-danger);
}

.status.info {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--accent-info);
}

.status a {
  color: inherit;
  font-weight: 500;
}

/* Toggle Switch */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
}

.toggle-info {
  flex: 1;
}

.toggle-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.toggle-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-secondary);
  transition: 0.3s;
  border-radius: 26px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-primary);
  transition: 0.3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent-info);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

/* Activity Log */
.logs-card {
  margin-top: 24px;
}

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

.logs-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.error-badge {
  background: var(--accent-danger);
  color: white;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 9999px;
  font-weight: 600;
}

.error-badge.hidden {
  display: none;
}

.clear-logs {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s, background-color 0.2s;
}

.clear-logs:hover {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

.logs-list {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.75rem;
}

.logs-list::-webkit-scrollbar {
  width: 6px;
}

.logs-list::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.logs-list::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 3px;
}

.logs-empty {
  color: var(--text-dim);
  font-style: italic;
  padding: 16px;
  text-align: center;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-primary);
}

.log-entry:last-child {
  border-bottom: none;
}

.log-time {
  color: var(--text-dim);
  font-family: 'SF Mono', 'Monaco', monospace;
  flex-shrink: 0;
}

.log-level {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.log-level.info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-info);
}

.log-level.success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-success);
}

.log-level.warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-warning);
}

.log-level.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-danger);
}

.log-message {
  color: var(--text-secondary);
  flex: 1;
}

/* Progress Bar */
.progress-container {
  margin-top: 20px;
  display: none;
}

.progress-container.active {
  display: block;
}

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

.progress-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

.progress-bar {
  width: 100%;
  height: 8px;
  background-color: var(--border-secondary);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-info), var(--accent-purple));
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-stage {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stage-icon {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

.stage-icon.crawling { background-color: var(--accent-info); }
.stage-icon.exporting { background-color: var(--accent-purple); }
.stage-icon.uploading { background-color: var(--accent-success); }
.stage-icon.complete { background-color: var(--accent-success); animation: none; }

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

.progress-details {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.progress-details span {
  display: inline-block;
  margin-right: 16px;
}

/* Results */
.results-panel {
  display: none;
}

.results-panel.active {
  display: block;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.result-item {
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius-sm);
}

.result-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.result-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.result-value.blue { color: var(--accent-info); }
.result-value.purple { color: var(--accent-purple); }
.result-value.green { color: var(--accent-success); }
.result-value.orange { color: var(--accent-warning); }

.result-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  transition: border-color 0.2s, background-color 0.2s;
}

.result-link:hover {
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.02);
}

.result-link svg {
  width: 18px;
  height: 18px;
  color: var(--text-dim);
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background-color: var(--border-secondary);
}

.divider span {
  padding: 0 16px;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Layout Grid */
.layout-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
}

.layout-grid.single {
  grid-template-columns: 1fr;
  max-width: 600px;
  margin: 0 auto;
}

/* Client Dropdown (header) */
.client-dropdown {
  background: var(--bg-secondary);
  border: 1px solid var(--border-input);
  border-radius: var(--border-radius);
  padding: 8px 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-family: var(--font-family);
  cursor: pointer;
  transition: border-color 0.2s;
}

.client-dropdown:hover,
.client-dropdown:focus {
  border-color: var(--border-hover);
  outline: none;
}

/* Metric Cards (dashboards) */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-secondary);
  border-radius: var(--border-radius);
  padding: 20px;
}

.metric-value {
  color: var(--text-primary);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}

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

.metric-change {
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 8px;
}

.metric-change.positive {
  color: var(--accent-success);
}

.metric-change.negative {
  color: var(--accent-danger);
}

/* Grid Layout (dashboards) */
.grid {
  display: grid;
  gap: 16px;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

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

/* Tables */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-secondary);
}

td {
  padding: 12px 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border-primary);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-success);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-danger);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-warning);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-info);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-secondary);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.2s, border-color 0.2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab:hover { color: var(--text-secondary); }

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

/* Chart Container */
.chart-container {
  position: relative;
  height: 300px;
}

/* Loading State */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  color: var(--text-secondary);
  font-size: 1.125rem;
  font-weight: 500;
  margin-bottom: 8px;
}

/* Utility Classes */
.text-success { color: var(--accent-success); }
.text-danger { color: var(--accent-danger); }
.text-warning { color: var(--accent-warning); }
.text-info { color: var(--accent-info); }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--text-primary); }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }

/* Client context — wider container for dashboards */
body.mode-client .container,
body.mode-client .header-inner,
body.has-client .container {
  max-width: 1600px;
}

/* Responsive */
@media (max-width: 1024px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .header {
    padding: 0 16px;
  }

  .header-nav {
    gap: 16px;
  }

  .nav-link {
    font-size: 0.8rem;
  }

  .form-row,
  .results-grid {
    grid-template-columns: 1fr;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .main {
    padding: calc(var(--header-height) + 16px) 16px 16px;
  }
}
