/* ============================================
   PILLES TRICORDER — Gesundheits-Dashboard
   Mobile-First PWA | Glassmorphism Dark Theme
   Designed by SANDY
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --bg: #0a0b14;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(99, 102, 241, 0.3);
  --text: #e8eaf0;
  --text-dim: #8b8fa3;
  --text-muted: #5a5e72;
  --accent: #6366f1;
  --accent-light: #818cf8;

  /* Health colors (1=best, 6=worst) */
  --health-1: #2d8a4e;
  --health-2: #6bc47f;
  --health-3: #f0c040;
  --health-4: #e88c30;
  --health-5: #d94040;
  --health-6: #8b0000;

  /* Specific slider themes */
  --pain-good: #2d8a4e;
  --pain-bad: #d94040;
  --sleep-good: #1e3a5f;
  --sleep-bad: #7cb3e0;
  --mood-good: #2d8a4e;
  --mood-bad: #8b0000;

  --schub: #7b2d8b;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 100px;
}

/* ===== HEADER ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-icon {
  width: 28px; height: 28px;
  color: var(--accent-light);
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-date {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

/* ===== GREETING ===== */
.greeting {
  padding: 16px 0 20px;
}

.greeting-text {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
}

.greeting-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

/* ===== SLIDER SYSTEM ===== */
.slider-group {
  margin-bottom: 20px;
}

.slider-group:last-child { margin-bottom: 0; }

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

.slider-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.slider-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  min-width: 90px;
  text-align: right;
}

.slider-track {
  position: relative;
  height: 44px;
  cursor: pointer;
  touch-action: none;
}

.slider-segments {
  display: flex;
  gap: 4px;
  height: 100%;
}

.slider-seg {
  flex: 1;
  border-radius: 8px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.slider-seg:hover {
  transform: scaleY(1.05);
}

.slider-seg.active {
  color: white;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transform: scaleY(1.08);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.slider-seg.filled {
  opacity: 1;
}

.slider-seg.empty {
  opacity: 0.15;
}

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

/* ===== EXPAND BUTTON ===== */
.expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

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

.expand-btn.expanded .expand-chevron {
  transform: rotate(180deg);
}

.expand-chevron {
  transition: transform 0.2s;
}

.optional-sliders {
  display: none;
  margin-top: 16px;
}

.optional-sliders.visible {
  display: block;
}

/* ===== TOGGLE BUTTONS ===== */
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.toggle-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.7rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
}

.toggle-btn:active { transform: scale(0.96); }

.toggle-btn.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: var(--border-accent);
  color: var(--text);
}

.toggle-icon {
  width: 28px; height: 28px;
  color: var(--text-dim);
}

.toggle-btn.active .toggle-icon {
  color: var(--accent-light);
}

.toggle-text {
  font-size: 0.68rem;
  line-height: 1.2;
  text-align: center;
}

/* ===== NOTE ===== */
.note-section { padding: 12px; }

.note-input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  min-height: 44px;
  transition: border-color 0.2s;
}

.note-input:focus {
  border-color: var(--border-accent);
}

.note-input::placeholder {
  color: var(--text-muted);
}

/* ===== SAVE BUTTON ===== */
.save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none;
  border-radius: var(--radius);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

.save-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}

.save-btn:active {
  transform: translateY(0);
}

.save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.save-btn.saved {
  background: linear-gradient(135deg, var(--health-1), var(--health-2));
}

