/* ============================================
   Global box-sizing
   ============================================ */
.caffeine-calculator-container,
.caffeine-calculator-container *,
.caffeine-calculator-container *::before,
.caffeine-calculator-container *::after {
  box-sizing: border-box;
}

/* ============================================
   Light Mode (Default)
   ============================================ */
.caffeine-calculator-container {
  /* Background colors */
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --bg-section: #fff;

  /* Borders */
  --border-color: #333;

  /* Text colors */
  --text-primary: #222;
  --text-secondary: #555;
  --text-light: #666;

  /* Brand colors */
  --color-accent: #3498db;
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;
  --color-purple: #9b59b6;
  --color-teal: #1abc9c;

  /* Shadows (neobrutalism) */
  --shadow-sm: 2px 2px 0 rgba(0,0,0,0.1);
  --shadow-md: 4px 4px 0 rgba(0,0,0,0.15);
  --shadow-lg: 8px 8px 0 rgba(0,0,0,0.15);

  /* Border radius */
  --radius-container: 8px;
  --radius-section: 6px;
  --radius-button: 4px;
  --radius-input: 4px;

  /* Input focus */
  --input-focus-bg: #fffacd;

  /* Header title */
  --title-color: #2c3e50;
  --title-shadow: 2px 2px 0 rgba(255,255,255,0.5);
}

/* ============================================
   Dark Mode (Manual toggle)
   ============================================ */
.caffeine-calculator-container.dark {
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-section: #2d2d2d;

  --border-color: #e0e0e0;

  --text-primary: #e8e8e8;
  --text-secondary: #b0b0b0;
  --text-light: #909090;

  --color-accent: #5dade2;
  --color-success: #52c77a;
  --color-warning: #f5b041;
  --color-danger: #ec7063;
  --color-purple: #af7ac5;
  --color-teal: #48d1cc;

  --shadow-sm: 2px 2px 0 rgba(255,255,255,0.08);
  --shadow-md: 4px 4px 0 rgba(255,255,255,0.12);
  --shadow-lg: 8px 8px 0 rgba(255,255,255,0.12);

  --input-focus-bg: #3a3a3a;

  --title-color: #7fb3d5;
  --title-shadow: 2px 2px 0 rgba(0,0,0,0.5);
}

/* ============================================
   System dark mode auto detection
   ============================================ */
@media (prefers-color-scheme: dark) {
  .caffeine-calculator-container:not(.dark):not(.light) {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-section: #2d2d2d;

    --border-color: #e0e0e0;

    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-light: #909090;

    --color-accent: #5dade2;
    --color-success: #52c77a;
    --color-warning: #f5b041;
    --color-danger: #ec7063;
    --color-purple: #af7ac5;
    --color-teal: #48d1cc;

    --shadow-sm: 2px 2px 0 rgba(255,255,255,0.08);
    --shadow-md: 4px 4px 0 rgba(255,255,255,0.12);
    --shadow-lg: 8px 8px 0 rgba(255,255,255,0.12);

    --input-focus-bg: #3a3a3a;

    --title-color: #7fb3d5;
    --title-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  }
}

/* ============================================
   Main Container
   ============================================ */
.caffeine-calculator-container {
  position: relative;
  max-width: 960px;
  width: 100%;
  margin: 8px auto;
  padding: 10px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-container);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  line-height: 1.5;
}

/* ============================================
   Dark Mode Toggle Button
   ============================================ */
.dark-mode-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  font-size: 17px;
  z-index: 10;
}

.dark-mode-toggle:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.15);
}

.dark-mode-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ============================================
   Header
   ============================================ */
.calculator-header {
  text-align: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border-color);
}

.calculator-header h2 {
  margin: 0 0 4px 0;
  font-size: 28px;
  font-weight: 700;
  color: var(--title-color);
  text-shadow: var(--title-shadow);
}

.subtitle {
  margin: 0;
  font-size: 15px;
  color: var(--text-light);
}

/* ============================================
   Quick Presets
   ============================================ */
.quick-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.preset-btn,
.btn-reset-all {
  padding: 7px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.preset-btn:hover,
.btn-reset-all:hover {
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.15);
  background: var(--input-focus-bg);
}

.preset-btn:active,
.btn-reset-all:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

