/* styles.css — Custom styles for PBRTQC Chart Simulator */

/* === CSS Variables === */
:root {
  --color-primary: #1e40af;
  --color-secondary: #4f46e5;
  --color-surface: #f8fafc;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-border: #e2e8f0;
  --color-phase1: #3b82f6;
  --color-phase2: #10b981;
  --color-alarm: #ef4444;
  --color-warning: #f59e0b;
  --sidebar-width: 340px;
  --header-height: 56px;
}

/* === Dark Theme === */
.dark {
  --color-surface: #0f172a;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-border: #334155;
}

.dark body {
  background-color: #0f172a;
  color: #e2e8f0;
}

.dark .sidebar {
  background-color: #1e293b;
  border-color: #334155;
}

.dark .stat-card {
  background-color: #1e293b;
  border-color: #334155;
}

.dark .chart-container {
  background-color: #1e293b;
  border-color: #334155;
}

.dark .alarm-log-table th {
  background-color: #1e293b;
}

.dark .alarm-log-table tr:hover {
  background-color: #334155;
}

.dark .section-header {
  border-color: #334155;
}

.dark input, .dark select, .dark textarea {
  background-color: #0f172a;
  border-color: #475569;
  color: #e2e8f0;
}

.dark .drop-zone {
  border-color: #475569;
  background-color: #1e293b;
}

/* === Layout === */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--color-surface);
  color: var(--color-text);
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--color-border);
  background: white;
  position: sticky;
  top: 0;
  z-index: 50;
}

.dark .app-header {
  background: #1e293b;
  border-color: #334155;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  background: white;
  padding: 0;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
}

.dark .sidebar {
  background: #1e293b;
}

.sidebar-section {
  border-bottom: 1px solid var(--color-border);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  user-select: none;
  transition: background-color 0.15s;
}

.section-header:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.dark .section-header:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.section-header .chevron {
  transition: transform 0.2s;
  font-size: 10px;
}

.section-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.section-content {
  padding: 0 16px 16px;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.section-content.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* === Main Area === */
.main-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  height: calc(100vh - var(--header-height));
}

/* === Phase Indicator === */
.phase-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 14px;
}

