/* ============================================================
   MediTakt – Medikamenten-Erinnerung & Einnahme-Tracker
   Design-Tokens: Petrol/Teal + warmes Amber, mobile-first
   ============================================================ */

:root {
  --c-primary: #0f766e;
  --c-primary-strong: #115e59;
  --c-primary-soft: #ccfbf1;
  --c-accent: #b45309;
  --c-accent-soft: #fef3c7;
  --c-danger: #b91c1c;
  --c-danger-soft: #fee2e2;
  --c-success: #15803d;
  --c-success-soft: #dcfce7;

  --c-bg: #f6faf9;
  --c-surface: #ffffff;
  --c-surface-2: #eef5f4;
  --c-text: #1c2b2a;
  --c-text-muted: #5b6f6d;
  --c-border: #d8e4e2;
  --c-shadow: 0 2px 10px rgba(17, 60, 56, 0.08);

  --hm-0: #e4edeb;
  --hm-1: #b7e2d8;
  --hm-2: #7fccbb;
  --hm-3: #34a38e;
  --hm-4: #0f766e;

  --radius: 14px;
  --radius-small: 9px;
  --font-body: "Manrope", "Segoe UI", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-primary: #2dd4bf;
    --c-primary-strong: #5eead4;
    --c-primary-soft: #134e4a;
    --c-accent: #fbbf24;
    --c-accent-soft: #452c07;
    --c-danger: #f87171;
    --c-danger-soft: #4a1414;
    --c-success: #4ade80;
    --c-success-soft: #123a1e;

    --c-bg: #0d1716;
    --c-surface: #16221f;
    --c-surface-2: #1d2c29;
    --c-text: #e6f0ee;
    --c-text-muted: #93a8a4;
    --c-border: #2b3d39;
    --c-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);

    --hm-0: #1d2c29;
    --hm-1: #14524a;
    --hm-2: #0f766e;
    --hm-3: #2dd4bf;
    --hm-4: #99f6e4;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: var(--font-display);
  line-height: 1.2;
  margin: 0 0 0.35rem;
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }

p { margin: 0 0 0.6rem; }

button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- Header ---------- */

.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem 0.4rem;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--c-text);
}
.brand-icon { width: 32px; height: 32px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  max-width: 920px;
  margin: 0 auto;
  padding: 0 0.6rem;
  overflow-x: auto;
}

.tab {
  border: none;
  background: none;
  color: var(--c-text-muted);
  font-weight: 600;
  padding: 0.55rem 0.8rem;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--c-text); }
.tab.is-active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}

/* ---------- Layout ---------- */

.app-main {
  flex: 1;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 1rem 1rem 2.5rem;
}

.view { display: none; }
.view.is-active { display: block; }

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.view-sub { color: var(--c-text-muted); margin: 0; font-size: 0.92rem; }
.section-title { margin-top: 1.5rem; }

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--c-primary-soft);
  color: var(--c-text);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  margin-bottom: 1.1rem;
  font-size: 0.9rem;
}
.privacy-note svg { width: 22px; height: 22px; flex: 0 0 auto; color: var(--c-primary); margin-top: 2px; }
.privacy-note p { margin: 0; }

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  padding: 0.55rem 1rem;
  font-weight: 700;
  transition: filter 120ms ease, background 120ms ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--c-primary); color: var(--c-bg); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-primary);
  border-color: var(--c-primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--c-primary-soft); }

.btn-ghost {
  background: transparent;
  color: var(--c-text-muted);
  border-color: var(--c-border);
}
.btn-ghost:hover:not(:disabled) { background: var(--c-surface-2); color: var(--c-text); }

.btn-warning { background: var(--c-accent); color: #fff; }
.btn-warning:hover:not(:disabled) { filter: brightness(1.08); }

.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.linklike {
  background: none;
  border: none;
  color: var(--c-primary);
  text-decoration: underline;
  padding: 0.2rem 0.3rem;
}

/* ---------- Karten / Heute ---------- */

.notify-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  flex-wrap: wrap;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--c-shadow);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}
.notify-text { flex: 1 1 260px; }
.notify-text p { margin: 0; font-size: 0.92rem; }
.notify-hint { color: var(--c-text-muted); font-size: 0.8rem; margin-top: 0.3rem; }
.notify-card.is-granted { border-color: var(--c-success); }
.notify-card.is-denied { border-color: var(--c-danger); }

