/* ========== CSS Variables & Themes ========== */
:root {
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-elevated: #242836;
  --bg-hover: #2a2e3d;
  --border: #2e3347;
  --text: #e4e7f0;
  --text-secondary: #8b90a5;
  --text-muted: #5c6079;
  --primary: #6c5ce7;
  --primary-hover: #7d6ff0;
  --primary-bg: rgba(108,92,231,0.12);
  --danger: #ff6b6b;
  --danger-bg: rgba(255,107,107,0.12);
  --success: #51cf66;
  --success-bg: rgba(81,207,102,0.12);
  --warning: #ffd43b;
  --warning-bg: rgba(255,212,59,0.12);
  --chart-normal: #6c5ce7;
  --chart-anomaly: #ff6b6b;
  --chart-line: #4a4d5e;
  --scrollbar-track: #1a1d27;
  --scrollbar-thumb: #2e3347;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-surface: #ffffff;
  --bg-elevated: #f0f2f8;
  --bg-hover: #e8ebf3;
  --border: #dde1ed;
  --text: #1a1d2e;
  --text-secondary: #5c6079;
  --text-muted: #9499b3;
  --primary: #6c5ce7;
  --primary-hover: #5a48d5;
  --primary-bg: rgba(108,92,231,0.08);
  --danger: #e03131;
  --danger-bg: rgba(224,49,49,0.08);
  --success: #2f9e44;
  --success-bg: rgba(47,158,68,0.08);
  --warning: #e67700;
  --warning-bg: rgba(230,119,0,0.08);
  --chart-normal: #6c5ce7;
  --chart-anomaly: #e03131;
  --chart-line: #dde1ed;
  --scrollbar-track: #f0f2f8;
  --scrollbar-thumb: #c1c5d6;
}

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ========== Navbar ========== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav-icon {
  width: 24px;
  height: 24px;
  color: var(--primary);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

.btn-icon {
  background: transparent;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.sample-panel {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.sample-panel label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Theme toggle icons */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ========== Layout ========== */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 20px 24px;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 56px);
}

.panel-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* ========== Tabs ========== */
.tab-group {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 7px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.tab.active {
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

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

/* ========== Dropzone ========== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
}
.dropzone p { margin-top: 8px; font-weight: 500; font-size: 0.9rem; }
.dropzone-hint { font-size: 0.78rem; color: var(--text-muted); }

.file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-top: 10px;
  background: var(--success-bg);
  color: var(--success);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
}

/* ========== Form Elements ========== */
textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.82rem;
  resize: vertical;
  transition: border var(--transition);
  margin-bottom: 10px;
}
textarea:focus { outline: none; border-color: var(--primary); }

.select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b90a5' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.select:focus { outline: none; border-color: var(--primary); }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.param-value {
  color: var(--primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
  outline: none;
  appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ========== Method Info ========== */
.method-info {
  background: var(--primary-bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 14px;
}
.method-info p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

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

/* ========== Summary Grid ========== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.summary-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: all var(--transition);
}

.summary-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.summary-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.summary-method { font-size: 0.95rem; }

.anomaly-card {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.anomaly-card .summary-value { color: var(--danger); }

/* ========== Interpretation ========== */
.interpretation {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.5;
}
.interpretation.good { background: var(--success-bg); color: var(--success); }
.interpretation.warning { background: var(--warning-bg); color: var(--warning); }
.interpretation.danger { background: var(--danger-bg); color: var(--danger); }

/* ========== Chart ========== */
.chart-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}
.chart-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.chart-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.chart-tab:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

.chart-container {
  position: relative;
  height: 340px;
}

/* ========== Table ========== */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.table-header .card-title { margin-bottom: 0; }

.table-wrapper {
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

tr:last-child td { border-bottom: none; }

tr.anomaly-row {
  background: var(--danger-bg);
}
tr.anomaly-row td:nth-child(3) {
  color: var(--danger);
  font-weight: 600;
}

tr.normal-row td:nth-child(3) {
  color: var(--success);
}

.table-footer {
  padding-top: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
}

/* ========== Empty State ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  flex: 1;
}
.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.empty-state p { font-size: 0.88rem; max-width: 340px; }

/* ========== Toast ========== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  box-shadow: var(--shadow-lg);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
.toast.info { background: var(--primary); color: #fff; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .navbar { padding: 0 14px; }
}

@media (max-width: 500px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }
  .summary-value { font-size: 1.3rem; }
  .chart-container { height: 260px; }
}

/* ========== Param group transition ========== */
.param-group {
  transition: opacity var(--transition);
}

/* ========== Site footer ========== */
.site-footer {
  padding: 20px 24px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--transition);
}
.site-footer a:hover {
  color: var(--primary);
  text-decoration: underline;
}
