/* KiddieMed - Modern Dark/Light & Night Mode Styling System */

:root {
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Color Palette - Dark Default */
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-header: rgba(15, 23, 42, 0.85);
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #38bdf8;
  --primary-hover: #0284c7;
  --primary-glow: rgba(56, 189, 248, 0.15);
  
  --fever-color: #f97316;
  --fever-high: #ef4444;
  --fever-mild: #eab308;
  --fever-normal: #10b981;
  --fever-glow: rgba(249, 115, 22, 0.2);
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
}

/* Light Theme Mode */
[data-theme="light"] {
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-header: rgba(255, 255, 255, 0.9);
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(2, 132, 199, 0.1);
  
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* 3 AM Ultra-Night Red-Tint Mode */
[data-theme="night"] {
  --bg-main: #050203;
  --bg-card: #18090b;
  --bg-card-hover: #260e12;
  --bg-header: rgba(5, 2, 3, 0.95);
  --border-color: #3b1419;
  --text-main: #fecdd3;
  --text-muted: #9f1239;
  --text-dim: #881337;
  --primary: #fb7185;
  --fever-color: #f43f5e;
  --fever-high: #e11d48;
}

html, body {
  overflow-x: hidden;
  width: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  vertical-align: middle;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  width: 100%;
  max-width: 680px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-main);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow-x: hidden;
}

/* HEADER */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 1.8rem;
  background: var(--primary-glow);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-badge-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-badge-btn:hover {
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

/* CHILD CHIP SELECTOR */
.child-selector-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.child-selector-container::-webkit-scrollbar {
  display: none;
}

.child-chips {
  display: flex;
  gap: 8px;
}

.child-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.child-chip:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.child-chip.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.child-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* QUICK ACTION FLOATING BAR */
.quick-action-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 16px 8px 16px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-fever {
  background: linear-gradient(135deg, #f97316, #ef4444);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--fever-glow);
}

.btn-fever:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

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

.btn-outline:hover {
  background: var(--bg-card-hover);
}

.btn-outline-fever {
  background: transparent;
  border: 1px solid var(--fever-color);
  color: var(--fever-color);
}

.btn-outline-fever:hover {
  background: var(--fever-glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 4px 8px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

/* TAB NAVIGATION */
.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  background: var(--bg-card);
  margin-top: 8px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 6px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  padding: 16px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.25s ease-in-out;
}

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

/* CARDS */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 14px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

/* SAFETY TIMERS */
.safety-card {
  background: linear-gradient(180deg, var(--bg-card), rgba(30, 41, 59, 0.95));
  border-color: var(--border-color);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: var(--fever-color);
  border-radius: 50%;
  box-shadow: 0 0 0 rgba(249, 115, 22, 0.4);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.7); }
  70% { box-shadow: 0 0 0 8px rgba(249, 115, 22, 0); }
  100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0); }
}

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

.timer-box {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.timer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.timer-med-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.timer-display {
  font-size: 1.4rem;
  font-weight: 800;
  font-family: monospace;
  letter-spacing: -0.03em;
  color: var(--primary);
  margin: 4px 0;
}

.timer-box.waiting .timer-display {
  color: var(--fever-high);
}

.timer-box.ready .timer-display {
  color: var(--fever-normal);
}

.timer-subtext {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-height: 28px;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-pill {
  border-radius: var(--radius-full);
}

.badge-info { background: var(--primary-glow); color: var(--primary); }
.badge-ready { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.badge-waiting { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

.badge-temp-normal { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.badge-temp-mild { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.badge-temp-high { background: rgba(249, 115, 22, 0.2); color: #f97316; }
.badge-temp-vhigh { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

.temp-status-card {
  background: var(--bg-card);
}

.temp-status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.temp-val-display {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.temp-badge-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.time-ago {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* LIST ITEMS (Rx & HISTORY) */
.rx-item, .log-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border-color);
}

.rx-item:last-child, .log-item:last-child {
  border-bottom: none;
}

.rx-title, .log-title {
  font-weight: 700;
  font-size: 0.9rem;
}

.rx-meta, .log-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.rx-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.progress-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--bg-main);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
}

.range-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.range-btn {
  height: 28px;
  min-width: 44px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.2s ease;
  white-space: nowrap;
  width: auto !important;
}

.range-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.range-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px var(--primary-glow);
}



.chart-container {
  margin: 12px 0;
}

.chart-wrapper {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  position: relative;
}

#fever-chart-svg {
  width: 100%;
  height: 220px;
  overflow: visible;
}

.chart-legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.temp-dot { background: var(--fever-color); }
.para-dot { background: #38bdf8; }
.ibu-dot { background: #a855f7; }
.rx-dot { background: #10b981; }

.chart-insights {
  margin-top: 14px;
  padding: 12px;
  background: var(--primary-glow);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

/* MODAL STYLES */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

/* FORMS */
.form-group {
  margin-bottom: 14px;
}

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

.form-control, .form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s ease;
}

.form-control:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-control-lg {
  font-size: 1.1rem;
  padding: 12px 16px;
  font-weight: 700;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .col {
  flex: 1;
}

.temp-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.temp-unit-badge {
  position: absolute;
  right: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
}

.quick-temp-pills {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.pill-btn {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

.subform {
  background: var(--bg-main);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.hidden { display: none !important; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 14px;
}

.alert-warning {
  background: rgba(249, 115, 22, 0.15);
  border: 1px solid var(--fever-color);
  color: var(--fever-color);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* FOOTER */
.app-footer {
  border-top: 1px solid var(--border-color);
  padding: 16px;
  text-align: center;
  background: var(--bg-card);
  margin-top: auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.danger-text {
  color: var(--fever-high) !important;
}

.footer-copy {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ==========================================================================
   MOBILE RESPONSIVE MEDIA QUERIES (Mobile-First Optimization)
   ========================================================================== */

@media (max-width: 520px) {
  .app-header {
    padding: 10px 12px;
  }

  .brand-title {
    font-size: 1.1rem;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
    font-size: 1.4rem;
  }

  .icon-badge-btn {
    width: 34px;
    height: 34px;
    font-size: 0.8rem;
  }

  .quick-action-bar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px 12px 4px 12px;
  }

  .btn {
    width: 100%;
    padding: 10px 14px;
  }

  .tab-nav {
    padding: 0 4px;
  }

  .tab-btn {
    padding: 10px 4px;
    font-size: 0.75rem;
    gap: 3px;
  }

  .main-content {
    padding: 12px;
  }

  .card {
    padding: 12px;
    margin-bottom: 12px;
    border-radius: var(--radius-md);
  }

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

  .timer-display {
    font-size: 1.3rem;
  }

  .temp-status-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .temp-badge-container {
    align-items: flex-start;
  }

  .form-row {
    flex-direction: column;
    gap: 8px;
  }

  .rx-item, .log-item {
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-start;
  }

  .rx-item button, .log-item button {
    align-self: flex-start;
    margin-left: 0 !important;
  }

  .chart-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #fever-chart-svg {
    min-width: 480px;
  }

  .modal-content {
    padding: 14px;
  }
}

@media (max-width: 380px) {
  .brand-subtitle {
    display: none;
  }

  .tab-icon {
    display: none;
  }

  .tab-btn {
    font-size: 0.7rem;
    padding: 8px 2px;
  }
}