.stock-warnings { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.stock-warning {
  background: var(--c-accent-soft);
  color: var(--c-text);
  border-left: 4px solid var(--c-accent);
  border-radius: var(--radius-small);
  padding: 0.6rem 0.85rem;
  font-size: 0.92rem;
}
.stock-warning strong { color: var(--c-accent); }
.stock-warning.is-empty { background: var(--c-danger-soft); border-left-color: var(--c-danger); }
.stock-warning.is-empty strong { color: var(--c-danger); }

.today-summary {
  color: var(--c-text-muted);
  font-size: 0.92rem;
  margin-bottom: 0.7rem;
}

.today-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.intake {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 5px solid var(--med-color, var(--c-primary));
  border-radius: var(--radius);
  box-shadow: var(--c-shadow);
  padding: 0.7rem 0.9rem;
}

.intake-time {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 3.2rem;
}

.intake-info { flex: 1; min-width: 0; }
.intake-name { font-weight: 700; }
.intake-dose { color: var(--c-text-muted); font-size: 0.88rem; }
.intake-note {
  display: inline-block;
  background: var(--c-surface-2);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.78rem;
  color: var(--c-text-muted);
  margin-top: 0.2rem;
}
.intake-status { font-size: 0.8rem; margin-top: 0.2rem; }
.intake-status.taken { color: var(--c-success); font-weight: 600; }
.intake-status.skipped { color: var(--c-accent); font-weight: 600; }

.intake-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

.intake.is-overdue { border-color: var(--c-danger); background: var(--c-danger-soft); }
.intake.is-overdue .intake-time { color: var(--c-danger); }
.overdue-badge {
  display: inline-block;
  background: var(--c-danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.05rem 0.5rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

.intake.is-done { opacity: 0.75; }
.intake.is-done .intake-name { text-decoration: line-through; text-decoration-thickness: 1px; }

/* ---------- Medikamentenliste ---------- */

.med-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.med-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 5px solid var(--med-color, var(--c-primary));
  border-radius: var(--radius);
  box-shadow: var(--c-shadow);
  padding: 0.85rem 1rem;
}
.med-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.med-title { font-weight: 800; font-size: 1.05rem; }
.med-dose { color: var(--c-text-muted); font-size: 0.92rem; }
.med-meta { margin-top: 0.4rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.med-chip {
  background: var(--c-surface-2);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  color: var(--c-text-muted);
}
.med-stockline { margin-top: 0.45rem; font-size: 0.88rem; }
.med-stockline.warn { color: var(--c-accent); font-weight: 600; }
.med-stockline.danger { color: var(--c-danger); font-weight: 700; }
.med-actions { display: flex; gap: 0.4rem; }

/* ---------- Formulare ---------- */

.field { margin-bottom: 0.85rem; }
.field label, .field legend {
  display: block;
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.3rem;
}
fieldset.field { border: none; padding: 0; margin-left: 0; margin-right: 0; }

input[type="text"],
input[type="number"],
input[type="time"],
input[type="date"],
select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-small);
  background: var(--c-surface);
  color: var(--c-text);
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

.grid-3 { display: grid; grid-template-columns: 1fr; gap: 0.4rem 0.8rem; }

.times-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.5rem; }
.time-row { display: flex; gap: 0.5rem; align-items: center; }
.time-row input[type="time"] { flex: 1; }
.time-remove {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-small);
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--c-text-muted);
}
.time-remove:hover { color: var(--c-danger); border-color: var(--c-danger); }

.check-inline { display: flex; align-items: center; gap: 0.45rem; font-weight: 600; }

.weekday-row { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.5rem; }
.daychip { position: relative; }
.daychip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.daychip span {
  display: inline-block;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--c-text-muted);
  user-select: none;
}
.daychip input:checked + span {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: var(--c-bg);
}
.daychip input:focus-visible + span { outline: 2px solid var(--c-primary); outline-offset: 2px; }

.color-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.colorchip { position: relative; }
.colorchip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.colorchip span {
  display: block;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 3px solid transparent;
}
.colorchip input:checked + span { border-color: var(--c-text); }
.colorchip input:focus-visible + span { outline: 2px solid var(--c-primary); outline-offset: 2px; }

.form-error { color: var(--c-danger); font-weight: 600; font-size: 0.9rem; }

/* ---------- Historie ---------- */

.adherence-card {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--c-shadow);
  padding: 1rem 1.2rem;
}
.adherence-score { display: flex; flex-direction: column; }
.adherence-value {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--c-primary);
  line-height: 1.1;
}
.adherence-label { color: var(--c-text-muted); font-size: 0.85rem; }
.adherence-detail { flex: 1 1 220px; color: var(--c-text-muted); font-size: 0.92rem; }

