:root {
  --bg: #0b0c0f;
  --fg: #e6e7ea;
  --muted: #a6adbb;
  --card: #14161a;
  --border: #2a2e36;
  --brand: #6aa6ff;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --accent: #8b5cf6;
  --gradient: linear-gradient(135deg, var(--brand), var(--accent));
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fff;
    --fg: #111418;
    --muted: #586174;
    --card: #f7f8fa;
    --border: #e5e7eb;
    --brand: #2563eb;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --accent: #7c3aed;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

/* Header & Navigation */
.header {
  padding: 24px 16px;
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.header h1 {
  font-size: 2rem;
  margin-bottom: 8px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lead {
  color: var(--muted);
  font-size: 1.1rem;
  margin-bottom: 24px;
}

/* Tabs Navigation */
.tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 25px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
}

.tab-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.tab-btn:hover:not(.active) {
  border-color: var(--brand);
  color: var(--fg);
}

/* Main Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* Tab Content */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin: 20px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.card h2 {
  margin: 0 0 20px 0;
  color: var(--fg);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Visual Enhancements */
.calculation-visual {
  margin: 16px 0;
  padding: 20px;
  background: linear-gradient(135deg, rgba(106, 166, 255, 0.05), rgba(139, 92, 246, 0.05));
  border-radius: 12px;
  border: 1px solid rgba(106, 166, 255, 0.2);
}

.dilution-diagram {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}

.solution-container {
  position: relative;
  width: 80px;
  height: 100px;
  border: 2px solid var(--border);
  border-radius: 8px 8px 12px 12px;
  background: linear-gradient(to bottom, transparent 20%, rgba(106, 166, 255, 0.1) 20%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
}

.solution-container.stock {
  background: linear-gradient(to bottom, transparent 40%, rgba(106, 166, 255, 0.3) 40%);
}

.solution-container.diluted {
  background: linear-gradient(to bottom, transparent 70%, rgba(106, 166, 255, 0.1) 70%);
}

.concentration-label {
  position: absolute;
  top: -24px;
  font-weight: 600;
  font-size: 12px;
  color: var(--brand);
}

.arrow {
  font-size: 24px;
  color: var(--brand);
  animation: pulse 2s infinite;
}

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

/* Form Elements */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--fg);
  font-weight: 500;
}

.input-group {
  display: flex;
  gap: 4px;
}

input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-size: 14px;
  transition: all 0.2s ease;
  flex: 1;
}

input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(106, 166, 255, 0.2);
}

select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  min-width: 60px;
}

/* Buttons */
.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
}

.btn.ghost {
  border-style: dashed;
  color: var(--muted);
}

.btn.ghost:hover {
  border-color: var(--brand);
  color: var(--fg);
}

.btn:hover {
  background: var(--border);
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.primary:hover {
  background: #5a96ff;
  box-shadow: 0 4px 12px rgba(106, 166, 255, 0.3);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.copy-btn {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn.solve-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.preset-btn {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
  width: 100%;
  margin-top: 8px;
}

.input-invalid,
.input-invalid:focus {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.3);
}

/* Results */
.result-box {
  margin-top: 16px;
  padding: 16px;
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(34, 197, 94, 0.05));
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 8px;
  color: var(--fg);
  font-weight: 600;
  font-size: 16px;
  min-height: 20px;
}

.result-box:empty {
  display: none;
}

.steps-container {
  margin-top: 12px;
  padding: 12px;
  background: rgba(106, 166, 255, 0.05);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  display: none;
}

.steps-container:not(:empty) {
  display: block;
}

/* Serial Dilution Results */
.serial-results {
  max-height: 400px;
  overflow-y: auto;
}

.serial-step {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 4px 0;
  background: rgba(106, 166, 255, 0.05);
  border-radius: 6px;
  font-size: 13px;
}

/* Presets */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.preset-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(106, 166, 255, 0.05), rgba(139, 92, 246, 0.05));
  text-align: center;
  transition: transform 0.2s ease;
}

.preset-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.preset-card h3 {
  margin: 0 0 8px 0;
  color: var(--fg);
  font-size: 16px;
}

.preset-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/* History */
.history-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.history-list {
  max-height: 400px;
  overflow-y: auto;
}

.history-item {
  padding: 12px;
  margin: 8px 0;
  background: rgba(106, 166, 255, 0.05);
  border-radius: 8px;
  border-left: 3px solid var(--brand);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.history-timestamp {
  color: var(--muted);
  font-size: 11px;
}

.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;
}

/* Notes */
.notes {
  margin-top: 32px;
  padding: 20px;
  background: rgba(106, 166, 255, 0.05);
  border-radius: 12px;
  border: 1px solid rgba(106, 166, 255, 0.2);
}

.notes ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.notes li {
  margin-bottom: 8px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 0 12px 32px;
  }

  .card {
    padding: 16px;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .row {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }

  .tabs {
    flex-direction: column;
    align-items: center;
  }

  .tab-btn {
    width: 100%;
    max-width: 200px;
  }

  .dilution-diagram {
    flex-direction: column;
    gap: 10px;
  }

  .solution-container {
    width: 60px;
    height: 80px;
  }

  .presets-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1.5rem;
  }

  .lead {
    font-size: 1rem;
  }

  .card h2 {
    font-size: 1.2rem;
  }

  input, select, .btn {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* Loading and Animation States */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.calculating {
  position: relative;
  overflow: hidden;
}

.calculating::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: loading 1s infinite;
}

@keyframes loading {
  to { left: 100%; }
}

/* Notification Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 16px;
  background: var(--success);
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  animation: slideIn 0.3s ease;
}

.toast.error {
  background: var(--danger);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
