/* Notfall-ID — Dark theme, mobile-first, print-friendly */

:root {
  --bg: #0b1220;
  --bg-elev: #131b2e;
  --bg-card: #1a2440;
  --line: #2a3656;
  --line-strong: #3a4a73;
  --text: #e6edf6;
  --text-dim: #9aa9c3;
  --text-mute: #6f7d99;
  --accent: #f04f4f;
  --accent-dim: #b83a3a;
  --accent-soft: #2a1818;
  --ok: #5fce8e;
  --warn: #ffb24d;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 880px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100dvh;
}

a { color: #8ab4ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11,18,32,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px env(safe-area-inset-top, 0) 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-weight: 700; font-size: 17px;
  text-decoration: none;
}
.brand-mark {
  width: 30px; height: 30px;
  display: inline-grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 8px;
  font-weight: 800; font-size: 22px; line-height: 1;
}
.brand-name { letter-spacing: .3px; }

.tabs {
  display: flex; gap: 4px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin: 0 -4px;
  grid-column: 1 / -1;
  order: 3;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
}
.tab.is-active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}
.tab:focus-visible { outline: 2px solid #8ab4ff; outline-offset: 2px; }
.lang-btn {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}

@media (min-width: 720px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .tabs { grid-column: 2; order: 0; justify-content: center; }
}

/* App content */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 14px 40px;
}

.view-title {
  font-size: 22px;
  margin: 6px 0 4px;
  letter-spacing: .2px;
}
.view-lede {
  color: var(--text-dim);
  margin: 0 0 18px;
  font-size: 15px;
}

/* Profile bar */
.profile-bar {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.prof-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.prof-pill {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  min-height: 32px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.prof-pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.prof-pill.prof-add {
  background: transparent;
  color: var(--text-dim);
  border-style: dashed;
}
.prof-actions { display: flex; gap: 4px; }
.prof-icon-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: 14px;
}
.prof-icon-btn:hover { color: var(--text); border-color: var(--line-strong); }

/* Tutorial */
.tutorial {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 12px;
}
.tutorial summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tutorial summary::before {
  content: "›";
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  transition: transform 0.15s;
  flex: 0 0 14px;
}
.tutorial[open] summary::before { transform: rotate(90deg); }
.tutorial summary::-webkit-details-marker { display: none; }
.tutorial-body {
  padding: 0 16px 16px;
  color: var(--text-dim);
  font-size: 14px;
}
.tutorial-body h3 {
  font-size: 14px;
  color: var(--text);
  margin: 14px 0 6px;
}
.tutorial-body ol, .tutorial-body ul { padding-left: 22px; margin: 6px 0; }
.tutorial-body li { margin: 0 0 4px; line-height: 1.55; }
.tutorial-body p { margin: 6px 0; }
.tutorial-body .btn { margin-top: 10px; max-width: 220px; }

/* Variant-picker (lockscreen device size) */
.variant-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}
.variant-pill {
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  flex: 1 1 auto;
  min-height: 36px;
  white-space: nowrap;
}
.variant-pill:hover { color: var(--text); border-color: var(--line-strong); }
.variant-pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* Contact rows (dynamic) */
.contact-row {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 0 0 12px;
}
.contact-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 10px;
}
.contact-row-head h3 {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 600;
}
.contact-remove {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text-mute);
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.contact-remove:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Source citation */
.source-citation {
  margin: 24px 0 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-left: 3px solid var(--text-mute);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text-dim);
  font-size: 13px;
}
.source-citation strong { color: var(--text); }
.source-citation ul { padding-left: 20px; margin: 8px 0; }
.source-citation li { margin: 0 0 4px; }
.source-citation .cite-note {
  font-size: 12px;
  color: var(--text-mute);
  margin: 10px 0 0;
}

/* Form */
.section {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}
.section h2 {
  font-size: 16px;
  margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
  color: var(--text);
}
.section h2 .icon {
  width: 24px; height: 24px;
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 6px; font-size: 14px;
  flex: 0 0 24px;
}
.field {
  display: block;
  margin: 0 0 12px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0 0 12px;
}
@media (min-width: 540px) {
  .field-row { grid-template-columns: repeat(2, 1fr); }
  .field-row.three { grid-template-columns: repeat(3, 1fr); }
}
.field label,
.field-row label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: .8px;
}
.field input,
.field textarea,
.field select,
.field-row input,
.field-row textarea,
.field-row select {
  width: 100%;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 16px; /* prevent iOS auto-zoom */
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus,
.field textarea:focus,
.field select:focus { outline: 2px solid #8ab4ff; outline-offset: 1px; border-color: #8ab4ff; }
.field-hint { font-size: 12px; color: var(--text-mute); margin: 4px 0 0; }

.radio-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.radio-row label {
  flex: 1 1 auto;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  margin: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px;
}
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row input:checked + label,
.radio-row label.is-checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.actions-row {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin: 18px 0 6px;
}
.btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
  flex: 1 1 auto;
  text-align: center;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: var(--accent-dim); }
.btn.secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line-strong);
}
.btn.secondary:hover { background: var(--bg-elev); }
.btn.ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line);
}