.phase-banner.phase-1 {
  background: rgba(59, 130, 246, 0.1);
  color: #1d4ed8;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.phase-banner.phase-2 {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.dark .phase-banner.phase-1 {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

.dark .phase-banner.phase-2 {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

/* === Stats Dashboard === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}

.stat-card .stat-label {
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.stat-card.alarm .stat-value {
  color: var(--color-alarm);
}

.stat-card.warning .stat-value {
  color: var(--color-warning);
}

/* === Chart Containers === */
.chart-container {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  position: relative;
}

.chart-container canvas {
  width: 100% !important;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Chart Scrollbar === */
.chart-scrollbar {
  margin-top: 6px;
  padding: 0 4px;
  user-select: none;
}

.chart-scrollbar-track {
  position: relative;
  height: 10px;
  background: #e2e8f0;
  border-radius: 5px;
  cursor: pointer;
}

.dark .chart-scrollbar-track {
  background: #334155;
}

.chart-scrollbar-thumb {
  position: absolute;
  top: 0;
  height: 100%;
  min-width: 30px;
  background: #94a3b8;
  border-radius: 5px;
  cursor: grab;
  transition: background 0.15s;
}

.chart-scrollbar-thumb:hover,
.chart-scrollbar-thumb.dragging {
  background: #64748b;
}

.dark .chart-scrollbar-thumb {
  background: #64748b;
}

.dark .chart-scrollbar-thumb:hover,
.dark .chart-scrollbar-thumb.dragging {
  background: #94a3b8;
}

/* === Alarm Log === */
.alarm-log-wrapper {
  max-height: 300px;
  overflow-y: auto;
  border-radius: 8px;
  border: 1px solid var(--color-border);
}

.alarm-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.alarm-log-table th {
  background: #f1f5f9;
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  position: sticky;
  top: 0;
  z-index: 1;
}

.alarm-log-table td {
  padding: 6px 10px;
  border-top: 1px solid var(--color-border);
}

.alarm-log-table tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

.alarm-log-table .status-alarm {
  color: #ef4444;
  font-weight: 600;
}

.alarm-log-table .status-warning {
  color: #f59e0b;
  font-weight: 600;
}

/* === Method Buttons === */
.method-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.method-btn {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: white;
  color: var(--color-text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.dark .method-btn {
  background: #0f172a;
  border-color: #475569;
  color: #e2e8f0;
}

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

.method-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.method-btn.locked {
  opacity: 0.6;
  cursor: not-allowed;
}

/* === Range Sliders === */
.slider-group {
  margin-bottom: 10px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.slider-label .slider-value {
  font-weight: 600;
  color: var(--color-text);
  min-width: 40px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #e2e8f0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.dark input[type="range"] {
  background: #475569;
}

/* === File Upload Drop Zone === */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--color-text-muted);
  font-size: 13px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--color-primary);
  background: rgba(30, 64, 175, 0.05);
  color: var(--color-primary);
}

.drop-zone input[type="file"] {
  display: none;
}

/* === Buttons === */
.btn-primary {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}

.btn-primary:hover {
  background: #1e3a8a;
}

.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: rgba(30, 64, 175, 0.08);
}

.btn-danger {
  background: #ef4444;
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: #10b981;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-success:hover {
  background: #059669;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
  width: auto;
}

/* === Inputs === */
.input-group {
  margin-bottom: 8px;
}

.input-group label {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 3px;
}

.input-group input,
.input-group select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 13px;
  box-sizing: border-box;
}

.input-group textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 12px;
  font-family: monospace;
  resize: vertical;
  min-height: 60px;
  box-sizing: border-box;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row .input-group {
  flex: 1;
}

/* === Data Preview === */
.data-preview {
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  margin-top: 8px;
}

.dark .data-preview {
  background: #0f172a;
}

.data-preview-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.data-preview-row .label {
  color: var(--color-text-muted);
}

.data-preview-row .value {
  font-weight: 600;
}

/* === Error List === */
.error-list {
  margin-top: 8px;
}

.error-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.15);
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 12px;
}

.error-item .remove-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}

/* === Locked State === */
.locked-overlay {
  position: relative;
}

.locked-overlay::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.5);
  pointer-events: all;
  border-radius: 6px;
}

.dark .locked-overlay::after {
  background: rgba(15, 23, 42, 0.5);
}

/* === Bottom Bar === */
.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: white;
  border-top: 1px solid var(--color-border);
  font-size: 13px;
}

.dark .bottom-bar {
  background: #1e293b;
  border-color: #334155;
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Column Mapping === */
.column-mapping {
  margin-top: 8px;
  padding: 8px;
  background: #f8fafc;
  border-radius: 6px;
}

.dark .column-mapping {
  background: #0f172a;
}

/* === Responsive === */
@media (max-width: 1024px) {
  .sidebar {
    width: 280px;
    min-width: 280px;
  }
}

@media (max-width: 768px) {
  .app-body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 40vh;
    position: relative;
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .main-area {
    height: auto;
  }

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

  .bottom-row {
    flex-direction: column;
  }
}

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

  .sidebar {
    max-height: 35vh;
  }
}

/* === Utility === */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.gap-2 { gap: 8px; }

/* AoN usage indicator */
.aon-usage {
  background: rgba(217, 119, 6, 0.1);
  border: 1px solid rgba(217, 119, 6, 0.2);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #92400e;
  margin-top: 8px;
}

.dark .aon-usage {
  color: #fbbf24;
  background: rgba(217, 119, 6, 0.15);
}

/* Phase transition animation */
.phase-transition {
  animation: phaseFlash 0.6s ease;
}

@keyframes phaseFlash {
  0% { opacity: 0.5; transform: scale(0.98); }
  50% { opacity: 1; transform: scale(1.01); }
  100% { opacity: 1; transform: scale(1); }
}

/* Comparison mode indicator */
.comparison-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