.save-icon {
  width: 22px; height: 22px;
  color: white;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  border-radius: 99px;
  background: rgba(18, 19, 26, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 100;
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== VITALS ===== */
.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.vitals {
  margin-bottom: 12px;
}

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

.vital-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.vital-icon {
  width: 28px; height: 28px;
  color: var(--accent-light);
}

.vital-value {
  font-size: 1rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.vital-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ===== SLEEP ===== */
.sleep-bar {
  display: flex;
  height: 24px;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.sleep-phase {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  min-width: 20px;
}

.sleep-deep { background: #1e3a5f; }
.sleep-light { background: #2d5f8a; }
.sleep-rem { background: #7b2d8b; }
.sleep-awake { background: rgba(255, 255, 255, 0.1); }

.sleep-stats {
  display: flex;
  gap: 12px;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.sleep-stat { font-family: 'JetBrains Mono', monospace; }
.sleep-stat b { color: var(--text); font-weight: 600; }

/* ===== SPARKLINES ===== */
.sparklines { padding: 14px 16px; }

.spark-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.spark-row:last-child { margin-bottom: 0; }

.spark-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  width: 70px;
  flex-shrink: 0;
}

.spark-canvas {
  flex: 1;
  height: 32px;
}

/* ===== PILLES KOMMENTAR ===== */
.pille-card {
  border-color: rgba(99, 102, 241, 0.2);
  background: rgba(99, 102, 241, 0.04);
}

.pille-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.pille-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-light);
}

.pille-text {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-dim);
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: rgba(16, 17, 28, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(99, 102, 241, 0.15);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  z-index: 50;
  max-width: 100%;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 20px;
  background: transparent;
  border: none;
  color: #8b8fa3;
  font-size: 0.65rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 10px;
}

.nav-btn:hover { color: #c0c4d0; }

.nav-btn.active {
  color: var(--accent-light);
  background: rgba(99, 102, 241, 0.12);
}

.nav-icon {
  width: 24px; height: 24px;
  color: currentColor;
}

.pille-icon {
  width: 20px; height: 20px;
  color: var(--accent-light);
}

/* ===== LOADING TEXT ===== */
.loading-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 20px;
}

/* ===== WEEK VIEW ===== */
.week-table { margin-bottom: 12px; }

.week-header, .week-row {
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.week-header {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 4px;
}

.week-row {
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.week-col-label {
  flex: 1.2;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.week-col {
  flex: 1;
  text-align: center;
  font-size: 0.78rem;
}

.health-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
}

.dot-empty {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.week-averages {
  display: flex;
  gap: 12px;
  font-size: 0.72rem;
  color: var(--text-dim);
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.week-averages b { color: var(--text); }

.week-notes { margin-top: 8px; }

.week-note {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  line-height: 1.5;
}

.week-note-date {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--accent-light);
  margin-right: 6px;
}

/* ===== MONTH HEATMAP ===== */
.heatmap-grid { margin-bottom: 12px; }

.heatmap-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}

.heatmap-header span {
  text-align: center;
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.heatmap-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.heatmap-day {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  position: relative;
  transition: transform 0.1s;
}

.heatmap-day:active { transform: scale(0.92); }
.heatmap-day.empty { opacity: 0; pointer-events: none; }

.heatmap-day.today {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.heatmap-num {
  font-weight: 600;
  font-size: 0.72rem;
}

.heatmap-val {
  font-size: 0.55rem;
  font-weight: 700;
  opacity: 0.8;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 8px;
}

.legend-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin: 0 4px;
}

.legend-dot {
  width: 18px; height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: white;
}

/* ===== LABOR ===== */
.labor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.labor-item {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border-left: 3px solid var(--text-muted);
}

.labor-item.lab-ok { border-left-color: var(--health-1); }
.labor-item.lab-warn { border-left-color: var(--health-4); }
.labor-item.lab-alert { border-left-color: var(--health-5); }

.labor-name {
  display: block;
  font-size: 0.68rem;
  color: var(--text-dim);
}

.labor-val {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  margin: 2px 0;
}

.labor-ref {
  display: block;
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* ===== MEDIKATION ===== */
.med-list { display: flex; flex-direction: column; gap: 4px; }

.med-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.med-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 500;
}

.med-dose {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-light);
}

.med-schema {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ===== DIAGNOSEN ===== */
.diagnose-list { display: flex; flex-direction: column; gap: 4px; }

.diagnose-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.diagnose-name {
  font-size: 0.82rem;
}

.diagnose-icd {
  font-size: 0.65rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-light);
  padding: 2px 6px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 4px;
}

/* ===== TREND VIEW ===== */
.trend-month {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 0.78rem;
}

.trend-month-label {
  width: 60px;
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.72rem;
}

.trend-month b {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
}

.trend-count {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ===== INSTALL BANNER ===== */
.install-banner {
  position: fixed;
  bottom: 64px;
  left: 16px; right: 16px;
  max-width: 448px;
  margin: 0 auto;
  display: none;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(18, 19, 30, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 20px rgba(99, 102, 241, 0.1);
  z-index: 60;
  animation: slideUp 0.3s ease;
}

.install-banner.visible { display: flex; }

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

.install-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.install-icon {
  width: 32px; height: 32px;
  color: var(--accent-light);
  flex-shrink: 0;
}

.install-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.install-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
}

.install-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.install-btn:hover {
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.install-dismiss {
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.install-dismiss:hover { color: var(--text-dim); }

/* Hide install banner in standalone mode */
@media (display-mode: standalone) {
  .install-banner { display: none !important; }
}

/* ===== STANDALONE PWA TWEAKS ===== */
@media (display-mode: standalone) {
  .header {
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  }

  .bottom-nav {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.card, .vitals, .greeting {
  animation: fadeInUp 0.3s ease backwards;
}

.quick-entry { animation-delay: 0.05s; }
.toggles { animation-delay: 0.1s; }
.note-section { animation-delay: 0.15s; }
.save-btn { animation-delay: 0.2s; }
.vitals { animation-delay: 0.25s; }
.sparklines { animation-delay: 0.3s; }

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
  #app { padding: 0 24px 100px; }
  .vitals-grid { gap: 12px; }
}

@media (max-width: 350px) {
  .toggle-grid { grid-template-columns: repeat(2, 1fr); }
  .vitals-grid { grid-template-columns: repeat(2, 1fr); }
}