.btn-reset-all {
  background: var(--color-warning);
  color: #fff;
}

/* ============================================
   Main Grid (2-column layout)
   ============================================ */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

/* ============================================
   Sections
   ============================================ */
.input-section,
.result-section {
  background: var(--bg-section);
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  box-shadow: var(--shadow-md);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.section-header.sub {
  font-size: 16px;
  margin-top: 8px;
}

.section-header.inline-header {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.section-header svg {
  stroke: var(--color-accent);
  flex-shrink: 0;
}

.section-divider {
  height: 1px;
  background: var(--border-color);
  margin: 10px 0;
  opacity: 0.3;
}

/* ============================================
   Input Groups and Rows
   ============================================ */
.input-row {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.input-row.two-col {
  grid-template-columns: 1fr 1fr;
}

.input-row.three-col {
  grid-template-columns: 1fr 1fr 1fr;
}

.input-row.four-col {
  grid-template-columns: 1fr 1fr 1fr 0.7fr;
}

.input-group {
  display: flex;
  flex-direction: column;
}

.input-group label {
  margin-bottom: 3px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-group input,
.input-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.input-group input:focus,
.input-group select:focus {
  outline: none;
  border-color: var(--color-accent);
  background: var(--input-focus-bg);
}

.input-group input[type="number"] {
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.input-group input:disabled,
.input-group select:disabled {
  background: var(--bg-primary);
  color: var(--text-light);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Amount wrapper */
.amount-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.amount-wrapper input {
  flex: 1;
  min-width: 0;
}

.amount-wrapper .unit {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ============================================
   Recommended Box
   ============================================ */
.recommended-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  background: var(--input-focus-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  margin-bottom: 4px;
}

.recommended-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.recommended-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-warning);
  font-family: 'Courier New', monospace;
}

.recommended-note {
  font-size: 13px;
  color: var(--text-light);
  width: 100%;
}

/* ============================================
   Add Row (Preview + Button)
   ============================================ */
.add-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.caffeine-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  flex-shrink: 0;
}

.preview-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.preview-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-warning);
  font-family: 'Courier New', monospace;
}

.add-btn {
  flex: 1;
  padding: 12px;
  background: var(--color-success);
  color: #fff;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
}

.add-btn:hover {
  filter: brightness(1.05);
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
}

.add-btn:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

/* ============================================
   Result Section
   ============================================ */
.result-top-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.total-card {
  text-align: center;
  padding: 12px 20px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
}

.total-label {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.total-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--color-accent);
  font-family: 'Courier New', monospace;
}

.progress-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
}

.progress-bar {
  height: 22px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-success);
  transition: width 0.3s, background-color 0.3s;
  border-radius: var(--radius-input);
}

.progress-fill.warning {
  background: var(--color-warning);
}

.progress-fill.danger {
  background: var(--color-danger);
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
}

.progress-percent {
  color: var(--color-accent);
  font-family: 'Courier New', monospace;
}

.progress-status {
  color: var(--color-success);
}

.progress-status.warning {
  color: var(--color-warning);
}

.progress-status.danger {
  color: var(--color-danger);
}

/* ============================================
   Status Message
   ============================================ */
.status-message {
  padding: 10px;
  background: rgba(39, 174, 96, 0.1);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-input);
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-success);
  margin-bottom: 10px;
}

.status-message.warning {
  background: rgba(243, 156, 18, 0.1);
  border-color: var(--color-warning);
  color: var(--color-warning);
}

.status-message.danger {
  background: rgba(231, 76, 60, 0.1);
  border-color: var(--color-danger);
  color: var(--color-danger);
}

/* ============================================
   Half-life Card
   ============================================ */
.halflife-card {
  padding: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  margin-bottom: 10px;
}

.halflife-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.halflife-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.halflife-item {
  text-align: center;
  padding: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
}

.hl-label {
  display: block;
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 2px;
}

.hl-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-warning);
  font-family: 'Courier New', monospace;
}

/* ============================================
   Button Group
   ============================================ */
.button-group {
  display: flex;
  gap: 8px;
}

.save-btn,
.load-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
  color: #fff;
}

.save-btn {
  background: var(--color-accent);
}

.load-btn {
  background: var(--color-purple);
}

