:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #16202b;
  --muted: #5d6b7a;
  --line: #d9dfe6;
  --accent: #1f4e79;
  --accent-text: #ffffff;
  --ward-bg: #e3edf7;
  --danger: #b3261e;
  --input: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --card: #1b232c;
    --text: #e6ebf0;
    --muted: #93a1b0;
    --line: #2d3843;
    --accent: #5b9bd5;
    --accent-text: #0b1622;
    --ward-bg: #23364a;
    --danger: #f28b82;
    --input: #141b22;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

button, input, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent);
  color: var(--accent-text);
}

.topbar h1 { margin: 0; font-size: 20px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 24px;
}

.menu {
  position: fixed;
  top: calc(60px + env(safe-area-inset-top));
  right: 12px;
  z-index: 10;
  min-width: 260px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  overflow: hidden;
}

.menu form { margin: 0; }

.menu button {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.menu form button { border-bottom: 0; color: var(--danger); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

.muted { color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.card-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.ward {
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--ward-bg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.fio { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }

.diagnosis, .notes { margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.notes { color: var(--muted); font-size: 15px; }

.empty { text-align: center; color: var(--muted); margin-top: 48px; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
}

dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
}

dialog::backdrop { background: rgba(0, 0, 0, .45); }

dialog form { padding: 16px; display: grid; gap: 12px; }

dialog h2 { margin: 0; font-size: 18px; }

label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }

input, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
  color: var(--text);
  font-size: 16px; /* меньше 16px — iOS зумит при фокусе */
}

textarea { resize: vertical; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.spacer { flex: 1; }

.actions button, .login button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
}

button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

button.danger { color: var(--danger); border-color: var(--danger); }

.error { margin: 0; color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  z-index: 20;
}

.login {
  max-width: 360px;
  margin: 15vh auto 0;
  padding: 0 16px;
  display: grid;
  gap: 12px;
}

.login h1 { margin: 0 0 8px; font-size: 22px; }

.login button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
