/* Manrope (SIL OFL 1.1), self-hosted variable font, weights 200-800. The app font. */
@font-face { font-family: "Manrope"; font-style: normal; font-display: swap; font-weight: 200 800;
  src: url("../fonts/manrope/manrope-cyrillic-ext-wght-normal.4cdf0bed0838.woff2") format("woff2-variations"), url("../fonts/manrope/manrope-cyrillic-ext-wght-normal.4cdf0bed0838.woff2") format("woff2");
  unicode-range: U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F; }
@font-face { font-family: "Manrope"; font-style: normal; font-display: swap; font-weight: 200 800;
  src: url("../fonts/manrope/manrope-cyrillic-wght-normal.e58febde317b.woff2") format("woff2-variations"), url("../fonts/manrope/manrope-cyrillic-wght-normal.e58febde317b.woff2") format("woff2");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }
@font-face { font-family: "Manrope"; font-style: normal; font-display: swap; font-weight: 200 800;
  src: url("../fonts/manrope/manrope-latin-ext-wght-normal.6d36d5bdedfa.woff2") format("woff2-variations"), url("../fonts/manrope/manrope-latin-ext-wght-normal.6d36d5bdedfa.woff2") format("woff2");
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: "Manrope"; font-style: normal; font-display: swap; font-weight: 200 800;
  src: url("../fonts/manrope/manrope-latin-wght-normal.938c6e8019b6.woff2") format("woff2-variations"), url("../fonts/manrope/manrope-latin-wght-normal.938c6e8019b6.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

/* Brand palette (Enigma Clinic): cyan #22AFDB, deep teal #00394B, orange #E7964F, black. */
:root {
  --brand-cyan: #22AFDB;
  --brand-teal: #00394B;
  --brand-orange: #E7964F;
  --brand-ink: #04232C;
  --brand-cyan-tint: #e3f4fa;
  --brand-cyan-line: #8fd3ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1a1a1a;
  background: #fafafa;
}

a {
  color: var(--brand-teal);
}

header.topbar {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

header.topbar .brand {
  font-weight: 600;
  text-decoration: none;
  color: #1a1a1a;
}

nav.mainnav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

nav.mainnav a {
  text-decoration: none;
  color: #333;
  padding: 4px 0;
}

nav.mainnav a.active {
  color: var(--brand-teal);
  font-weight: 600;
}

.logout-form {
  display: inline;
  margin: 0;
  padding: 0;
}

.link-button {
  background: none;
  border: none;
  padding: 4px 0;
  margin: 0;
  font: inherit;
  color: #333;
  cursor: pointer;
  text-decoration: none;
}

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

h1 {
  font-size: 1.4rem;
  margin: 0 0 16px;
}

h2 {
  font-size: 1.1rem;
  margin: 24px 0 10px;
  border-top: 1px solid #e5e5e5;
  padding-top: 16px;
}

.field {
  margin-bottom: 14px;
}

.field ul {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
}

.field ul li {
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}

.field ul li:last-child {
  border-bottom: none;
}

.field ul label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  font-size: 1rem;
  color: #1a1a1a;
}

.field ul input[type="checkbox"] {
  width: auto;
}

input:disabled {
  background: #f0f0f0;
  color: #666;
}

/* --- Chip select (Google-sharing-style multi/single pick from a list) --- */

.chip-select {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chip-select-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--brand-cyan-tint);
  color: var(--brand-teal);
  border-radius: 14px;
  padding: 6px 8px 6px 12px;
  font-size: 0.85rem;
  border: none;
}

.chip-remove {
  background: none;
  border: none;
  color: inherit;
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.chip-add {
  background: #eee;
  color: #444;
  border: 1px dashed #aaa;
  cursor: pointer;
  padding: 6px 12px;
}

.chip-link {
  text-decoration: none;
  padding: 8px 14px;
}

.chip-select-dropdown {
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  min-width: 200px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.chip-select-option {
  padding: 10px 12px;
  font-size: 0.95rem;
}

.chip-select-option:active {
  background: var(--brand-cyan-tint);
}

/* --- Photo sections (До/После on operations, photos on visits) --- */

.photo-section {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.photo-group {
  flex: 1;
  min-width: 130px;
}

.photo-group-label {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 6px;
}

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.photo-thumbs:empty {
  margin-bottom: 0;
}

.photo-thumbs img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e5e5e5;
  cursor: pointer;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.photo-upload-btn {
  display: inline-block;
  margin: 0;
  position: relative;
  overflow: hidden;
}

.photo-upload-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  cursor: pointer;
}

label {
  display: block;
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-family: inherit;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

button, .btn {
  display: inline-block;
  padding: 11px 18px;
  font-size: 16px;
  border: none;
  border-radius: 6px;
  background: var(--brand-teal);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

button:active, .btn:active {
  background: var(--brand-ink);
}

.btn.secondary {
  background: #eee;
  color: #1a1a1a;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-form input {
  flex: 1;
}

.list-item {
  display: block;
  padding: 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}

.list-item:hover {
  border-color: var(--brand-teal);
}

.list-item .name {
  font-weight: 600;
}

.list-item .meta {
  font-size: 0.85rem;
  color: #666;
  margin-top: 2px;
}

.card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.card .meta {
  font-size: 0.85rem;
  color: #666;
}

.empty {
  color: #888;
  font-style: italic;
  padding: 8px 0;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
}

.messages li {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  background: #fdecea;
  color: #7a1f14;
  font-size: 0.9rem;
}

.messages li.success {
  background: #e6f4ea;
  color: #1e4620;
}

.patient-header {
  margin-bottom: 4px;
}

.patient-header .iin {
  color: #666;
  font-weight: 400;
}

#calendar {
  background: #fff;
  border-radius: 8px;
  padding: 8px;
}

/* --- Swipe-to-delete + long-press --- */

.swipeable {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 10px;
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 88px;
  display: flex;
}

/* The red button only exists while a swipe is under way, so it never peeks out from behind the card. */
.swipeable .swipe-actions { visibility: hidden; }
.swipeable.swiping .swipe-actions,
.swipeable.swiped-open .swipe-actions { visibility: visible; }

.swipe-delete-btn {
  flex: 1;
  border-radius: 0;
  background: #d33;
  font-size: 0.85rem;
}

.swipe-content {
  position: relative;
  background: #fff;
  touch-action: pan-y;
  transition: transform 0.15s ease-out;
  margin-bottom: 0;
}

.swipe-content.card {
  margin-bottom: 0;
}

/* --- Long-press action sheet --- */

.action-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.action-sheet {
  background: #fff;
  width: 100%;
  border-radius: 14px 14px 0 0;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
}

.action-sheet-title {
  text-align: center;
  color: #888;
  font-size: 0.8rem;
  padding: 10px 0;
}

.action-sheet-btn {
  display: block;
  width: 100%;
  background: none;
  color: var(--brand-teal);
  padding: 14px;
  font-size: 1rem;
  border-top: 1px solid #eee;
}

.action-sheet-btn.danger {
  color: #d33;
}

/* --- Bottom tab bar (mobile) --- */

.bottom-nav {
  display: none;
}

.logout-icon-form {
  display: none;
}

@media (max-width: 640px) {
  header.topbar nav.mainnav {
    display: none;
  }

  .logout-icon-form {
    display: inline-block;
  }

  .logout-icon-form .link-button {
    font-size: 1.2rem;
    padding: 0;
  }

  body {
    padding-bottom: 76px;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #ddd;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-between;
    align-items: center;
    z-index: 50;
    /* Forces its own GPU compositing layer — without this, iOS Safari
       sometimes fails to paint a `position: fixed` element on initial
       load and only renders it after a tap/scroll triggers a repaint. */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
  }

  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: #666;
    text-decoration: none;
    font-size: 0.7rem;
    flex: 1;
  }

  .bottom-nav a.active {
    color: var(--brand-teal);
  }

  .bottom-nav .icon {
    font-size: 1.3rem;
    line-height: 1;
  }

  .bottom-nav .add-action {
    flex: 0 0 auto;
    margin-top: -28px;
  }

  .bottom-nav .add-action .icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--brand-teal);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    box-shadow: 0 2px 8px rgba(10, 88, 202, 0.4);
  }

  .bottom-nav .add-action span:last-child {
    color: #666;
  }
}

/* Photo archive (patient page) */
.archive-new { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.archive-new input, .archive-new select { width: auto; flex: 1 1 140px; }
.archive-path { word-break: break-word; }
.archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin: 10px 0; }
.archive-grid:empty { display: none; }
.archive-item { position: relative; display: block; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: #eee; }
.archive-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.archive-ph { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 12px; color: #777; text-align: center; padding: 4px; }
.archive-badge { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.archive-card { margin-top: 14px; padding-top: 12px; border-top: 1px solid #eee; }
.archive-card .archive-grid { margin-top: 8px; }
.archive-badge-left { right: auto; left: 6px; }

/* Examinations (осмотры) inside an operation card */
.exams { margin-top: 16px; padding-top: 12px; border-top: 1px solid #eee; }
.exams-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.exams-head form { margin: 0; }
.exam-item .card { background: #fafbfc; }

/* Upload sheet (new examination / add files) — iOS-style grouped sheet */
dialog.sheet { --ios-blue: #0b7fa3; --ios-green: #34c759; --ios-red: #ff3b30; --ios-gray: #8e8e93; --ios-fill: #f2f2f7; --ios-sep: rgba(60, 60, 67, .18);
  border: none; padding: 0; width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 48px); color: #1c1c1e;
  border-radius: 28px; background: rgba(255, 255, 255, .94); backdrop-filter: blur(28px) saturate(1.8); -webkit-backdrop-filter: blur(28px) saturate(1.8);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .28), 0 0 0 .5px rgba(0, 0, 0, .08); font-family: -apple-system, "SF Pro Text", system-ui, sans-serif; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .35); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
dialog.sheet[open] { animation: sheet-in .38s cubic-bezier(.32, .72, 0, 1); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px) scale(.97); } }
@media (max-width: 600px) {
  dialog.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 28px 28px 0 0; max-height: 94vh; }
  dialog.sheet[open] { animation-name: sheet-up; }
  @keyframes sheet-up { from { transform: translateY(100%); } }
}
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } .ring .arc, .ring .tick { transition: none; } }

