/* ═══════════════════════════════════════════════════
   PlotFunction — Design System & Styles
   ═══════════════════════════════════════════════════ */

/* ── CSS Custom Properties (Tokens) ── */
:root {
  /* Palette — dark theme */
  --bg-primary:    #0b0e17;
  --bg-secondary:  #111827;
  --bg-surface:    #1a1f35;
  --bg-glass:      rgba(26, 31, 53, 0.65);

  --text-primary:   #e8eaf0;
  --text-secondary: #8b93a8;
  --text-muted:     #5a6178;

  --accent:        #6c63ff;
  --accent-light:  #8b83ff;
  --accent-glow:   rgba(108, 99, 255, 0.35);
  --accent-2:      #00d4aa;
  --accent-3:      #ff6b9d;

  --success: #22c55e;
  --error:   #ef4444;
  --warning: #f59e0b;

  --border:        rgba(139, 147, 168, 0.12);
  --border-focus:  rgba(108, 99, 255, 0.5);

  /* Gradients */
  --grad-header: linear-gradient(135deg, #6c63ff 0%, #00d4aa 100%);
  --grad-btn:    linear-gradient(135deg, #6c63ff 0%, #8b83ff 100%);
  --grad-card:   linear-gradient(145deg, rgba(108,99,255,0.06) 0%, rgba(0,212,170,0.04) 100%);

  /* Spacing & radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.35);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.45);
  --shadow-glow: 0 0 30px var(--accent-glow);

  /* Fonts */
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;

  /* Transitions */
  --fast:   150ms ease;
  --medium: 300ms ease;
  --slow:   500ms ease;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Screen-reader only utility */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ═══════════════════════════════════════
   HEADER
   ═══════════════════════════════════════ */
#app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.logo-icon {
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--grad-header);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

.logo h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.logo .accent {
  background: var(--grad-header);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ═══════════════════════════════════════
   INPUT SECTION
   ═══════════════════════════════════════ */
#input-section {
  padding: 1.5rem 2rem 0.75rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.input-container {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.input-prefix {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--accent-light);
  white-space: nowrap;
  user-select: none;
}

#function-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 400;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--fast), box-shadow var(--fast);
}

#function-input::placeholder {
  color: var(--text-muted);
  font-weight: 300;
}

#function-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#plot-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.5rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  background: var(--grad-btn);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--fast), box-shadow var(--fast), filter var(--fast);
  box-shadow: var(--shadow-sm), 0 0 16px var(--accent-glow);
}

#plot-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), var(--shadow-glow);
  filter: brightness(1.1);
}

#plot-btn:active {
  transform: translateY(0) scale(0.97);
}

.btn-icon { font-size: 1.1rem; }

/* Error message */
.error-msg {
  font-size: 0.82rem;
  color: var(--error);
  margin-top: 0.5rem;
  min-height: 1.2em;
  font-weight: 500;
  transition: opacity var(--fast);
}

/* Presets */
.presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.presets-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-right: 0.25rem;
}

.preset {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--fast);
}

.preset:hover {
  border-color: var(--accent);
  color: var(--accent-light);
  background: rgba(108, 99, 255, 0.08);
}

/* ═══════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════ */
#main-content {
  flex: 1;
  padding: 1rem 2rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Functions bar */
#functions-bar {
  margin-bottom: 1rem;
}

.section-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

#functions-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.fn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);
  animation: chip-in 0.3s ease;
  cursor: pointer;
  transition: border-color var(--fast), background var(--fast);
}

.fn-chip:hover {
  border-color: var(--accent);
}

.fn-chip.active {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.1);
  box-shadow: 0 0 8px var(--accent-glow);
}

.fn-chip .color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.fn-chip .remove-fn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--fast);
  line-height: 1;
}

.fn-chip .remove-fn:hover {
  background: var(--error);
  color: #fff;
}

@keyframes chip-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.empty-state {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Grid layout */
.grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.25rem;
  align-items: start;
}

/* Panels */
.panel {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

/* Graph panel */
#graph-panel {
  min-height: 480px;
}

#plot-area {
  width: 100%;
  height: 520px;
}

/* Analysis panel */
#analysis-panel {
  padding: 1.25rem;
  max-height: 570px;
  overflow-y: auto;
}

/* Custom scrollbar */
#analysis-panel::-webkit-scrollbar { width: 5px; }
#analysis-panel::-webkit-scrollbar-track { background: transparent; }
#analysis-panel::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 4px;
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.analysis-placeholder {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 2rem 0;
}

/* Analysis sections */
.analysis-block {
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
  animation: fade-up 0.35s ease;
}

.analysis-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.analysis-block h3 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-light);
  margin-bottom: 0.35rem;
}

.analysis-block .value {
  font-size: 0.88rem;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 400;
  line-height: 1.55;
}

.analysis-block .value .math {
  color: var(--accent-2);
}

/* Function selector tabs in analysis */
.analysis-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.analysis-tab {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--fast);
}

.analysis-tab.active {
  border-color: var(--accent);
  background: rgba(108, 99, 255, 0.12);
  color: var(--accent-light);
}

/* ═══════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════ */
#app-footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */
@media (max-width: 900px) {
  .grid {
    grid-template-columns: 1fr;
  }

  #analysis-panel {
    max-height: none;
  }

  .header-content {
    flex-direction: column;
    gap: 0.25rem;
  }

  .tagline { text-align: center; }
}

@media (max-width: 600px) {
  #input-section, #main-content { padding-left: 1rem; padding-right: 1rem; }

  .input-row {
    flex-wrap: wrap;
  }

  #function-input { min-width: 0; }

  #plot-btn { width: 100%; justify-content: center; }

  #plot-area { height: 350px; }
}