.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 6px;
  margin-top: 0.4rem;
}
.hm-cell {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--hm-0);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: var(--c-text-muted);
  line-height: 1.15;
}
.hm-cell .d { font-weight: 800; font-size: 0.8rem; color: inherit; }
.hm-cell.hm-1 { background: var(--hm-1); }
.hm-cell.hm-2 { background: var(--hm-2); }
.hm-cell.hm-3 { background: var(--hm-3); color: var(--c-bg); }
.hm-cell.hm-4 { background: var(--hm-4); color: var(--c-bg); }
.hm-cell.is-today { outline: 2px solid var(--c-accent); outline-offset: 1px; }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 0.7rem;
  font-size: 0.78rem;
  color: var(--c-text-muted);
}
.heatmap-legend .hm { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.hm-0 { background: var(--hm-0); }
.hm-1 { background: var(--hm-1); }
.hm-2 { background: var(--hm-2); }
.hm-3 { background: var(--hm-3); }
.hm-4 { background: var(--hm-4); }

/* ---------- Export ---------- */

.export-form {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}
.export-form .field { margin-bottom: 0; flex: 1 1 140px; }

.print-area {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.print-area h2 { margin-top: 0; }
.print-meta { color: var(--c-text-muted); font-size: 0.88rem; }

.protocol-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-top: 0.6rem;
}
.protocol-table th, .protocol-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
.protocol-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--c-text-muted); }
.protocol-table .st-taken { color: var(--c-success); font-weight: 700; }
.protocol-table .st-skipped { color: var(--c-accent); font-weight: 700; }
.protocol-table .st-open { color: var(--c-text-muted); }
.table-scroll { overflow-x: auto; }

/* ---------- Ad-Slot / Footer ---------- */

.ad-slot {
  margin-top: 2rem;
  border: 1px dashed var(--c-border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  text-align: center;
  color: var(--c-text-muted);
  background: var(--c-surface);
}
.ad-slot-label {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 0 0.35rem;
  margin-bottom: 0.35rem;
}
.ad-slot-placeholder { margin: 0; font-size: 0.85rem; }

.app-footer {
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  padding: 1rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--c-text-muted);
}
.app-footer p { max-width: 640px; margin: 0 auto 0.5rem; }

/* ---------- Empty State ---------- */

.empty-state {
  text-align: center;
  padding: 2.2rem 1rem;
  color: var(--c-text-muted);
}
.empty-state svg { width: 44px; height: 44px; color: var(--c-primary); margin-bottom: 0.5rem; }
.empty-state h2 { color: var(--c-text); }
.empty-state .btn { margin-top: 0.6rem; }

.fineprint { color: var(--c-text-muted); font-size: 0.8rem; }

/* ---------- Modals ---------- */

.modal { border: none; padding: 0; background: transparent; max-width: none; }
.modal::backdrop { background: rgba(10, 26, 24, 0.55); backdrop-filter: blur(2px); }

.modal-card {
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  width: min(94vw, 460px);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  margin: 0;
}
.modal-wide { width: min(94vw, 560px); }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.1rem 0.4rem;
}
.modal-head h2 { margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--c-text-muted);
  padding: 0.1rem 0.4rem;
}
.modal-close:hover { color: var(--c-danger); }

.modal-body { padding: 0.5rem 1.1rem; overflow-y: auto; }
.modal-context { background: var(--c-surface-2); border-radius: var(--radius-small); padding: 0.5rem 0.7rem; font-size: 0.9rem; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.7rem 1.1rem 1rem;
}

.premium-price { font-size: 1.15rem; }
.premium-list { margin: 0.4rem 0 0.8rem; padding-left: 1.2rem; }
.premium-list li { margin-bottom: 0.3rem; }

.legal-text { font-size: 0.9rem; }

/* ---------- Responsive ---------- */

@media (min-width: 560px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  h1 { font-size: 2rem; }
}

/* ---------- Druck ---------- */

@media print {
  .app-header, .app-footer, .ad-slot, .privacy-note, .notify-card,
  .export-form, #btn-print, .stock-warnings, .tabs { display: none !important; }
  .view { display: none !important; }
  #view-export { display: block !important; }
  .print-area { border: none; padding: 0; box-shadow: none; }
  body { background: #fff; color: #000; }
  .protocol-table th, .protocol-table td { border-bottom: 1px solid #999; }
}

/* ---------- Erste Schritte (Onboarding) ---------- */

.help-btn {
  inline-size: 2rem;
  block-size: 2rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-muted);
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}
.help-btn:hover,
.help-btn:focus-visible { color: var(--c-primary); border-color: var(--c-primary); }

.tour-intro { color: var(--c-text-muted); margin-bottom: 0.9rem; }
.tour-steps { margin: 0 0 1rem; padding-left: 1.25rem; display: grid; gap: 0.6rem; }
.tour-steps li strong { color: var(--c-primary); }

.know-box {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-small);
  padding: 0.9rem 1rem;
  margin-bottom: 0.25rem;
}
.know-box h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.know-box ul { margin: 0; padding-left: 1.1rem; display: grid; gap: 0.4rem; }
.know-box li { font-size: 0.9rem; color: var(--c-text-muted); }