/* Preview view */
.preview-card-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 16px;
}
.preview-card-wrap canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.preview-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin: 0 0 8px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.preview-label .meta { color: var(--text-mute); font-weight: 400; }

.preview-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 10px 0 0;
}
.preview-actions .btn { flex: 1 1 200px; }

.preview-empty {
  background: var(--bg-elev);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 28px 18px;
  text-align: center;
  color: var(--text-dim);
}

/* Phrases */
.phrase-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.phrase {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.phrase h3 {
  font-size: 14px;
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .8px;
}
.phrase .line {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 10px;
  margin: 0 0 4px;
  font-size: 14px;
  align-items: baseline;
}
.phrase .lang {
  color: var(--text-mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
}
.phrase .text { color: var(--text); }
.phrase .text.rtl { direction: rtl; text-align: right; font-size: 16px; }
.phrase .phonetic { color: var(--text-dim); font-style: italic; font-size: 13px; }

/* About */
.about-block {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 14px;
}
.about-block h2 { font-size: 16px; margin: 0 0 8px; }
.about-block p, .about-block ul { color: var(--text-dim); font-size: 14px; }
.about-block ul { padding-left: 18px; }
.about-block li { margin: 0 0 4px; }

/* Footer */
.footer {
  max-width: var(--maxw);
  margin: 24px auto 0;
  padding: 20px 14px 28px;
  border-top: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 13px;
}
.footer-row {
  display: flex; flex-wrap: wrap; gap: 12px;
  margin: 0 0 12px;
}
.footer-disclaim {
  color: var(--text-mute);
  font-size: 12px;
  margin: 0 0 16px;
}
.footer-cross { margin: 14px 0 8px; color: var(--text-dim); font-size: 13px; }
.cross-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0 0 14px;
}
@media (min-width: 600px) { .cross-grid { grid-template-columns: repeat(4, 1fr); } }
.cross-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  color: var(--text);
  text-decoration: none;
  display: flex; flex-direction: column; gap: 4px;
  min-height: 80px;
}
.cross-card:hover { background: var(--bg-card); text-decoration: none; }
.cross-mark { font-size: 22px; }
.cross-title { font-weight: 700; font-size: 13px; color: var(--text); }
.cross-sub { font-size: 11px; color: var(--text-mute); }
.footer-version { font-size: 11px; color: var(--text-mute); margin: 6px 0 0; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ok); color: #0b1220;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.warn { background: var(--warn); }
.toast.err { background: var(--accent); color: #fff; }

/* First-run disclaimer modal */
.disc-overlay {
  position: fixed; inset: 0; background: rgba(5,8,16,.92);
  display: grid; place-items: center;
  z-index: 200;
  padding: 16px;
}
.disc-card {
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  max-width: 520px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.disc-card h2 { margin: 0 0 10px; font-size: 19px; }
.disc-card p { color: var(--text-dim); font-size: 14px; margin: 0 0 12px; }
.disc-card .btn { width: 100%; margin: 8px 0 0; }

/* Print */
@media print {
  .topbar, .footer, .preview-actions, .tabs, .lang-btn, #disc-overlay { display: none !important; }
  body { background: #fff; color: #000; }
  .app { padding: 0; max-width: none; }
  .section { display: none; }
  #print-sheet { display: block !important; padding: 12mm; }
}
#print-sheet { display: none; }
@media print {
  #print-sheet {
    color: #000;
    font: 11pt/1.4 "Segoe UI", system-ui, sans-serif;
  }
  #print-sheet h1 { font-size: 20pt; margin: 0 0 8pt; }
  #print-sheet h2 { font-size: 13pt; margin: 12pt 0 4pt; border-bottom: 1pt solid #999; padding-bottom: 2pt; }
  #print-sheet .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8pt; }
  #print-sheet .kv { margin: 0 0 3pt; }
  #print-sheet .kv b { display: inline-block; min-width: 110pt; }
  #print-sheet .card-print {
    width: 86mm; height: 54mm;
    border: 0.5pt solid #444;
    padding: 6pt;
    margin: 8pt 0;
    page-break-inside: avoid;
    border-radius: 3mm;
    background: #fff;
  }
  #print-sheet .action-banner {
    border: 1.5pt solid #cc1a1a;
    background: #fff5f5;
    padding: 6pt 8pt;
    border-radius: 2mm;
    margin: 6pt 0 12pt;
  }
  #print-sheet .action-label {
    color: #cc1a1a; font-weight: 700; font-size: 9pt;
    text-transform: uppercase; letter-spacing: .5pt;
    margin: 0 0 3pt;
  }
  #print-sheet .action-text {
    font-weight: 700; font-size: 12pt; color: #000; margin: 0;
  }
}
