/* MedAsystent — mobile only (iPhone / Samsung). Tokeny z design handoffu. */
:root {
  --teal: #0D9488;
  --teal-light: #E6FBF8;
  --success: #16A34A;
  --success-bg: #ECFDF3;
  --bg: #F5F8F9;
  --card: #FFFFFF;
  --border: #E7EEEE;
  --text: #10201F;
  --muted: #64748B;
  --muted-2: #94A3B8;
  --disabled: #E2E8F0;
  --danger: #DC2626;
  --danger-bg: #FEF2F2;
  --shadow: 0 1px 2px rgba(16, 32, 31, .05);
  --r-card: 18px;
  --r-btn: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { display: flex; flex-direction: column; }

button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ layout */
.app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 18px) 18px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}
.screen.center {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
}

/* --------------------------------------------------------- typography */
.title { font-size: 28px; font-weight: 700; letter-spacing: -.4px; margin: 6px 0 16px; }
.title--sm { font-size: 20px; margin: 0; }
.greeting { font-size: 15px; color: var(--muted); margin: 6px 0 0; }
.muted { color: var(--muted); margin: 2px 0 18px; font-size: 14px; }
.hint { font-size: 12.5px; color: var(--muted-2); margin: 14px 2px 16px; }
.label {
  font-size: 11.5px; letter-spacing: .5px; text-transform: uppercase;
  color: var(--muted-2); margin: 0 0 6px;
}