.sheet-body { display: flex; flex-direction: column; gap: 18px; padding: 10px 20px 22px; max-height: inherit; overflow: auto; }
.sheet-grabber { align-self: center; width: 36px; height: 5px; border-radius: 3px; background: rgba(60, 60, 67, .3); margin-bottom: 2px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet-head h3 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.sheet-sub { margin: 3px 0 0; color: var(--ios-gray); font-size: 15px; }
.sheet-close { flex: none; width: 30px; height: 30px; padding: 0; border-radius: 50%; background: rgba(120, 120, 128, .16); color: #636366; font-size: 19px; line-height: 30px; }
.sheet-close:active { background: rgba(120, 120, 128, .3); }

.sheet-group { background: var(--ios-fill); border-radius: 14px; }
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 16px; min-height: 48px; }
.sheet-row span { font-size: 17px; }
.sheet-row input { width: auto; border: none; background: transparent; font: inherit; font-size: 17px; color: var(--ios-blue); text-align: right; padding: 8px 0; }

.dropzone { border-radius: 16px; padding: 22px 16px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; background: var(--ios-fill); transition: background .2s, transform .2s; }
.dropzone svg { width: 34px; height: 34px; color: var(--ios-blue); margin-bottom: 4px; }
.dropzone strong { font-size: 17px; font-weight: 600; color: var(--ios-blue); }
.dropzone span { color: var(--ios-gray); font-size: 14px; }
.dropzone.over { background: #dff3fa; transform: scale(1.01); }
.dropzone:active { background: #e5e5ea; }
.dropzone:focus-visible { outline: 3px solid rgba(0, 122, 255, .45); outline-offset: 2px; }

.sheet-summary { background: var(--ios-fill); border-radius: 14px; padding: 14px 16px 16px; }
.sheet-summary[hidden] { display: none; }
.sum-top { display: flex; align-items: baseline; justify-content: space-between; }
.sum-count { font-size: 17px; font-weight: 600; }
.sum-pct { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ios-blue); }
.sum-track { height: 6px; border-radius: 3px; background: rgba(120, 120, 128, .2); margin: 10px 0 8px; overflow: hidden; }
.sum-track i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--ios-blue); transition: width .25s cubic-bezier(.4, 0, .2, 1); }
.sum-sub { font-size: 13px; color: var(--ios-gray); font-variant-numeric: tabular-nums; }
.sheet-summary.is-done .sum-pct { color: var(--ios-green); }
.sheet-summary.is-done .sum-track i { background: var(--ios-green); }

