/* Design Tokens – Health365 AC GmbH Design System */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #dbeafe;
  --accent: #1d4ed8;
  --border: #e2e8f0;
  --header-bg: #1a365d;
  --header-text: #ffffff;
  /* Zustands-Farben */
  --success: #10b981;
  --success-bg: #d1fae5;
  --success-text: #065f46;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --info: #1e40af;
  --info-bg: #dbeafe;
  --info-text: #1e40af;
  /* Status (Einsatzdokumentation) */
  --status-draft-bg: #fef3c7;
  --status-draft-text: #92400e;
  --status-progress-bg: #dbeafe;
  --status-progress-text: #1e40af;
  --status-done-bg: #d1fae5;
  --status-done-text: #065f46;
  --status-billed-bg: #e9d5ff;
  --status-billed-text: #6b21a8;
  /* Abstände */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  /* Radien */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
}

* { box-sizing: border-box; }
html { background-color: #f8fafc; }
body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 14px/1.6 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; }
@media (prefers-color-scheme: dark) { html { background-color: #0f172a; } body { background-color: #0f172a; color: #e5e7eb; } }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
.topbar { position: sticky; top: 0; background: var(--header-bg); display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem; z-index: 10; min-height: 56px; }
.topbar .brand { display: flex; align-items: center; gap: 12px; color: var(--header-text); text-decoration: none; } .topbar .brand:hover { text-decoration: none; }
.topbar .brand img { height: 36px; width: auto; }
.topbar .brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.topbar .brand-title { font-weight: 700; font-size: 15px; color: var(--header-text); }
.topbar .brand-subtitle { font-size: 11px; color: rgba(255,255,255,0.7); font-weight: 400; }
.topbar .topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.topbar .topbar-actions a, .topbar .topbar-actions button { color: var(--header-text); opacity: 0.85; transition: opacity .15s; }
.topbar .topbar-actions a:hover, .topbar .topbar-actions button:hover { opacity: 1; text-decoration: none; }
nav a { margin-left: 12px; }
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-md); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-md); box-shadow: 0 1px 2px rgba(0,0,0,.04); }
/* Buttons */
.btn { display: inline-block; background: #eee; border: 1px solid #ddd; border-radius: var(--radius-md); padding: 8px 12px; min-height: 44px; box-sizing: border-box; cursor: pointer; font: inherit; }
.btn.primary, .btn-primary, .btn.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover, .btn-primary:hover, .btn.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.secondary, .btn-secondary { background: #f3f4f6; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover, .btn-secondary:hover { background: #e5e7eb; }
.btn.danger, .btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.warning, .btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn.success, .btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn:hover { filter: brightness(.97); }
.btn-sm { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.btn-lg { min-height: 52px; padding: 12px 16px; font-size: 16px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 10px 6px; border-bottom: 1px dashed #eee; }
.list li:last-child { border-bottom: none; }
label { display: block; margin-top: 10px; margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); box-sizing: border-box; }
.footer { color: var(--muted); text-align: center; margin: var(--space-xl) 0; }
.link { color: var(--accent); }
.muted { color: var(--muted); }
.pillbar { display: flex; gap: var(--space-sm); margin-top: var(--space-sm); }
.pill { border: 1px solid #ddd; border-radius: 999px; padding: 6px 10px; background: #fafafa; }
.mail-body img { max-width: 100%; height: auto; }

/* Status-Badges (Einsatzdokumentation u.a.) */
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-draft { background: var(--status-draft-bg); color: var(--status-draft-text); }
.status-in_progress { background: var(--status-progress-bg); color: var(--status-progress-text); }
.status-completed { background: var(--status-done-bg); color: var(--status-done-text); }
.status-billed { background: var(--status-billed-bg); color: var(--status-billed-text); }

/* Seiten-Header */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: var(--space-md); margin-bottom: var(--space-lg); }
.page-header h1 { font-size: clamp(20px, 5vw, 28px); font-weight: 800; color: var(--text); margin: 0 0 4px 0; }
.page-actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; align-items: center; }

/* Info-Boxen */
.info-box { padding: 12px 16px; border-radius: var(--radius-md); border-left: 4px solid var(--info); background: var(--info-bg); color: var(--info-text); font-size: 14px; margin-bottom: var(--space-md); }
.info-box--success { border-color: var(--success); background: var(--success-bg); color: var(--success-text); }
.info-box--warning { border-color: var(--warning); background: var(--warning-bg); color: var(--warning-text); }
.info-box--danger { border-color: var(--danger); background: var(--danger-bg); color: var(--danger-text); }

/* Formulare */
.form-group { margin-bottom: var(--space-md); }
.form-group label { display: block; margin-bottom: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; margin-top: var(--space-lg); }
.required { color: var(--danger); }

/* Tabellen */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { background: var(--bg); color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; padding: 10px 12px; border-bottom: 2px solid var(--border); text-align: left; }
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.data-table tr:hover td { background: var(--bg); }

/* ========== Kacheln / Metric-Cards (einheitlich wie Dashboard) ==========
   Nutzen: .metric-grid > a.metric-card bzw. .kachel-grid > a.kachel
   Icon immer in .metric-icon / .kachel-icon (SVG bevorzugt, 24x24 viewBox).
   Keine beliebigen Emojis oder inline style="background:..." für Kacheln. */
.metric-grid,
.kachel-grid {
  display: grid;
  gap: clamp(8px, 1.5vw, 12px);
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 640px) {
  .metric-grid { grid-template-columns: repeat(5, 1fr); }
  .kachel-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

.metric-card,
a.kachel.metric-style {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: clamp(10px, 2vw, 14px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: box-shadow .12s, border-color .12s;
  min-height: 72px;
  box-sizing: border-box;
}
.metric-card:hover,
a.kachel.metric-style:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border-color: var(--brand);
}

.metric-icon,
.kachel-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  color: var(--brand);
  flex-shrink: 0;
}
.metric-icon svg,
.kachel-icon svg {
  width: 20px;
  height: 20px;
}
.kachel-icon:not(:has(svg)) {
  font-size: 20px;
  line-height: 1;
}

.metric-title,
.kachel-title {
  font-size: clamp(10px, 2.2vw, 12px);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin-bottom: 2px;
}
.metric-value,
.kachel-value {
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.metric-arrow,
.kachel-arrow {
  margin-top: auto;
  font-size: 12px;
  color: var(--brand);
  font-weight: 600;
}

/* Allgemeine Kachel (ohne metric-Subklassen) – z.B. für Listen wie Löschgruppen */
.kachel {
  display: block;
  padding: clamp(12px, 3vw, 16px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  transition: box-shadow .12s, border-color .12s;
  box-sizing: border-box;
}
.kachel:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border-color: var(--brand);
}

/* ============================================================
   ZENTRALER iOS DARK-MODE FIX
   Health365 Design – Helles Layout auf iOS erzwingen.
   ============================================================ */
@supports (-webkit-touch-callout: none) {

  html, body {
    background-color: #f8fafc !important;
    color: #1e293b !important;
  }

  [class$="-page"],
  .hero-page,
  .kachel-page {
    --bg:     #f8fafc !important;
    --card:   #ffffff !important;
    --text:   #1e293b !important;
    --muted:  #64748b !important;
    --border: #e2e8f0 !important;
    --brand:  #2563eb !important;
    background-color: #f8fafc !important;
    color: #1e293b !important;
  }

  .topbar {
    background: #1a365d !important;
    border-bottom: none !important;
  }
  .topbar .brand, .topbar .brand-title, .topbar .brand-subtitle { color: #ffffff !important; }

  .sidebar {
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
  }

  @media (prefers-color-scheme: dark) {
    html, body {
      background-color: #f8fafc !important;
      color: #1e293b !important;
    }

    [class$="-page"],
    .hero-page,
    .kachel-page {
      --bg:     #f8fafc !important;
      --card:   #ffffff !important;
      --text:   #1e293b !important;
      --muted:  #64748b !important;
      --border: #e2e8f0 !important;
      --brand:  #2563eb !important;
      background-color: #f8fafc !important;
      color: #1e293b !important;
    }

    .container, .card, section, main, article {
      background-color: #ffffff !important;
      color: #1e293b !important;
      border-color: #e2e8f0 !important;
    }

    input, select, textarea {
      background-color: #ffffff !important;
      color: #1e293b !important;
      border-color: #cbd5e1 !important;
    }

    a { color: #2563eb !important; }

    .topbar { background: #1a365d !important; }
    .sidebar { background: #ffffff !important; border-color: #e2e8f0 !important; }

    .btn.primary, .btn-primary,
    button.btn.primary, a.btn.primary {
      background-color: #2563eb !important;
      color: #ffffff !important;
      border-color: #2563eb !important;
    }
  }
}