/* -------------------------------------------------------------- brand */
.page-head { margin-bottom: 4px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.head-row--answer { gap: 12px; justify-content: flex-start; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand--big { justify-content: center; margin-bottom: 22px; }
.logo {
  width: 26px; height: 26px; border-radius: 8px; background: var(--teal);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.brand-name { font-size: 13px; font-weight: 600; color: var(--teal); }
.mini-logo {
  width: 24px; height: 24px; border-radius: 7px; background: var(--teal);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}

.icon-btn, .round-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
}
.icon-btn:active, .round-btn:active { background: #F1F5F9; }

/* -------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-row--tight { justify-content: flex-start; gap: 9px; margin-bottom: 10px; }
.card-title { font-size: 13.5px; font-weight: 700; }

textarea {
  width: 100%; border: 0; outline: 0; resize: none;
  background: transparent; font-size: 15px; line-height: 1.5;
  min-height: 108px;
}
textarea::placeholder { color: var(--muted-2); }

.pill {
  border: 0; border-radius: 999px; padding: 7px 15px;
  background: var(--teal-light); color: var(--teal);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.pill:active { opacity: .75; }

/* -------------------------------------------------------------- photo */
.photo-slot { margin-top: 12px; }
.dropzone {
  width: 100%; height: 170px; border-radius: 14px;
  border: 1.5px dashed #B8DEDA; background: #FBFEFE;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
  cursor: pointer; padding: 12px;
}
.dropzone:active { background: var(--teal-light); }
.dz-title { font-size: 14px; font-weight: 600; color: var(--teal); }
.dz-sub { font-size: 12px; color: var(--muted-2); }

.preview { margin: 0; }
.preview img {
  width: 100%; height: 170px; object-fit: cover;
  border-radius: 14px; border: 1px solid var(--border); display: block;
}
.pdf-card {
  display: flex; align-items: center; gap: 12px;
  height: 88px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--teal-light); color: var(--teal);
  font-size: 14px; font-weight: 600;
}
.preview figcaption {
  font-size: 12px; color: var(--muted-2); margin-top: 7px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------ buttons */
.btn {
  width: 100%; border: 0; border-radius: var(--r-btn);
  padding: 15px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:active { background: #0B8177; }
.btn-primary:disabled { background: var(--disabled); color: var(--muted-2); cursor: default; }
.btn.is-busy { opacity: .75; pointer-events: none; }

.link-btn {
  border: 0; background: none; color: var(--teal);
  font-size: 13px; font-weight: 700; cursor: pointer;
  padding: 2px 4px; margin-left: auto;
}

/* ----------------------------------------------------------- odpowiedź */
.qtext { font-size: 14.5px; margin: 0; }
.badge {
  display: inline-block; margin-top: 10px; padding: 4px 10px;
  border-radius: 999px; font-size: 11.5px; font-weight: 700;
}
.badge-teal { background: var(--teal-light); color: var(--teal); }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-grey { background: #F1F5F9; color: var(--muted); }
.badge-red { background: var(--danger-bg); color: var(--danger); }

.answer-text { font-size: 15px; line-height: 1.55; }
.answer-text p { margin: 0 0 10px; }
.answer-text p:last-child { margin-bottom: 0; }
.answer-text ul, .answer-text ol { margin: 0 0 10px; padding-left: 20px; }
.answer-text li { margin-bottom: 5px; }
.answer-text strong { font-weight: 700; color: #0B5F58; }
.disclaimer { font-size: 12px; font-style: italic; color: var(--muted-2); margin: 14px 0 0; }

/* --------------------------------------------- przełącznik trybu deep */
.switch-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 14px; cursor: pointer;
}
.switch-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.switch-title { font-size: 14.5px; font-weight: 600; }
.switch-sub { font-size: 12px; color: var(--muted-2); line-height: 1.35; }
.switch-input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-ui {
  width: 46px; height: 28px; border-radius: 999px;
  background: var(--disabled); position: relative; flex: 0 0 auto;
  transition: background .18s ease;
}
.switch-ui::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(16,32,31,.25); transition: transform .18s ease;
}
.switch-input:checked ~ .switch-ui { background: var(--teal); }
.switch-input:checked ~ .switch-ui::after { transform: translateX(18px); }
.switch-input:focus-visible ~ .switch-ui { outline: 2px solid var(--teal); outline-offset: 2px; }

.deep-mini {
  display: flex; align-items: center; gap: 9px;
  margin: 0 4px 9px; font-size: 12.5px; color: var(--muted);
  cursor: pointer;
}
.deep-mini-ui {
  width: 34px; height: 20px; border-radius: 999px;
  background: var(--disabled); position: relative; flex: 0 0 auto;
  transition: background .18s ease;
}
.deep-mini-ui::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(16,32,31,.25); transition: transform .18s ease;
}
.deep-mini .switch-input:checked ~ .deep-mini-ui { background: #4338CA; }
.deep-mini .switch-input:checked ~ .deep-mini-ui::after { transform: translateX(14px); }

.deep-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #EEF2FF; color: #4338CA;
  border-radius: 999px; padding: 4px 11px;
  font-size: 11.5px; font-weight: 700;
}

/* ------------------------------------------------------ wątek rozmowy */
.bubble-user {
  background: var(--teal-light);
  border-radius: 16px 16px 6px 16px;
  padding: 13px 15px; margin: 0 0 12px auto;
  max-width: 88%; width: fit-content;
  font-size: 14.5px; color: #0B5F58; white-space: pre-wrap;
}

.followup {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 8px 8px 8px 14px; margin-bottom: 14px;
}
.followup textarea {
  min-height: 26px; max-height: 130px; padding: 6px 0; font-size: 15px;
}
.send-round {
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: var(--teal); color: #fff; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.send-round:disabled { background: var(--disabled); color: var(--muted-2); cursor: default; }
.send-round.is-busy { opacity: .6; pointer-events: none; }

.thinking {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; color: var(--muted); margin: 0 0 14px 2px;
}

.hermes {
  display: flex; align-items: center; gap: 10px;
  background: #F1F5F9; border-radius: 14px;
  padding: 13px 15px; font-size: 13.5px; color: var(--muted);
  margin-bottom: 14px;
}
.hermes.is-done { background: var(--success-bg); color: var(--success); font-weight: 600; }
.hermes.is-error { background: var(--danger-bg); color: var(--danger); font-weight: 600; }

.check { width: 18px; height: 18px; flex: 0 0 auto; }

/* ------------------------------------------------------------ spinner */
.spinner {
  width: 18px; height: 18px; flex: 0 0 auto;
  border: 2px solid #CBD5E1; border-top-color: var(--teal);
  border-radius: 50%; animation: spin .9s linear infinite;
}
.spinner--lg { width: 56px; height: 56px; border-width: 3px; margin-bottom: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.load-title { font-size: 16px; font-weight: 600; margin: 0; }
.load-sub { font-size: 13px; color: var(--muted-2); margin: 0; }

/* ----------------------------------------------------------- historia */
.entry {
  width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 15px 40px 15px 16px; margin-bottom: 12px;
  position: relative; cursor: pointer;
}
.entry:active { background: #FAFDFD; }
.entry-date { font-size: 12.5px; color: var(--muted-2); margin: 0 0 5px; }
.entry-q { font-size: 14.5px; margin: 0 0 10px; }
.entry-badges { display: flex; flex-wrap: wrap; gap: 7px; }
.entry-badges .badge { margin-top: 0; }
.chev { position: absolute; right: 14px; top: 16px; color: var(--muted-2); }

.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 60px 0; color: var(--muted-2);
}
.empty p { margin: 0; font-size: 14.5px; }

/* ------------------------------------------------------------- tabbar */
.tabbar {
  display: flex; flex: 0 0 auto;
  background: rgba(255,255,255,.94);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 7px; color: var(--muted-2); font-size: 11.5px; font-weight: 600;
}
.tab.is-active { color: var(--teal); }

/* --------------------------------------------------------- logowanie */
.login {
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
}
.login-box { width: 100%; max-width: 420px; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--r-btn);
  padding: 14px 15px; font-size: 16px; outline: 0; /* 16px = brak zoomu na iOS */
}
.field input:focus { border-color: var(--teal); }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 74px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--teal);
  font-size: 13px; font-weight: 600; padding: 8px; cursor: pointer;
}

.form-error {
  background: var(--danger-bg); color: var(--danger);
  border-radius: 12px; padding: 11px 14px;
  font-size: 13.5px; font-weight: 600; margin: 0 0 14px;
}

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px);
  background: #10201F; color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; z-index: 50;
  max-width: calc(100% - 40px); text-align: center;
}

/* ---------------------------------------------- duże ekrany = telefon */
@media (min-width: 560px) {
  body {
    max-width: 460px; margin: 0 auto;
    border-left: 1px solid var(--border); border-right: 1px solid var(--border);
    background: var(--bg);
  }
}

.badge-deep { background: #EEF2FF; color: #4338CA; }