.sheet-files { list-style: none; margin: 0; padding: 0; background: var(--ios-fill); border-radius: 14px; max-height: 36vh; overflow: auto; }
.sheet-files:empty { display: none; }
.sheet-file { display: grid; grid-template-columns: 44px 1fr 30px; gap: 12px; align-items: center; padding: 10px 14px 10px 12px; position: relative; }
.sheet-file + .sheet-file::before { content: ""; position: absolute; top: 0; left: 68px; right: 0; border-top: .5px solid var(--ios-sep); }
.sheet-file .thumb { width: 44px; height: 44px; border-radius: 9px; object-fit: cover; background: #e5e5ea; display: grid; place-items: center; color: var(--ios-gray); font-size: 17px; }
.sheet-file .name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-file .size { font-size: 13px; color: var(--ios-gray); font-variant-numeric: tabular-nums; }
.sheet-file.is-uploading .size { color: var(--ios-blue); }
.sheet-file.done .size { color: var(--ios-green); }
.sheet-file.failed .size { color: var(--ios-red); }

.ring { position: relative; width: 28px; height: 28px; }
.ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: rgba(120, 120, 128, .2); stroke-width: 3; }
.ring .arc { fill: none; stroke: var(--ios-blue); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 0 70; transition: stroke-dasharray .2s linear; }
.ring .remove { position: absolute; inset: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(120, 120, 128, .16); color: #636366; font-size: 17px; line-height: 28px; }
.ring .remove:active { background: rgba(120, 120, 128, .3); }
.ring .tick { position: absolute; inset: 0; width: 28px; height: 28px; border-radius: 50%; display: none; place-items: center; color: #fff; font-weight: 700; font-size: 15px; }
.sheet-file .track, .sheet-file .arc { display: none; }
.sheet-file.is-uploading .track, .sheet-file.is-uploading .arc { display: block; }
.sheet-file.is-uploading .remove, .sheet-file.done .remove, .sheet-file.failed .remove { display: none; }
.sheet-file.done .tick { display: grid; background: var(--ios-green); animation: pop .3s cubic-bezier(.3, 1.6, .5, 1); }
.sheet-file.failed .tick { display: grid; background: var(--ios-red); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

.sheet-file.is-skip .thumb { opacity: .45; }
.sheet-file.is-skip .name { color: var(--ios-gray); }
.sheet-file.is-skip .size { color: var(--ios-gray); }
.sheet-file.is-warn .size { color: #b25e00; }
.row-action { background: none; color: var(--ios-blue); padding: 2px 0 0; font-size: 13px; font-weight: 500; text-align: left; }
.row-action:active { background: none; opacity: .5; }
.row-action[hidden] { display: none; }
.sheet-error { margin: 0; color: var(--ios-red); font-size: 14px; }
.sheet-foot { display: flex; flex-direction: column; gap: 6px; }
.sheet-primary { position: relative; overflow: hidden; width: 100%; height: 52px; padding: 0 20px; border-radius: 15px; background: var(--ios-blue); color: #fff; font-size: 17px; font-weight: 600; letter-spacing: -.01em; transition: opacity .15s, background .25s; }
.sheet-primary:active { background: var(--ios-blue); opacity: .82; }
.sheet-primary .sheet-fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--p, 0) * 1%); background: rgba(255, 255, 255, .28); transition: width .25s cubic-bezier(.4, 0, .2, 1); }
.sheet-primary .sheet-label { position: relative; }
.sheet-primary:disabled { cursor: default; opacity: .55; }
.sheet-primary.is-busy:disabled { opacity: 1; cursor: progress; }
.sheet-primary.is-done, .sheet-primary.is-done:active { background: var(--ios-green); opacity: 1; }
.sheet-cancel { background: none; color: var(--ios-blue); height: 44px; padding: 0 12px; font-size: 17px; font-weight: 400; }
.sheet-cancel:active { background: none; opacity: .5; }

/* Examination header: date + how long after the operation */
.exam-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; line-height: 1.3; }
.pill-early { background: #fbe6d2; color: #8a4a10; }
.pill-mid { background: #d6f0f9; color: #0b6a8a; }
.pill-late { background: #d9f0e2; color: #1b6e3a; }

/* ===== Patient page (card layout) ===== */
body:has(.pd) { background: #eef5f8; }
.pd { --pd-blue: var(--brand-teal); --pd-ink: var(--brand-ink); --pd-mute: #5f7480; --pd-tint: var(--brand-cyan-tint); --pd-line: #e1eaee; color: var(--pd-ink); }
.pd-card { background: #fff; border-radius: 24px; padding: 18px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(30, 40, 90, .04), 0 10px 30px rgba(30, 40, 90, .07); }
.pd-hero-top { display: flex; gap: 14px; align-items: center; }
.pd-avatar { flex: none; width: 76px; height: 76px; border-radius: 22px; background: linear-gradient(145deg, #bfe8f5, #8fd3ea); color: var(--pd-blue); font-size: 32px; font-weight: 700; display: grid; place-items: center; }
.pd-hero-id { min-width: 0; }
.pd .patient-header { margin: 0 0 8px; font-size: 1.35rem; line-height: 1.2; word-break: break-word; }
.pd-copy { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--pd-tint); color: var(--pd-blue); font-size: 13px; font-weight: 600; }
.pd-copy:active { background: #c9ebf6; }
.pd-copy svg { width: 16px; height: 16px; }
.pd-facts { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.pd-facts li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.pd-facts svg { flex: none; width: 18px; height: 18px; margin-top: 2px; color: var(--pd-mute); }
.pd-facts em { font-style: normal; color: var(--pd-mute); }
.pd-facts a { color: var(--pd-blue); font-weight: 600; }
.pd-note { margin: 14px 0 0; padding: 10px 12px; border-radius: 14px; background: #fff7e6; color: #7a4b00; font-size: 14px; white-space: pre-line; }
.pd-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.pd-btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 12px; border-radius: 16px; background: #edf3f6; color: var(--pd-ink); font-weight: 600; font-size: 15px; text-decoration: none; }
.pd-btn svg { width: 18px; height: 18px; }
.pd-btn:active { background: #dde9ee; }
.pd-btn-primary { grid-column: 1 / -1; background: var(--pd-blue); color: #fff; padding: 15px; font-size: 16px; box-shadow: 0 8px 20px rgba(37, 99, 235, .3); }
.pd-btn-primary:active { background: var(--brand-ink); }
.pd-btn-wide { grid-column: 1 / -1; }
.pd-title { border: 0; margin: 22px 4px 10px; padding: 0; font-size: 1.15rem; }
.pd-op-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pd-date { color: var(--pd-mute); font-size: 14px; }
.pd-badge { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pd-badge-done { background: #dcf5e6; color: #15803d; }
.pd-badge-wait { background: #fbe6d2; color: #8a4a10; }
.pd-op-name { margin: 8px 0 6px; font-size: 1.25rem; line-height: 1.25; }
.pd-case { color: var(--pd-mute); font-weight: 600; }
.pd-surgeon { display: flex; align-items: center; gap: 8px; color: var(--pd-mute); font-size: 14px; }
.pd-surgeon svg { width: 17px; height: 17px; }
.pd-diag { display: inline-block; margin: 12px 0 0; padding: 8px 12px; border-radius: 14px; background: var(--pd-tint); color: var(--brand-teal); font-size: 14px; font-weight: 500; }
.pd-seg { display: flex; gap: 6px; margin-top: 14px; padding: 5px; border-radius: 18px; background: #edf3f6; }
.pd-seg a { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 10px 4px; border-radius: 14px; color: var(--pd-ink); font-size: 13px; white-space: nowrap; font-weight: 600; text-decoration: none; text-align: center; }
.pd-seg a:active { background: #fff; }
.pd-seg svg { width: 17px; height: 17px; flex: none; }
.pd-sub { margin: 20px 0 0; font-size: 1rem; }
.pd .archive-card { border-top: 0; margin-top: 4px; padding-top: 0; }
.pd .archive-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pd .archive-item { border-radius: 14px; }
.pd .archive-add { border-radius: 14px; padding: 10px 14px; background: var(--pd-tint); color: var(--pd-blue); border: 1.5px dashed var(--brand-cyan-line); }
.pd .exams { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--pd-line); }
.pd .exams-head { font-size: 1.05rem; }
.pd .exams-head small { margin-left: 6px; color: var(--pd-mute); font-weight: 600; font-size: .85rem; }
.pd .exam-item .card { background: #fff; border: 0; border-bottom: 1px solid var(--pd-line); border-radius: 0; padding: 12px 2px; margin: 0; }
.pd .exam-item:last-of-type .card { border-bottom: 0; }
.pd .exam-title .name { font-size: 1.05rem; font-weight: 700; }
.pd-add-exam { width: 100%; margin-top: 12px; padding: 14px; border-radius: 16px; background: var(--pd-tint); color: var(--pd-blue); font-size: 15px; font-weight: 600; }
.pd-add-exam:active { background: #c9ebf6; }
.pd form { margin: 0; }
.pd-content { margin-top: 10px; }
.pd-content .pd-sub small { margin-left: 6px; color: var(--pd-mute); font-weight: 500; font-size: .8rem; }
.pd button.pd-add-content { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: flex-start; gap: 6px; padding: 6px 0; font-size: 13px; font-weight: 600; background: none; border: 0; border-radius: 8px; color: var(--pd-mute); cursor: pointer; }
.pd button.pd-add-content:hover, .pd button.pd-add-content:active { background: none; color: var(--pd-blue); }

/* Header logo and brand accents */
header.topbar .brand { display: inline-flex; align-items: center; gap: 8px; }
header.topbar .brand-symbol { height: 30px; width: auto; display: block; }
header.topbar .brand-word { height: 22px; width: auto; display: block; }
nav.mainnav a.active { color: var(--brand-teal); }
header.topbar { border-bottom: 2px solid var(--brand-cyan); }
.bottom-nav a.active { color: var(--brand-teal); }
.bottom-nav a.active .icon { filter: none; }
@media (max-width: 640px) {
  .bottom-nav .add-action .icon { background: var(--brand-orange); color: var(--brand-ink); box-shadow: 0 2px 10px rgba(231, 150, 79, .5); }
}
.login-logo { display: block; margin: 8px auto 20px; height: 64px; width: auto; }
.pd-avatar { color: var(--brand-teal); }
.pd-btn-primary { box-shadow: 0 8px 20px rgba(0, 57, 75, .28); }
.pd-diag { color: var(--brand-teal); }
.pd-badge-wait { background: #fbe6d2; color: #8a4a10; }

/* Black-and-white lockup, shown only when the history is printed */
.print-logo { display: none; }
@media print { .print-logo { display: block; height: 70px; width: auto; margin: 0 0 12px; } header.topbar, .bottom-nav { display: none; } }

/* ===== Lucide icons, HTMX, Alpine, PhotoSwipe ===== */
.i { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.bottom-nav .icon .i { width: 1.3rem; height: 1.3rem; vertical-align: middle; }
.bottom-nav .add-action .icon .i { width: 1.7rem; height: 1.7rem; stroke-width: 2.2; }
.link-button .i { width: 1.35rem; height: 1.35rem; vertical-align: middle; }
.archive-badge .i { width: 12px; height: 12px; vertical-align: -2px; }
.archive-ph .i { width: 16px; height: 16px; margin-right: 3px; }
.chip .i, .archive-add .i { margin-right: 2px; }
[x-cloak] { display: none !important; }
.htmx-indicator { opacity: 0; transition: opacity .15s; pointer-events: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
body:has(.pl) { background: #eef5f8; }
.pswp-video { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.pswp-video video { max-width: 100%; max-height: 100%; }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* Avatar: tap to choose a photo from the archive */
.pd-avatar-btn { position: relative; padding: 0; border: 0; overflow: hidden; cursor: pointer; font: inherit; }
.pd-avatar-btn > span { font-size: 32px; font-weight: 700; }
.pd-avatar-btn img { width: 100%; height: 100%; object-fit: cover; object-position: center 25%; display: block; }
.pd-avatar-edit { position: absolute; right: 4px; bottom: 4px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-teal); color: #fff; box-shadow: 0 0 0 2px #fff; }
.pd-avatar-edit .i { width: 13px; height: 13px; }
.avatar-group { margin: 14px 4px 8px; font-size: 14px; color: #5f7480; font-weight: 600; }
.avatar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 4px; }
.avatar-pick { padding: 0; border: 0; border-radius: 14px; overflow: hidden; aspect-ratio: 1; background: #edf3f6; cursor: pointer; position: relative; }
.avatar-pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-pick.is-current { outline: 3px solid var(--brand-cyan); outline-offset: -3px; }
.avatar-pick:active { opacity: .7; }
.avatar-empty { margin: 18px 8px; color: #5f7480; font-size: 15px; }
dialog.sheet .sheet-body { max-height: calc(100vh - 48px); overflow-y: auto; }

/* ===== Unified look for every staff page: same cards, fields, date buttons and buttons as the patient card ===== */
body { background: #eef5f8; }
main > h1 { font-size: 1.5rem; font-weight: 700; color: var(--brand-ink); margin: 4px 4px 16px; }
main > h2, main > form > h2 { border-top: 0; margin: 24px 0 10px; padding-top: 0; font-size: 1.05rem; font-weight: 700; color: var(--brand-ink); }
main > form > h2:first-of-type { margin-top: 0; }
main > .meta, .meta { color: #5f7480; }
main > p.meta { margin: -8px 4px 14px; }

/* forms become white cards */
main > form:not(.plain-form):not(.search-form):not(.logout-form), main > .card-block {
  background: #fff; border-radius: 24px; padding: 18px; margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0, 57, 75, .05), 0 10px 30px rgba(0, 57, 75, .08);
}
main > form.field { margin-bottom: 14px; }
main > form.plain-form { text-align: center; margin: 4px 0 14px; }
main > form.plain-form .link-button { color: #b3261e; font-weight: 600; }

label { font-size: 13px; font-weight: 600; color: #5f7480; margin-bottom: 6px; }
input, select, textarea {
  padding: 13px 14px; border: 1px solid #dde9ee; border-radius: 14px; background: #f5f9fb; color: var(--brand-ink);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, select:focus, textarea:focus { outline: 0; background: #fff; border-color: var(--brand-cyan); box-shadow: 0 0 0 3px rgba(34, 175, 219, .22); }
input::placeholder, textarea::placeholder { color: #94a8b2; }
input:disabled { background: #eaf0f3; color: #6f8590; }
input[type="checkbox"], input[type="radio"] { width: auto; }

/* date, time and select fields look like the card's buttons */
input[type="date"], input[type="time"], input[type="datetime-local"], select {
  -webkit-appearance: none; appearance: none; position: relative; min-height: 50px; padding-right: 44px;
  background-color: var(--brand-cyan-tint); border-color: transparent; color: var(--brand-teal); font-weight: 600;
  background-repeat: no-repeat; background-position: right 14px center; background-size: 20px 20px;
}
input[type="date"], input[type="datetime-local"] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300394B' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v4M16 2v4'/%3E%3Crect x='3' y='4' width='18' height='18' rx='3'/%3E%3Cpath d='M3 10h18'/%3E%3C/svg%3E"); }
input[type="time"] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300394B' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 6v6l4 2'/%3E%3C/svg%3E"); }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300394B' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
input[type="date"]::-webkit-calendar-picker-indicator, input[type="time"]::-webkit-calendar-picker-indicator, input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="date"]:disabled, input[type="time"]:disabled { background-color: #eaf0f3; color: #6f8590; }
input[type="date"]:focus, input[type="time"]:focus, select:focus { background-color: #fff; border-color: var(--brand-cyan); }

/* buttons */
button, .btn { padding: 14px 20px; border-radius: 16px; font-weight: 600; }
main > form > button[type="submit"], main > form .actions .btn, main > form .actions button { min-height: 50px; }
main > form > button[type="submit"] { width: 100%; margin-top: 6px; box-shadow: 0 8px 20px rgba(0, 57, 75, .25); }
.btn.secondary { background: #edf3f6; color: var(--brand-ink); box-shadow: none; }
.btn.secondary:active { background: #dde9ee; }
.actions .btn, .actions button { flex: 1; }

/* chips */
.chip { border-radius: 999px; padding: 8px 14px 8px 14px; font-size: 14px; font-weight: 600; }
.chip-link { padding: 10px 16px; }
.chip-add { background: var(--brand-cyan-tint); color: var(--brand-teal); border: 1.5px dashed var(--brand-cyan-line); }
.chip-select-dropdown { border: 0; border-radius: 16px; box-shadow: 0 12px 32px rgba(0, 57, 75, .18); padding: 4px; }
.chip-select-option { border-radius: 12px; }

/* cards, lists, messages */
.card { border: 0; border-radius: 20px; padding: 14px; box-shadow: 0 1px 2px rgba(0, 57, 75, .05), 0 8px 24px rgba(0, 57, 75, .07); }
.list-item { border: 0; border-radius: 20px; box-shadow: 0 1px 2px rgba(0, 57, 75, .05), 0 8px 24px rgba(0, 57, 75, .07); }
.empty { color: #5f7480; font-style: normal; }
.messages { margin: 0 0 14px; padding: 0; list-style: none; }
.messages li { border-radius: 16px; padding: 12px 16px; }

/* calendar */
#calendar { border-radius: 24px; padding: 14px; box-shadow: 0 1px 2px rgba(0, 57, 75, .05), 0 10px 30px rgba(0, 57, 75, .08); }
.fc { --fc-button-bg-color: #00394B; --fc-button-border-color: #00394B; --fc-button-hover-bg-color: #04232C; --fc-button-hover-border-color: #04232C;
  --fc-button-active-bg-color: #04232C; --fc-button-active-border-color: #04232C; --fc-border-color: #e1eaee; --fc-today-bg-color: #e3f4fa;
  --fc-neutral-bg-color: #edf3f6; --fc-list-event-hover-bg-color: #f1f7fa; --fc-event-bg-color: #22AFDB; --fc-event-border-color: #22AFDB; }
.fc .fc-button { border-radius: 12px; padding: 8px 12px; }
.fc .fc-button-group > .fc-button:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.fc .fc-button-group > .fc-button:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.fc .fc-toolbar-title { font-size: 1.25em; color: var(--brand-ink); }
.fc-theme-standard .fc-list { border-radius: 16px; overflow: hidden; border-color: #e1eaee; }
.fc .fc-list-day-cushion { font-weight: 700; color: var(--brand-ink); }
.fc .fc-list-event-title a { color: var(--brand-ink); font-weight: 500; }
.fc .fc-toolbar-title { border: 0; padding: 0; margin: 0; }
.fc .fc-list-event-dot { border-width: 5px; }
@media (max-width: 640px) {
  .fc .fc-header-toolbar { flex-wrap: wrap; gap: 10px; }
  .fc .fc-toolbar-chunk:nth-child(2) { order: -1; flex-basis: 100%; }
  .fc .fc-toolbar-title::first-letter { text-transform: uppercase; }
  .fc .fc-direction-ltr .fc-toolbar > * > :not(:first-child) { margin-left: 0; }
}

/* Header tools: notifications and profile */
header.topbar { flex-wrap: nowrap; }
.tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.tool { position: relative; }
.tool-btn { position: relative; width: 42px; height: 42px; padding: 0; border-radius: 50%; background: #edf3f6; color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.tool-btn:active { background: #dde9ee; }
.tool-btn .i { width: 20px; height: 20px; }
.tool-avatar { background: var(--brand-teal); color: #fff; letter-spacing: .02em; }
.tool-avatar:active { background: var(--brand-ink); }
.tool-dot { position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand-orange); color: var(--brand-ink); font-size: 11px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 0 0 2px #fff; }
.tool-panel { position: absolute; right: 0; top: calc(100% + 10px); width: min(330px, calc(100vw - 24px)); background: #fff; border-radius: 22px; padding: 8px; box-shadow: 0 16px 44px rgba(0, 57, 75, .22), 0 0 0 1px rgba(0, 57, 75, .06); z-index: 80; }
.tool-title { padding: 10px 12px 6px; font-weight: 700; color: var(--brand-ink); }
.tool-item { display: flex; gap: 12px; padding: 10px 12px; border-radius: 14px; text-decoration: none; color: var(--brand-ink); }
.tool-item:active, .tool-all:active { background: #edf3f6; }
.tool-when { flex: none; width: 62px; font-size: 12px; font-weight: 700; color: var(--brand-teal); line-height: 1.35; }
.tool-text { min-width: 0; display: grid; }
.tool-text b { font-size: 15px; }
.tool-text small { color: #5f7480; font-size: 13px; }
.tool-empty { margin: 0; padding: 10px 12px 14px; color: #5f7480; font-size: 14px; }
.tool-all { display: block; margin-top: 4px; padding: 12px; border-radius: 14px; text-align: center; font-weight: 600; text-decoration: none; color: var(--brand-teal); border-top: 1px solid #e1eaee; }
.tool-profile { width: 230px; }
.tool-name { padding: 10px 12px 0; font-weight: 700; color: var(--brand-ink); }
.tool-sub { padding: 0 12px 8px; color: #5f7480; font-size: 13px; }
.tool-profile form { margin: 0; }
.tool-logout { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; border-radius: 14px; background: #fdecea; color: #b3261e; font-size: 15px; }
.tool-logout:active { background: #f7d6d2; }

.filter-select { font-weight: 600; }
.pl input[type="radio"] { width: auto; padding: 0; }

/* Period dialog on the patient list */
.range-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.range-grid input { width: 100%; min-width: 0; padding-left: 12px; }
.range-grid label { margin: 0; }
.range-grid label span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: #5f7480; }
.range-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.range-quick button { padding: 12px 4px; border-radius: 14px; background: #edf3f6; color: var(--brand-ink); font-size: 15px; font-weight: 600; }
.range-quick button:active { background: #dde9ee; }
.range-quick button.is-on { background: var(--brand-teal); color: #fff; }
@media (max-width: 380px) { .range-quick { grid-template-columns: 1fr 1fr; } }

/* Keep every page from sliding sideways on phones. The clip sits on <main>, never on html/body:
   overflow rules on those break position: fixed bars in iOS Safari. */
html { overscroll-behavior-x: none; }
body { max-width: 100%; touch-action: pan-y pinch-zoom; }
main { overflow-x: clip; }
main, main > form, .field { min-width: 0; max-width: 100%; }
input, select, textarea { min-width: 0; max-width: 100%; }
.field input[type="date"], .field input[type="time"], .field input[type="datetime-local"] { display: block; -webkit-min-logical-width: calc(100% - 16px); }
textarea { display: block; }

/* Manrope everywhere in the staff app */
button, input, select, textarea { font-family: inherit; }
dialog.sheet { font-family: inherit; }

/* ===== Phone app shell: header + scrolling middle + bottom navigation that cannot leave the screen ===== */
@media (max-width: 640px) {
  html, body { height: 100%; }
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; padding-bottom: 0; }
  header.topbar { flex: none; position: relative; z-index: 60; }
  .app-scroll { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
  .bottom-nav { position: relative; flex: none; left: auto; right: auto; bottom: auto; z-index: 50; transform: none; -webkit-transform: none; will-change: auto; }
}


/* ===== Desktop: dark sidebar, search bar on top, content centred with a width limit ===== */
.sidebar, .topsearch { display: none; }
main { max-width: 820px; }
main.main-wide { max-width: 1320px; }
@media (min-width: 1024px) {
  body.has-sidebar { display: grid; grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; }
  .sidebar { display: flex; flex-direction: column; grid-column: 1; grid-row: 1 / 3; position: sticky; top: 0; height: 100vh; padding: 22px 14px 16px;
    background: var(--brand-ink); color: #fff; }
  .side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 26px; color: #fff; text-decoration: none; font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
  .side-brand { padding: 2px 10px 24px; }
  .side-brand img { display: block; width: 100%; max-width: 190px; height: auto; }
  .side-nav { display: grid; gap: 6px; }
  .side-nav a { display: flex; align-items: center; gap: 14px; padding: 13px 16px; border-radius: 14px; color: rgba(255, 255, 255, .78); text-decoration: none; font-size: 16px; font-weight: 600; }
  .side-nav a .i { width: 22px; height: 22px; }
  .side-nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
  .side-nav a.active { background: var(--brand-teal); color: #fff; box-shadow: inset 3px 0 0 var(--brand-cyan); }
  .side-user { margin-top: auto; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px; background: rgba(255, 255, 255, .07); }
  .side-avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-cyan); color: var(--brand-ink); font-weight: 800; font-size: 14px; }
  .side-who { min-width: 0; display: grid; flex: 1; }
  .side-who b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side-who small { color: rgba(255, 255, 255, .6); font-size: 13px; }
  .side-user form { margin: 0; }
  .side-logout { padding: 8px; width: 36px; height: 36px; border-radius: 10px; background: transparent; color: rgba(255, 255, 255, .7); display: grid; place-items: center; }
  .side-logout:hover { background: rgba(255, 255, 255, .12); color: #fff; }
  .side-logout .i { width: 20px; height: 20px; }

  body.has-sidebar header.topbar { grid-column: 2; grid-row: 1; position: sticky; top: 0; z-index: 60; padding: 14px 32px; gap: 20px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px); border-bottom: 1px solid #e1eaee; }
  body.has-sidebar header.topbar .brand, body.has-sidebar nav.mainnav { display: none; }
  .topsearch { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 640px; padding: 0 14px; height: 46px; border-radius: 14px; background: #f5f9fb; border: 1px solid #dde9ee; color: #5f7480; }
  .topsearch:focus-within { background: #fff; border-color: var(--brand-cyan); box-shadow: 0 0 0 3px rgba(34, 175, 219, .22); }
  .topsearch input { border: 0; background: transparent; box-shadow: none; padding: 0; height: 100%; font-size: 15px; }
  .topsearch input:focus { box-shadow: none; background: transparent; }
  .topsearch kbd { flex: none; padding: 3px 8px; border-radius: 8px; background: #e6eef2; color: #5f7480; font: 600 12px/1.3 inherit; font-family: inherit; }
  body.has-sidebar .app-scroll { grid-column: 2; grid-row: 2; }
  body.has-sidebar main { padding: 28px 36px 56px; }
  body.has-sidebar .bottom-nav { display: none; }
  .tools { margin-left: auto; }
}

/* Photo grid actions: full-width add button, small quiet round refresh at the right */
.pd .archive-card { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pd .archive-path, .pd .archive-grid { flex: 1 0 100%; margin: 0; }
.pd .archive-add { flex: 1 0 100%; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; font-size: 15px; }
.pd .archive-status { order: 4; flex: 1 1 0; min-width: 0; margin: 0; font-size: 13px; }
.pd .archive-refresh { order: 5; margin: 0 0 0 auto; width: 30px; height: 30px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: transparent; color: #94a8b2; box-shadow: none; }
.pd .archive-refresh:hover { background: #edf3f6; color: var(--brand-teal); }
.pd .archive-refresh:active { background: #dde9ee; }
.pd .archive-refresh .i { width: 16px; height: 16px; margin: 0; }

/* Refresh feedback: quiet light-grey message on the left, icon spins while loading */
.pd .archive-status { color: #a9b8c0; }
.pd .archive-status.is-error { color: #a9b8c0; }
.archive-card.is-refreshing .archive-refresh { pointer-events: none; color: var(--brand-cyan); }
.archive-card.is-refreshing .archive-refresh .i { animation: spin .8s linear infinite; }

/* ===== Hover highlights for mouse/trackpad (not applied on touch screens) ===== */
@media (hover: hover) {
  button, .btn, .chip, .pd-btn, .pd-seg a, .tool-btn, .tool-item, .tool-all, .range-quick button, .avatar-pick, .archive-item, a.list-item {
    transition: background-color .15s, color .15s, box-shadow .15s, border-color .15s, opacity .15s, transform .15s;
  }
  main > form > button[type="submit"]:hover, .btn:not(.secondary):hover, .pd-btn-primary:hover { background: var(--brand-ink); box-shadow: 0 10px 24px rgba(0, 57, 75, .32); }
  .btn.secondary:hover, .pd-btn:not(.pd-btn-primary):hover { background: #dde9ee; }
  .chip:hover { background: #cdebf6; }
  .chip-add:hover { background: #d3eef8; border-color: var(--brand-cyan); }
  .chip-remove:hover { background: none; color: #b3261e; }
  .pd-seg a:hover { background: #fff; box-shadow: 0 2px 8px rgba(0, 57, 75, .12); }
  .pd-add-exam:hover, .pd .archive-add:hover { background: #cdebf6; border-color: var(--brand-cyan); }
  .pd-copy:hover { background: #cdebf6; }
  .pd-avatar-btn:hover img, .pd-avatar-btn:hover > span:not(.pd-avatar-edit) { filter: brightness(.92); }
  .pd-avatar-btn:hover .pd-avatar-edit { transform: scale(1.12); }
  .pd-facts a:hover { text-decoration: underline; }
  .avatar-pick:hover { transform: scale(1.04); box-shadow: 0 4px 14px rgba(0, 57, 75, .25); }
  .archive-item:hover { opacity: .88; transform: scale(1.02); }
  .range-quick button:hover { background: #dde9ee; }
  .range-quick button.is-on:hover { background: var(--brand-ink); }
  .tool-btn:hover { background: #dde9ee; }
  .tool-avatar:hover { background: var(--brand-ink); }
  .tool-item:hover, .tool-all:hover { background: #edf3f6; }
  .tool-logout:hover { background: #f7d6d2; }
  .sheet-primary:hover { opacity: .9; }
  .sheet-cancel:hover { opacity: .65; background: none; }
  .sheet-close:hover { background: rgba(120, 120, 128, .3); }
  .chip-select-option:hover { background: var(--brand-cyan-tint); cursor: pointer; }
  nav.mainnav a:hover { color: var(--brand-teal); }
  a.list-item:hover { box-shadow: 0 6px 20px rgba(0, 57, 75, .14); }
  .fc-list-event:hover td { background-color: #eaf6fb; }
  .swipe-delete-btn:hover { filter: brightness(.92); }
}

/* Date picker on the home page: a fixed-size pill with the date as plain text; the real input is an invisible layer on top,
   so the pill never changes width while the browser renders its own date widget (this is what made it drift on phones). */
.date-pill { overflow: hidden; }
input.date-overlay { position: absolute; inset: 0; width: 100%; height: 100%; min-width: 0; min-height: 0; margin: 0; padding: 0; border: 0;
  opacity: 0; background: transparent; cursor: pointer; -webkit-appearance: none; appearance: none; font-size: 16px; -webkit-min-logical-width: 0; }
input.date-overlay::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* Archive folder path under "Фото и видео": present, but small and quiet */
.pd .archive-path { font-size: 10.5px; line-height: 1.35; color: #a9b8c0; margin: -2px 0 0; word-break: break-all; }
.pd .archive-path .i { width: 11px; height: 11px; margin-right: 2px; vertical-align: -1px; }

/* Suggestions from the TickTick plan under the ФИО field, and the note on the new-operation form */
.plan-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.plan-chips[hidden] { display: none; }
.plan-caption { font-size: 13px; font-weight: 600; color: #5f7480; flex: 1 0 100%; }
.plan-chip { padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; line-height: 1.25; text-align: left; box-shadow: none; border: 1.5px solid transparent; }
.plan-eyes { background: #d6f0f9; color: #0b6a8a; }
.plan-nose { background: #d7efe6; color: #0f6b55; }
.plan-face { background: #e1e7fb; color: #33449a; }
.plan-breast { background: #fbe6d2; color: #8a4a10; }
.plan-body { background: #eadcf7; color: #5b2f86; }
.plan-other { background: #e6eef2; color: #3d5560; }
.plan-chip.is-on { border-color: currentColor; box-shadow: 0 0 0 3px rgba(0, 57, 75, .12); }
.plan-note { display: grid; gap: 4px; margin: 0 0 14px; padding: 14px 16px; border-radius: 18px; background: var(--brand-cyan-tint); color: var(--brand-teal); font-size: 14px; }
.plan-note em { font-style: normal; font-weight: 700; }
.plan-note small { color: #5f7480; }
@media (hover: hover) { .plan-chip:hover { filter: brightness(.96); border-color: currentColor; } }

/* --- Upload dock: running upload minimised into a corner pill --- */
.dock { position: fixed; z-index: 90; left: 12px; right: 12px; bottom: calc(86px + env(safe-area-inset-bottom)); display: flex; align-items: stretch; max-width: 360px; margin: 0 auto;
  background: #fff; border: 1px solid #dde9ee; border-radius: 18px; box-shadow: 0 10px 30px rgba(7, 30, 40, .18); overflow: hidden; }
.dock[hidden], .dock.is-hidden { display: none; }
.dock-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: none; text-align: left; color: var(--brand-ink, #0b2a36); }
.dock-ring { position: relative; flex: none; width: 34px; height: 34px; display: grid; place-items: center; }
.dock-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.dock-ring .t { fill: none; stroke: #e1eaee; stroke-width: 3; }
.dock-ring .a { fill: none; stroke: var(--brand-cyan, #22afdb); stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray .25s; }
.dock-glyph { position: relative; font-size: 15px; font-weight: 800; }
.dock[data-state="done"] .a { stroke: #34c759; } .dock[data-state="done"] .dock-glyph { color: #34c759; }
.dock[data-state="failed"] .a { stroke: #ff3b30; } .dock[data-state="failed"] .dock-glyph { color: #ff3b30; }
.dock[data-state="uploading"] .dock-ring::after { content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-cyan, #22afdb); animation: dock-pulse 1.2s ease-in-out infinite; }
@keyframes dock-pulse { 50% { transform: scale(.4); opacity: .4; } }
.dock-text { display: grid; min-width: 0; }
.dock-title { font-size: 15px; font-weight: 700; line-height: 1.25; }
.dock-sub { font-size: 12.5px; color: #5f7480; line-height: 1.25; }
.dock-close { flex: none; width: 40px; background: none; color: #8aa0ab; font-size: 22px; }
@media (min-width: 1024px) { .dock { left: auto; right: 24px; bottom: 24px; margin: 0; width: 340px; } }
@media (prefers-reduced-motion: reduce) { .dock-ring::after { animation: none !important; } }

.pd-back { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 12px -4px; padding: 6px 12px 6px 6px; border-radius: 12px; color: var(--brand-teal); font-weight: 700; font-size: 15px; text-decoration: none; }
.pd-back .i { width: 20px; height: 20px; }
@media (hover: hover) { .pd-back:hover { background: var(--brand-cyan-tint); } }
.dock-close[hidden] { display: none; }

/* Clinic tag on an operation card: a small pill that is also the dropdown to change it. */
.pd-clinic { margin: 0 0 10px; }
.pd-clinic label { position: relative; display: inline-block; cursor: pointer; }
.pd-clinic-tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; background: var(--brand-cyan-tint); color: var(--brand-teal); font-size: 13px; font-weight: 700; }
.pd-clinic-tag::after { content: "▾"; font-size: 10px; opacity: .6; }
.pd-clinic select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
@media (hover: hover) { .pd-clinic label:hover .pd-clinic-tag { background: #cdebf6; } }

/* --- Loading feedback: top bar, soft page entrance, dimmed live list --- */
.topbar-progress { position: fixed; z-index: 200; top: 0; left: 0; right: 0; height: 3px; pointer-events: none; opacity: 0; transition: opacity .25s ease; }
.topbar-progress.is-on { opacity: 1; }
.topbar-progress i { display: block; height: 100%; transform-origin: left center; transform: scaleX(0); transition: transform .25s ease-out;
  background: linear-gradient(90deg, var(--brand-cyan), var(--brand-orange)); border-radius: 0 3px 3px 0; box-shadow: 0 0 8px rgba(34, 175, 219, .55); }
.topbar-progress.is-done { opacity: 0; transition-delay: .12s; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }
.app-scroll > main { animation: page-in .28s ease-out backwards; }
#results { transition: opacity .15s ease; }
#filters.htmx-request ~ #results, #filters.htmx-request + #results { opacity: .55; }
@media (prefers-reduced-motion: reduce) {
  .app-scroll > main { animation: none; }
  .topbar-progress i, .topbar-progress { transition: none; }
}

/* Download menu inside the photo/video viewer */
.pswp-dl-menu { position: absolute; top: 56px; right: 10px; z-index: 100; min-width: 230px; padding: 6px; border-radius: 16px; background: #fff; box-shadow: 0 12px 32px rgba(0, 0, 0, .35); }
.pswp-dl-menu a { display: flex; align-items: baseline; justify-content: space-between; gap: 18px; padding: 12px 14px; border-radius: 11px; color: #16303c; font-size: 15px; font-weight: 600; text-decoration: none; }
.pswp-dl-menu a:hover, .pswp-dl-menu a:active { background: #e8f6fb; }
.pswp-dl-menu small { color: #6a7f8a; font-size: 13px; font-weight: 500; white-space: nowrap; }
.pswp-dl-toast { position: absolute; left: 50%; bottom: 28px; z-index: 101; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 11px 18px; border-radius: 999px; background: rgba(255, 255, 255, .96); color: #16303c; font-size: 15px; font-weight: 600; text-align: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.pswp-dl-save { padding: 6px; }
.pswp-dl-save button { display: block; padding: 11px 22px; border: 0; border-radius: 999px; background: var(--brand-teal, #0e7c9a); color: #fff; font-size: 16px; font-weight: 700; }
button.htmx-request > svg.i { animation: spin 1s linear infinite; }
.archive-folder { position: absolute; top: 6px; left: 6px; max-width: calc(100% - 12px); padding: 1px 7px; overflow: hidden; border-radius: 10px; background: rgba(255, 255, 255, .88); color: #16303c; font-size: 11px; font-weight: 600; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