.save-btn:hover,
.load-btn:hover {
  filter: brightness(1.05);
  transform: translate(0.5px, 0.5px);
  box-shadow: 1.5px 1.5px 0 rgba(0,0,0,0.15);
}

.save-btn:active,
.load-btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ============================================
   Intake Section - Compact
   ============================================ */
.intake-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-md);
}

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

.intake-header .section-header {
  gap: 8px;
}

.intake-count {
  padding: 3px 10px;
  background: var(--color-warning);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-button);
  margin-left: 8px;
}

.intake-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
}

.empty-message {
  width: 100%;
  text-align: center;
  color: var(--text-light);
  padding: 10px;
  font-size: 14px;
}

.intake-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 14px;
}

.intake-name {
  font-weight: 600;
  color: var(--text-primary);
}

.intake-caffeine {
  font-weight: 700;
  color: var(--color-warning);
  font-family: 'Courier New', monospace;
}

.btn-delete {
  padding: 2px 6px;
  background: var(--color-danger);
  border: none;
  border-radius: 3px;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-delete:hover {
  filter: brightness(1.1);
}

.clear-all-btn {
  padding: 6px 12px;
  background: #95a5a6;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}

.clear-all-btn:hover {
  background: #7f8c8d;
  transform: translate(0.5px, 0.5px);
}

.clear-all-btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ============================================
   Compact Info Sections
   ============================================ */
.info-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-section);
  padding: 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-md);
}

.compact-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.compact-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.compact-header svg {
  stroke: var(--color-accent);
  flex-shrink: 0;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
}

.chip strong {
  color: var(--color-accent);
}

/* ============================================
   Guide Section - Compact Multi-column
   ============================================ */
.guide-section {
  padding: 10px;
}

.guide-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.guide-tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 5px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--color-accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.tab-btn:not(.active):hover {
  background: var(--bg-secondary);
}

.guide-content {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  max-height: 200px;
  overflow-y: auto;
}

.guide-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-input);
  gap: 8px;
}

.guide-name {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.guide-caffeine {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-warning);
  font-family: 'Courier New', monospace;
  white-space: nowrap;
}

/* ============================================
   Footer Note
   ============================================ */
.footer-note {
  padding: 10px;
  background: var(--bg-primary);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-input);
  text-align: center;
  font-size: 13px;
  color: var(--text-light);
}

/* ============================================
   Toast Notification
   ============================================ */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-button);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 1000;
  max-width: 300px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast svg {
  stroke: var(--color-success);
  flex-shrink: 0;
}

.toast-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toast-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.toast-value {
  font-size: 14px;
  color: var(--text-secondary);
  font-family: 'Courier New', monospace;
}

/* ============================================
   Responsive - Tablet (768px or less)
   ============================================ */
@media (max-width: 768px) {
  .caffeine-calculator-container {
    margin: 6px 5px;
    padding: 8px;
    width: calc(100% - 10px);
  }

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

  .calculator-header h2 {
    font-size: 24px;
  }

  .input-row.three-col,
  .input-row.four-col {
    grid-template-columns: 1fr 1fr;
  }

  .result-top-row {
    grid-template-columns: 1fr;
  }

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

  .compact-section {
    flex-direction: column;
    align-items: flex-start;
  }

  .dark-mode-toggle {
    font-size: 15px;
    padding: 5px 8px;
  }
}

/* ============================================
   Responsive - Mobile (480px or less)
   ============================================ */
@media (max-width: 480px) {
  .caffeine-calculator-container {
    padding: 6px;
    border-width: 1px;
  }

  .input-section,
  .result-section,
  .info-section,
  .intake-section {
    padding: 8px;
  }

  .calculator-header h2 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 13px;
  }

  .quick-presets {
    flex-direction: column;
  }

  .preset-btn,
  .btn-reset-all {
    width: 100%;
  }

  .input-row.three-col,
  .input-row.four-col {
    grid-template-columns: 1fr;
  }

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

  .guide-content {
    grid-template-columns: 1fr;
  }

  .guide-header-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .guide-tabs {
    width: 100%;
  }

  .tab-btn {
    flex: 1;
    text-align: center;
  }

  .total-value {
    font-size: 28px;
  }

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

  .toast {
    right: 10px;
    left: 10px;
    max-width: none;
  }
}