/* ==========================================================================
   Запись на плановые операции — оформление
   ========================================================================== */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #0f766e;
  --primary-600: #0d9488;
  --primary-soft: #ccfbf1;
  --today: #2563eb;
  --today-glow: rgba(37, 99, 235, .22);
  --accent: #4f46e5;
  --danger: #dc2626;
  --ok: #047857;
  --warn: #92400e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .14);

  /* Уровни загрузки дня */
  --lvl-empty: #cbd5e1;
  --lvl-low: #10b981;
  --lvl-mid: #f59e0b;
  --lvl-high: #f97316;
  --lvl-full: #ef4444;
  --track: #e2e8f0;

  /* Дни недели — как в бумажном журнале: пн синий, вт розовый, ср белый, чт красный, пт оранжевый */
  --wd0: #eef2ff; --wd0-head: #c7d2fe;
  --wd1: #fdf2f8; --wd1-head: #f5c6e3;
  --wd2: #ffffff; --wd2-head: #e2e8f0;
  --wd3: #fef2f2; --wd3-head: #fecaca;
  --wd4: #fff7ed; --wd4-head: #fed7aa;
  --wd5: #f1f5f9; --wd5-head: #d8dee8;
  --wd6: #f1f5f9; --wd6-head: #d8dee8;
  font-size: 15px;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0 0 .8rem; letter-spacing: .01em; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.inline { display: inline; margin: 0; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: var(--c, var(--lvl-empty)); flex: none; }

/* --- Верхняя панель ------------------------------------------------------ */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1.2rem;
  padding: .6rem 1.25rem;
  background: linear-gradient(110deg, #0b3b4a 0%, #0f766e 55%, #1e3a8a 130%);
  color: #fff; position: sticky; top: 0; z-index: 40;
  box-shadow: 0 2px 12px rgba(2, 6, 23, .25);
}
.topbar a { color: #fff; text-decoration: none; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255, 255, 255, .16); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}
.brand-mark svg { fill: #fff; stroke: none; width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.1; }
.brand-text small { font-weight: 400; opacity: .7; font-size: .75rem; }
.nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.nav a {
  display: inline-flex; align-items: center; gap: .4rem; padding: .42rem .7rem; border-radius: 9px;
  opacity: .85; font-size: .93rem; transition: background .15s, opacity .15s;
}
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.nav a.is-active { opacity: 1; background: rgba(255, 255, 255, .2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.search {
  flex: 1; min-width: 200px; max-width: 340px; display: flex; align-items: center; gap: .4rem;
  background: rgba(255, 255, 255, .14); border-radius: 10px; padding: 0 .6rem;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
}
.search svg { opacity: .8; }
.search input { background: transparent; border: 0; color: #fff; padding: .45rem 0; width: 100%; font: inherit; outline: none; }
.search input::placeholder { color: rgba(255, 255, 255, .7); }
.btn--new { background: #fff !important; color: var(--primary) !important; border-color: #fff !important; font-weight: 600; }
.who { position: relative; margin-left: auto; }
.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: #fde68a; color: #78350f; font-weight: 700; font-size: .85rem; cursor: default;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .5);
}
.who-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; display: none; flex-direction: column; gap: .15rem;
  background: var(--surface); color: var(--text); border-radius: 12px; padding: .6rem; box-shadow: var(--shadow-lg);
}
.who-menu::before { content: ""; position: absolute; inset: -10px 0 auto 0; height: 10px; }
.who:hover .who-menu, .who:focus-within .who-menu { display: flex; }
.who-menu b { padding: .3rem .5rem 0; }
.who-login { padding: 0 .5rem .5rem; color: var(--muted); font-size: .8rem; border-bottom: 1px solid var(--line); margin-bottom: .2rem; }
.who-menu a, .who-menu .link { color: var(--text) !important; padding: .4rem .5rem; border-radius: 8px; text-align: left; text-decoration: none; }
.who-menu a:hover, .who-menu .link:hover { background: var(--surface-2); }
.who-menu form { margin: 0; }
.link { background: none; border: 0; color: inherit; cursor: pointer; padding: 0; font: inherit; width: 100%; }

.page { padding: 1.25rem; max-width: 1600px; margin: 0 auto; }

/* --- Сообщения ----------------------------------------------------------- */
.messages {
  list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem;
  position: fixed; right: 1rem; bottom: 1rem; z-index: 70; width: min(440px, calc(100vw - 2rem));
}
.msg { position: relative; padding-right: 2.2rem !important; box-shadow: var(--shadow-lg); animation: toast-in .25s ease-out; transition: opacity .4s, transform .4s; }
.msg.is-leaving { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.msg-close { position: absolute; top: .35rem; right: .45rem; border: 0; background: none; color: inherit; font-size: 1.2rem; cursor: pointer; opacity: .6; line-height: 1; }
.msg-close:hover { opacity: 1; }
.msg { padding: .7rem 1rem; border-radius: 12px; background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.msg--success { background: #ecfdf5; color: var(--ok); border-color: #a7f3d0; }
.msg--error { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.msg--warning { background: #fffbeb; color: var(--warn); border-color: #fde68a; }

/* --- Кнопки -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem .95rem; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s, box-shadow .15s, transform .05s;
}
.btn:hover { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; box-shadow: none; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-600); }
.btn--ghost { background: var(--surface); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger-ghost { color: var(--danger); background: transparent; margin-left: auto; border-color: #fecaca; }
.btn--small { padding: .25rem .6rem; font-size: .85rem; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--text); transition: all .15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }

/* --- Заголовок страницы -------------------------------------------------- */
.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: 1rem; }
.hero-nav { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.hero h1 { min-width: 10rem; text-align: center; font-size: 1.75rem; }
.hero h1 span { color: var(--muted); font-weight: 500; }
.hero-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.hero-stat { color: var(--muted); margin-left: .4rem; }
.hero-stat b { color: var(--text); }

.live-banner {
  position: sticky; top: calc(var(--topbar-h, 64px) + 8px); z-index: 30; display: flex; gap: 1rem; align-items: center;
  padding: .6rem 1rem; margin-bottom: .8rem; border-radius: 12px; background: #fffbeb; color: var(--warn);
  border: 1px solid #fde68a; box-shadow: var(--shadow);
}
.live-banner[hidden] { display: none; }

/* --- Карточки сводки ----------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; margin-bottom: 1rem; }
.kpi {
  background: var(--surface); border-radius: var(--radius); padding: .9rem 1.1rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .1rem; position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, rgba(15, 118, 110, .12), transparent 70%);
}
.kpi--ring { flex-direction: row; align-items: center; gap: .9rem; }
.kpi--ring > div { display: flex; flex-direction: column; gap: .15rem; }
.kpi-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.kpi-value--ok { color: var(--ok); }
.kpi-value--date { font-size: 1.45rem; padding: .2rem 0; }
.kpi-sub { color: var(--muted); font-size: .85rem; }

/* --- Кольцо загрузки ----------------------------------------------------- */
.ring {
  --size: 40px; --lvl: var(--lvl-empty);
  width: var(--size); height: var(--size); border-radius: 50%; flex: none; position: relative;
  display: flex; align-items: baseline; justify-content: center; padding-top: calc(var(--size) / 2 - .5rem);
  background: conic-gradient(var(--lvl) calc(var(--p, 0) * 1%), var(--track) 0);
  font-size: .78rem; line-height: 1; letter-spacing: -.02em;
}
.ring::before { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--surface); }
.ring > * { position: relative; }
.ring b { font-size: .88rem; }
.ring small { color: var(--muted); font-size: .64rem; }
.cal-top .ring { --size: 48px; }
.cal-top .ring::before { inset: 5px; }
.ring--lg { --size: 64px; }
.ring--lg::before { inset: 6px; }
.ring--lg b { font-size: 1rem; }
.ring--xs { --size: 18px; }
.ring--xs::before { inset: 3px; }
.lvl-low { --lvl: var(--lvl-low); }
.lvl-mid { --lvl: var(--lvl-mid); }
.lvl-high { --lvl: var(--lvl-high); }
.lvl-full { --lvl: var(--lvl-full); }
.lvl-empty, .lvl-closed { --lvl: var(--lvl-empty); }

/* --- Календарь ----------------------------------------------------------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1rem; align-items: start; margin-bottom: 1rem; }
@media (max-width: 1100px) { .cal-layout { grid-template-columns: 1fr; } }
.cal-card { padding: .8rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; }
.cal-head { text-align: center; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; padding: .2rem 0; }
.cal-head--weekend { color: #b45309; }
.cal-day {
  position: relative; min-height: 124px; padding: .55rem .6rem; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: .45rem;
  transition: transform .12s, box-shadow .12s, border-color .12s; outline: none;
}
.cal-day::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; border-radius: 12px 12px 0 0;
  background: var(--lvl); opacity: .9;
}
.cal-day.lvl-empty::before, .cal-day.lvl-closed::before { opacity: 0; }
.cal-day:hover, .cal-day:focus-visible { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--line-strong); z-index: 5; }
.cal-day.is-weekend { background: var(--surface-2); }
.cal-day.lvl-closed { background: repeating-linear-gradient(135deg, #f8fafc 0 8px, #f1f5f9 8px 16px); cursor: default; }
.cal-day.lvl-full { background: linear-gradient(180deg, #fff1f2, #fff 60%); }
.cal-day.is-other { opacity: .38; }
.cal-day.is-today { border: 2px solid var(--today); box-shadow: 0 0 0 4px var(--today-glow), var(--shadow); }
.cal-day.is-today:hover { box-shadow: 0 0 0 4px var(--today-glow), var(--shadow-lg); }
.cal-today-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--today); margin-left: .35rem; }
.cal-top { display: flex; align-items: flex-start; justify-content: space-between; }
.cal-num { font-size: 1.15rem; font-weight: 700; }
.is-today .cal-num { background: var(--today); color: #fff; border-radius: 8px; padding: 0 .45rem; }
.slots { display: flex; flex-wrap: wrap; gap: 3px; }
.slot { width: 11px; height: 11px; border-radius: 3px; background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-strong); }
.slot.is-taken { background: var(--c); box-shadow: none; }
.cal-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: .3rem; font-size: .78rem; }
.cal-closed { margin-top: auto; font-size: .78rem; color: var(--muted); }
.tag { display: inline-block; padding: .08rem .45rem; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.tag--free { background: #ecfdf5; color: var(--ok); }
.tag--full { background: #fee2e2; color: #b91c1c; }
.tag--today { background: var(--today); color: #fff; }
.cal-add {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; text-decoration: none;
  background: var(--primary); color: #fff !important; font-weight: 700; opacity: 0; transition: opacity .15s, transform .15s;
}
.cal-day:hover .cal-add, .cal-day:focus-within .cal-add { opacity: 1; }
.cal-add:hover { transform: scale(1.12); }
.cal-busy {
  position: absolute; left: .4rem; right: .4rem; bottom: -.55rem; z-index: 2; text-align: center;
  font-size: .72rem; font-weight: 600; color: #78350f; background: #fde68a; border-radius: 999px; padding: .1rem .4rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 2px 6px rgba(146, 64, 14, .25);
}
.cal-busy[hidden] { display: none; }
.cal-day.is-busy { animation: cal-pulse 1.8s ease-in-out infinite; }
@keyframes cal-pulse { 0%, 100% { box-shadow: 0 0 0 2px #fbbf24; } 50% { box-shadow: 0 0 0 5px rgba(251, 191, 36, .35); } }
.cal-pop {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 35; width: 280px;
  background: #0f172a; color: #e2e8f0; border-radius: 12px; padding: .7rem .8rem; box-shadow: var(--shadow-lg);
  font-size: .82rem; cursor: default;
}
.pop-left .cal-pop { left: auto; right: 0; }
.cal-pop b { color: #fff; }
.cal-pop ol { margin: .4rem 0 0; padding-left: 1.2rem; display: grid; gap: .2rem; }
.cal-pop .dot { margin-right: .35rem; }
.cal-pop .muted { color: #94a3b8; }
@media (hover: hover) { .cal-day:hover .cal-pop { display: block; } }
.cal-day:focus-visible .cal-pop { display: block; }

.cal-side { display: grid; gap: 1rem; }
.surgeons { list-style: none; margin: 0; padding: 0; display: grid; gap: .65rem; }
.surgeons li { display: grid; grid-template-columns: 1fr auto; gap: .25rem .5rem; align-items: center; }
.surgeon-name { display: flex; align-items: center; gap: .45rem; font-weight: 500; }
.surgeon-count { font-weight: 700; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--c); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; font-size: .88rem; color: #334155; }
.legend li { display: flex; align-items: center; gap: .55rem; }
.legend-slots { display: inline-flex; gap: 3px; }
.legend-busy { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: #fde68a; color: #78350f; font-size: .7rem; }

.year-card h2 { margin-bottom: .6rem; }
.year-strip { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .5rem; }
.year-month {
  display: flex; flex-direction: column; align-items: center; gap: .25rem; text-decoration: none; color: var(--text);
  padding: .4rem .2rem; border-radius: 10px; transition: background .15s;
}
.year-month:hover { background: var(--surface-2); }
.year-month.is-current { background: var(--primary-soft); }
.year-bar { width: 22px; height: 70px; border-radius: 6px; background: var(--track); display: flex; align-items: flex-end; overflow: hidden; }
.year-bar span { width: 100%; background: var(--lvl); border-radius: 6px 6px 0 0; min-height: 2px; }
.year-count { font-weight: 700; font-size: .9rem; }
.year-name { font-size: .78rem; color: var(--muted); text-transform: capitalize; }

@media (max-width: 760px) {
  .cal-grid { gap: .25rem; }
  .cal-day { min-height: 70px; padding: .35rem; }
  .slots, .cal-foot, .cal-closed, .cal-pop { display: none !important; }
  .ring { --size: 30px; }
  .ring small { display: none; }
  .year-strip { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* --- Журнал записи (таблица) -------------------------------------------- */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .9rem; }
.tab { padding: .32rem .8rem; text-decoration: none; color: var(--muted); border-radius: 999px; font-size: .9rem; transition: background .15s; }
.tab:hover { background: var(--surface); color: var(--text); }
.tab--active { background: var(--primary); color: #fff; font-weight: 600; }

.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
@media (min-width: 1240px) { .table-wrap { overflow: visible; } }
table { border-collapse: collapse; width: 100%; }
.journal { table-layout: fixed; min-width: 1150px; }
.journal th, .journal td { padding: .42rem .5rem; border-bottom: 1px solid rgba(15, 23, 42, .06); vertical-align: top; overflow-wrap: anywhere; }
.journal thead th {
  position: sticky; top: var(--topbar-h, 0px); background: #f8fafc; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); text-align: left; z-index: 5; border-bottom: 1px solid var(--line);
}
.c-num { width: 2.6rem; } .c-date { width: 6.8rem; } .c-name { width: 17%; } .c-birth { width: 6.8rem; }
.c-contacts { width: 9.5rem; } .c-diag { width: 15%; } .c-anest { width: 6.5rem; } .c-doctor { width: 8.5rem; }
.c-note { width: 12%; }

.day-head th { text-align: left; padding: .55rem .7rem; border-top: 6px solid var(--bg); }
.day-head__inner { display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-items: center; }
.day-date { font-weight: 700; font-size: 1rem; }
.day-wd { color: rgba(15, 23, 42, .6); text-transform: capitalize; }
.day-load { margin-left: auto; display: inline-flex; align-items: center; gap: .55rem; }
.load-bar { width: 120px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .7); overflow: hidden; box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .08); }
.load-bar span { display: block; height: 100%; background: var(--lvl); border-radius: 999px; transition: width .3s; }
.day-count { font-weight: 700; font-size: .9rem; min-width: 3.6rem; }
.day-count.lvl-full { color: #b91c1c; }
.seats { display: inline-flex; gap: .3rem; }
.seat-btn {
  font: inherit; font-size: .8rem; padding: .18rem .55rem; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(15, 23, 42, .18); background: rgba(255, 255, 255, .75); color: var(--text);
}
.seat-btn:hover:not(:disabled) { background: #fff; border-color: var(--primary); color: var(--primary); }
.seat-btn:disabled { opacity: .35; cursor: default; }
.num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row { cursor: pointer; transition: background .1s; }
.row:hover td { background: rgba(15, 118, 110, .08) !important; }
.row .name a { color: var(--text); font-weight: 600; text-decoration: none; }
.row .name a:hover { color: var(--primary); text-decoration: underline; }
.note { font-size: .86rem; color: #334155; }
.chip { display: inline-block; padding: .05rem .45rem; border-radius: 6px; background: rgba(15, 23, 42, .06); font-size: .82rem; font-weight: 600; }
.doctor { display: inline-flex; align-items: center; gap: .35rem; }
.free td { padding-top: .14rem; padding-bottom: .14rem; font-size: .84rem; }
.free a { text-decoration: none; opacity: .6; font-weight: 500; }
.free a:hover { opacity: 1; text-decoration: underline; }

.wd0 td { background: var(--wd0); } .wd0 .day-head th { background: var(--wd0-head); }
.wd1 td { background: var(--wd1); } .wd1 .day-head th { background: var(--wd1-head); }
.wd2 td { background: var(--wd2); } .wd2 .day-head th { background: var(--wd2-head); }
.wd3 td { background: var(--wd3); } .wd3 .day-head th { background: var(--wd3-head); }
.wd4 td { background: var(--wd4); } .wd4 .day-head th { background: var(--wd4-head); }
.wd5 td, .wd6 td { background: var(--wd5); } .wd5 .day-head th, .wd6 .day-head th { background: var(--wd5-head); }
.day--today .day-head th { box-shadow: inset 0 0 0 2px var(--today), inset 7px 0 0 var(--today); }
tbody:target .day-head th { box-shadow: inset 0 0 0 2px var(--primary); }

/* Строка, которую сейчас заполняет коллега */
@keyframes busy-pulse { 0%, 100% { background-color: #fde68a; } 50% { background-color: #fef3c7; } }
tr.is-busy td { animation: busy-pulse 1.8s ease-in-out infinite; }
tr.is-busy .num { color: #78350f; font-weight: 700; }
.busy-label { font-weight: 600; color: #78350f; font-size: .85rem; }
.busy-label[hidden] { display: none; }
.row .busy-label { display: block; margin-top: .1rem; font-weight: 500; }
.presence-note {
  margin: .4rem 0 .9rem; padding: .6rem .85rem; border-radius: 10px;
  background: #fef3c7; color: #78350f; font-weight: 500; border: 1px solid #fde68a;
}
.presence-note[hidden] { display: none; }

/* --- Формы и карточка пациента ------------------------------------------ */
.card.narrow { max-width: 460px; margin: 2.5rem auto; }
.card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .3rem; }
.card-head h1 { font-size: 1.4rem; }
.detail { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
@media (max-width: 1000px) { .detail { grid-template-columns: 1fr; } }

.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  font: inherit; padding: .5rem .65rem; border: 1px solid var(--line-strong); border-radius: 10px;
  background: #fff; color: var(--text); width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .15); }
input:disabled, textarea:disabled { background: var(--surface-2); color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem 1rem; margin-top: .6rem; }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: .78rem; font-weight: 700; margin-bottom: .25rem; color: #475569; text-transform: uppercase; letter-spacing: .04em; }
.field--full_name, .field--diagnosis, .field--note, .field--contacts { grid-column: 1 / -1; }
.field--contacts { position: relative; }
.field--contacts input { font-size: 1.05rem; padding-left: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1.9.4 1.8.7 2.7a2 2 0 0 1-.5 2.1L8 9.8a16 16 0 0 0 6 6l1.3-1.3a2 2 0 0 1 2.1-.4c.9.3 1.8.6 2.7.7a2 2 0 0 1 1.7 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: .7rem center; background-size: 18px; }
input.is-filled, textarea.is-filled { animation: filled-flash 1.6s ease-out; }
@keyframes filled-flash { 0% { box-shadow: 0 0 0 3px rgba(16, 185, 129, .45); border-color: #10b981; } 100% { box-shadow: none; } }

/* Выпадающий список автоподбора пациента */
.lookup {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; max-height: 380px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow-lg); padding: .3rem;
}
.lookup[hidden] { display: none; }
.lookup-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: .35rem .6rem .2rem; }
.lookup-item { padding: .5rem .65rem; border-radius: 9px; cursor: pointer; display: grid; gap: .1rem; }
.lookup-item.is-active { background: var(--primary-soft); }
.lookup-main { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .45rem; }
.lookup-main .tag { margin-left: auto; }
.lookup-sub { font-size: .86rem; color: var(--text); opacity: .85; }
.lookup-visits { font-size: .8rem; color: var(--muted); }
.lookup-empty { padding: .6rem .7rem; color: var(--muted); font-size: .88rem; }
.lookup-foot { font-size: .72rem; color: var(--muted); padding: .35rem .6rem .15rem; border-top: 1px solid var(--line); margin-top: .2rem; }
.patient-note { margin: .2rem 0 .6rem; padding: .55rem .8rem; border-radius: 10px; font-size: .9rem; background: #ecfdf5; color: var(--ok); border: 1px solid #a7f3d0; }
.patient-note[hidden] { display: none; }
.patient-note--warn { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.patient-note__warn { margin-top: .3rem; font-weight: 600; }
.field--full_name input { font-size: 1.1rem; font-weight: 600; }
.field--error input, .field--error textarea { border-color: var(--danger); }
.req { color: var(--danger); }
.errors, .errorlist { color: var(--danger); font-size: .86rem; margin: .25rem 0 0; padding: 0; list-style: none; }
.help { color: var(--muted); font-size: .82rem; }
.help ul { margin: .2rem 0; padding-left: 1.1rem; }
.conflict { margin-top: .3rem; font-size: .84rem; color: var(--warn); background: #fef3c7; padding: .25rem .5rem; border-radius: 7px; }
.merged { margin-top: .3rem; font-size: .84rem; color: var(--ok); background: #ecfdf5; padding: .25rem .5rem; border-radius: 7px; }
.actions { display: flex; gap: .6rem; margin-top: 1.1rem; flex-wrap: wrap; align-items: center; }

.filters {
  display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; margin: .8rem 0 1rem;
  background: var(--surface); padding: .9rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow);
}
.filters label { display: flex; flex-direction: column; font-size: .75rem; font-weight: 700; gap: .25rem; color: #475569; text-transform: uppercase; letter-spacing: .04em; }
.filters input, .filters select { width: auto; min-width: 9rem; }
.filters input[type=search] { min-width: 18rem; }

/* --- История изменений -------------------------------------------------- */
.entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.entry { background: var(--surface); border-radius: 12px; padding: .65rem .85rem; box-shadow: var(--shadow); border-left: 4px solid var(--line-strong); }
.entry--create, .entry--restore { border-left-color: var(--lvl-low); }
.entry--update, .entry--capacity { border-left-color: var(--accent); }
.entry--delete, .entry--login_failed { border-left-color: var(--danger); }
.history .entry { box-shadow: none; background: var(--surface-2); }
.entry-head { display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: center; }
.entry-head time { color: var(--muted); font-variant-numeric: tabular-nums; }
.entry-comment { margin-top: .3rem; font-style: italic; color: #334155; }
.changes { margin-top: .45rem; font-size: .87rem; width: auto; max-width: 100%; }
.changes th { text-align: left; font-weight: 500; color: var(--muted); padding: .12rem .7rem .12rem 0; width: 11rem; vertical-align: top; }
.changes td { padding: .12rem .3rem; vertical-align: top; overflow-wrap: anywhere; }
.changes .old { color: var(--danger); text-decoration: line-through; text-decoration-color: rgba(220, 38, 38, .4); }
.changes .new { color: var(--ok); font-weight: 500; }
.changes .arrow { color: var(--muted); width: 1rem; }

.badge { font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; background: #e2e8f0; color: #334155; font-weight: 600; }
.badge--create, .badge--restore { background: #d1fae5; color: var(--ok); }
.badge--update, .badge--capacity { background: #e0e7ff; color: var(--accent); }
.badge--delete, .badge--danger, .badge--login_failed { background: #fee2e2; color: var(--danger); }

.list th, .list td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.list thead th { background: var(--surface-2); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.list tbody tr:hover td { background: var(--surface-2); }
.is-deleted td { color: var(--muted); }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* Сводка по анестезии на день */
.anest-chips { display: inline-flex; flex-wrap: wrap; gap: .25rem; }
.anest-chip {
  font-size: .72rem; line-height: 1.5; padding: 0 .4rem; border-radius: 6px; white-space: nowrap;
  background: rgba(79, 70, 229, .1); color: #3730a3; border: 1px solid rgba(79, 70, 229, .2);
}
.anest-chip b { font-weight: 800; }
.cal-day .anest-chips { gap: .2rem; }
.cal-day .anest-chip { font-size: .68rem; padding: 0 .3rem; }
.plan-head .anest-chip, .day-head .anest-chip { font-size: .78rem; }

/* Действия с записью: меню, перетаскивание, окна */
.row-menu-btn {
  display: none; border: 0; background: var(--surface); color: var(--text); border-radius: 6px; width: 22px; height: 20px;
  line-height: 1; font-size: 1rem; cursor: pointer; box-shadow: 0 0 0 1px var(--line-strong); padding: 0;
}
.row:hover .row-menu-btn, .row:focus-within .row-menu-btn { display: inline-block; }
.row:hover .num-value, .row:focus-within .num-value { display: none; }
@media (hover: none) { .row-menu-btn { display: inline-block; } .num-value { display: none; } }
.row[draggable="true"] { cursor: grab; }
.row.is-dragging td { opacity: .45; }
.drag-active .free td, .drag-active .day-head th { transition: background .15s; }
tbody.drop-target .day-head th { box-shadow: inset 0 0 0 3px var(--primary); }
tbody.drop-target td { background: var(--primary-soft) !important; }
tbody.drop-target .day-head th::after { content: "  ← отпустите, чтобы перенести сюда"; font-weight: 600; color: var(--primary); }

.ctx-menu {
  position: fixed; z-index: 60; min-width: 250px; padding: .35rem; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-lg); display: grid;
}
.ctx-menu[hidden] { display: none; }
.ctx-title { padding: .35rem .6rem .45rem; font-size: .78rem; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: .2rem; }
.ctx-menu button {
  text-align: left; border: 0; background: none; color: var(--text); font: inherit; padding: .45rem .6rem; border-radius: 8px; cursor: pointer;
}
.ctx-menu button:hover, .ctx-menu button:focus { background: var(--primary-soft); outline: none; }
.ctx-menu button[hidden] { display: none; }
.ctx-menu hr { border: 0; border-top: 1px solid var(--line); margin: .25rem 0; width: 100%; }
.ctx-menu .ctx-danger { color: var(--danger); }
.ctx-menu .ctx-danger:hover, .ctx-menu .ctx-danger:focus { background: rgba(220, 38, 38, .1); }

.dlg {
  border: 0; border-radius: 16px; padding: 1.3rem 1.4rem; width: min(440px, calc(100vw - 2rem));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dlg::backdrop { background: rgba(2, 6, 23, .45); backdrop-filter: blur(2px); }
.dlg h2 { font-size: 1.2rem; margin: 0 0 .3rem; }
.dlg form { display: grid; gap: .65rem; }
.dlg label { display: grid; gap: .25rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
.dlg-who { margin: 0 0 .3rem; font-weight: 600; }
.dlg .actions { margin-top: .4rem; }

/* Контакты: каждый номер с новой строки, длинное переносится, не наезжая на соседние колонки */
.journal td.contacts { white-space: normal; }
.contact-line { display: block; overflow-wrap: anywhere; }
.contact-line + .contact-line { margin-top: .1rem; color: var(--muted); font-size: .92em; }

/* Файлы и фото к примечанию */
.files { margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.files h2 { font-size: .95rem; }
.files-grid { list-style: none; margin: 0 0 .7rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .6rem; }
.file-card { position: relative; display: flex; gap: .6rem; align-items: center; padding: .45rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.file-thumb { flex: none; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: var(--track); text-decoration: none; }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb--doc span { font-weight: 800; font-size: .78rem; color: var(--primary); }
.file-meta { display: grid; min-width: 0; }
.file-name { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-del { position: absolute; top: .15rem; right: .35rem; margin: 0; }
.file-del .link { width: auto; font-size: 1.1rem; color: var(--muted); text-decoration: none; }
.file-del .link:hover { color: var(--danger); }
.file-upload { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: 0; }
.file-pick { cursor: pointer; }
.file-pick.is-busy { opacity: .6; pointer-events: none; }
.clip { display: inline-block; margin-left: .3rem; text-decoration: none; font-size: .8rem; white-space: nowrap; }

/* Масштаб */
.zoom-ctl { display: inline-flex; align-items: center; border-radius: 999px; background: rgba(255, 255, 255, .14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); overflow: hidden; }
.zoom-ctl button { border: 0; background: none; color: #fff; font: inherit; cursor: pointer; height: 32px; min-width: 30px; padding: 0 .45rem; }
.zoom-ctl button:hover { background: rgba(255, 255, 255, .18); }
.zoom-ctl .zoom-value { font-size: .78rem; font-variant-numeric: tabular-nums; min-width: 46px; }
.page { zoom: var(--ui-zoom, 1); }
@media print { .page { zoom: 1 !important; } .zoom-ctl { display: none !important; } }

/* Праздники и переносы */
.tag--holiday { background: rgba(220, 38, 38, .12); color: #b91c1c; }
.tag--workday { background: rgba(37, 99, 235, .12); color: #1d4ed8; }
.cal-day.is-holiday { background: repeating-linear-gradient(135deg, #fff1f2 0 8px, #ffe4e6 8px 16px); }
.cal-day.is-holiday .cal-num { color: #b91c1c; }
.cal-day.is-holiday .cal-closed { color: #b91c1c; font-weight: 600; }
.cal-special { font-size: .7rem; font-weight: 600; color: #b91c1c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-special--work { color: #1d4ed8; }

/* Отменённые операции */
.is-cancelled td { color: var(--muted); }
.is-cancelled .name a, .is-cancelled .pname, .is-cancelled td:not(.num) > span.doctor,
.cal-pop li.is-cancelled .pop-name { text-decoration: line-through; text-decoration-color: var(--danger); text-decoration-thickness: 2px; }
.cancel-note {
  display: block; margin-top: .2rem; font-size: .82rem; font-weight: 600; color: var(--danger);
  text-decoration: none !important; white-space: normal;
}
.cancel-note .muted { font-weight: 400; }
.pop-cancel { color: #fca5a5; font-size: .76rem; }
.tag--cancel { background: rgba(220, 38, 38, .1); color: var(--danger); }
.badge--cancel, .badge--uncancel { background: #fee2e2; color: var(--danger); }
.badge--uncancel { background: #d1fae5; color: var(--ok); }
.entry--cancel { border-left-color: var(--danger); }
.cancel-banner {
  margin: .6rem 0; padding: .7rem .9rem; border-radius: 12px; background: rgba(220, 38, 38, .07);
  border: 1px solid rgba(220, 38, 38, .3); color: var(--text); display: grid; gap: .35rem;
}
.cancel-banner b { color: var(--danger); }
.cancel-box { margin-top: 1rem; border: 1px dashed rgba(220, 38, 38, .45); border-radius: 12px; padding: .6rem .85rem; }
.cancel-box summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.cancel-form { display: grid; gap: .5rem; margin-top: .7rem; }
.cancel-form label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.cancel-form .btn { justify-self: start; }

/* План операций (операционные сёстры) */
.plan-title span { color: var(--muted); font-weight: 500; font-size: 1.1rem; }
.hero-actions .btn.is-on { background: var(--primary-soft); border-color: var(--primary); }
.plan-wrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.plan-table { table-layout: fixed; width: 100%; border-collapse: separate; border-spacing: 0; }
.pc-num { width: 3.2rem; } .pc-adm { width: 9.5rem; } .pc-patient { width: 24%; } .pc-anest { width: 8rem; } .pc-doctor { width: 15%; }
.plan-table thead th {
  position: sticky; top: var(--topbar-h, 0px); z-index: 6; background: var(--surface-2); text-align: left;
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: .7rem 1rem; border-bottom: 2px solid var(--line-strong);
}
.plan-table thead th:first-child { border-top-left-radius: var(--radius); }
.plan-table thead th:last-child { border-top-right-radius: var(--radius); }
.plan-table td { padding: .6rem 1rem; font-size: 1rem; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.plan-head th { text-align: left; padding: .75rem 1rem .55rem; background: var(--primary-soft); border-bottom: 1px solid var(--line); }
.plan-head th > * { margin-right: .7rem; }
.plan-date { font-size: 1.15rem; font-weight: 700; }
.plan-wd { color: var(--muted); text-transform: capitalize; }
.plan-count { float: right; font-weight: 600; margin-right: 0 !important; }
.plan-day--today .plan-head th { box-shadow: inset 6px 0 0 var(--today); }
.plan-patient { font-weight: 600; }
.auto-mark { font-size: .68rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 5px; padding: 0 .25rem; vertical-align: 1px; }
.plan-foot { margin-top: 1rem; }
@media print {
  .plan-table thead th { position: static; }
  .plan-day { break-inside: avoid; }
  .plan-foot, .hero-actions, .icon-btn, .hero .btn { display: none !important; }
}

/* Быстрый вход */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.page-title { text-align: left !important; }
.mt { margin-top: 1.4rem; }
.bullets { padding-left: 1.1rem; margin: 0; display: grid; gap: .35rem; }
.login-card { max-width: 440px; }
.login-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.2rem; }
.login-brand h1 { font-size: 1.3rem; }
.login-brand p { margin: 0; }
.brand-mark--solid { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(135deg, #0f766e, #1e3a8a); }
.brand-mark--solid svg { fill: #fff; stroke: none; width: 24px; height: 24px; }
.login-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.login-error { margin-bottom: .6rem; padding: .5rem .7rem; border-radius: 10px; background: rgba(220, 38, 38, .08); }
.quick-users { display: grid; gap: .5rem; }
.quick-user { margin: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); transition: border-color .15s, box-shadow .15s; }
.quick-user.is-open { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); background: var(--surface); }
.quick-tile {
  width: 100%; display: flex; align-items: center; gap: .8rem; padding: .7rem .85rem; border: 0; background: none;
  font: inherit; color: var(--text); cursor: pointer; text-align: left; border-radius: 14px;
}
.quick-name { font-weight: 600; font-size: 1.05rem; flex: 1; }
.quick-chevron { color: var(--muted); transition: transform .2s; }
.quick-user.is-open .quick-chevron { transform: rotate(90deg); }
.avatar--lg { width: 42px; height: 42px; font-size: .95rem; box-shadow: none; background: var(--primary-soft); color: var(--primary); }
.quick-pin { display: none; grid-template-columns: 1fr auto; gap: .5rem; padding: 0 .85rem .85rem; }
.quick-user.is-open .quick-pin { display: grid; }
.pin-input { font-size: 1.4rem; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }
.pin-input::placeholder { font-size: 1rem; letter-spacing: normal; }
.quick-forget { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); text-align: left; text-decoration: underline; }
.login-switch { display: inline-block; margin-top: 1rem; font-weight: 500; }
.login-foot { margin: 1.2rem 0 0; }
.check { flex-direction: row !important; align-items: flex-start; gap: .55rem !important; font-weight: 500 !important; }
.check input { width: 18px; height: 18px; margin-top: .15rem; flex: none; accent-color: var(--primary); }

/* Страница входа */
body:not(:has(.topbar)) { background: radial-gradient(1200px 600px at 10% -10%, #99f6e4 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #c7d2fe 0%, transparent 60%), var(--bg); min-height: 100vh; }
body:not(:has(.topbar)) .card.narrow { margin-top: 12vh; box-shadow: var(--shadow-lg); padding: 1.8rem 2rem; }

@media print {
  .topbar, .tabs, .hero-actions, .icon-btn, .seats, .free, .live-banner, .messages, .cal-side, .cal-add { display: none !important; }
  .page { padding: 0; }
  .table-wrap, .card, .kpi { box-shadow: none; border: 1px solid #ddd; }
  .journal { min-width: 0; font-size: 10px; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ==========================================================================
   Переключатель темы
   ========================================================================== */
.theme-toggle {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; cursor: pointer;
  border: 0; color: #fff; background: rgba(255, 255, 255, .14); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
  transition: background .15s, transform .2s;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .24); transform: rotate(-15deg); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-toggle--floating { position: fixed; top: 1rem; right: 1rem; z-index: 50; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }

/* ==========================================================================
   Тёмная тема (только на экране — печать остаётся светлой)
   ========================================================================== */
@media screen {
  [data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a101d;
    --surface: #111a2b;
    --surface-2: #0d1524;
    --text: #e2e8f0;
    --muted: #8b9ab1;
    --line: #1d2a3f;
    --line-strong: #2c3b54;
    --primary: #2dd4bf;
    --primary-600: #5eead4;
    --primary-soft: rgba(45, 212, 191, .16);
    --today: #60a5fa;
    --today-glow: rgba(96, 165, 250, .28);
    --accent: #a5b4fc;
    --danger: #f87171;
    --ok: #34d399;
    --warn: #fcd34d;
    --track: #1e2a3d;
    --lvl-empty: #334155;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 34px rgba(0, 0, 0, .55);

    --wd0: #131c35; --wd0-head: #1f2c55;
    --wd1: #1f1427; --wd1-head: #36203f;
    --wd2: #111a2b; --wd2-head: #1c283c;
    --wd3: #221316; --wd3-head: #3d1d22;
    --wd4: #22180f; --wd4-head: #3d2a15;
    --wd5: #121925; --wd5-head: #1f2938;
    --wd6: #121925; --wd6-head: #1f2938;
  }

  [data-theme="dark"] .topbar { background: linear-gradient(110deg, #04161d 0%, #0a3f3b 55%, #172352 130%); box-shadow: 0 2px 14px rgba(0, 0, 0, .5); }
  [data-theme="dark"] .btn--new { background: var(--primary) !important; color: #042f2e !important; border-color: var(--primary) !important; }
  [data-theme="dark"] .btn--primary,
  [data-theme="dark"] .tab--active,
  [data-theme="dark"] .cal-add { background: #14b8a6; border-color: #14b8a6; color: #042f2e !important; }
  [data-theme="dark"] .is-today .cal-num { color: #0a101d; }
  [data-theme="dark"] .btn--primary:hover { background: #2dd4bf; }
  [data-theme="dark"] .btn:hover, [data-theme="dark"] .icon-btn:hover { box-shadow: 0 0 0 3px rgba(45, 212, 191, .18); }
  [data-theme="dark"] .btn--danger { color: #fff; background: #dc2626; border-color: #dc2626; }
  [data-theme="dark"] .btn--danger-ghost { border-color: rgba(248, 113, 113, .4); }

  [data-theme="dark"] .msg { background: rgba(56, 189, 248, .1); color: #7dd3fc; border-color: rgba(56, 189, 248, .25); }
  [data-theme="dark"] .msg--success { background: rgba(52, 211, 153, .1); color: var(--ok); border-color: rgba(52, 211, 153, .25); }
  [data-theme="dark"] .msg--error { background: rgba(248, 113, 113, .1); color: var(--danger); border-color: rgba(248, 113, 113, .3); }
  [data-theme="dark"] .msg--warning,
  [data-theme="dark"] .live-banner { background: rgba(251, 191, 36, .1); color: var(--warn); border-color: rgba(251, 191, 36, .3); }

  [data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea { background-color: #0b1322; border-color: var(--line-strong); }
  [data-theme="dark"] .search input { background: transparent; box-shadow: none; }
  [data-theme="dark"] input:disabled, [data-theme="dark"] textarea:disabled { background: #0f1828; color: #cbd5e1; }
  [data-theme="dark"] input:focus, [data-theme="dark"] select:focus, [data-theme="dark"] textarea:focus { box-shadow: 0 0 0 3px rgba(45, 212, 191, .2); }
  [data-theme="dark"] .field label, [data-theme="dark"] .filters label { color: var(--muted); }

  /* Календарь */
  [data-theme="dark"] .kpi::after { background: radial-gradient(circle, rgba(45, 212, 191, .16), transparent 70%); }
  [data-theme="dark"] .cal-day { border-color: var(--line); }
  [data-theme="dark"] .cal-day:hover { border-color: var(--line-strong); }
  [data-theme="dark"] .cal-day.lvl-closed { background: repeating-linear-gradient(135deg, #0e1626 0 8px, #121c2e 8px 16px); }
  [data-theme="dark"] .cal-day.lvl-full { background: linear-gradient(180deg, rgba(239, 68, 68, .14), var(--surface) 65%); }
  [data-theme="dark"] .cal-head--weekend { color: #fbbf24; }
  [data-theme="dark"] .tag--free { background: rgba(52, 211, 153, .14); color: #6ee7b7; }
  [data-theme="dark"] .tag--full { background: rgba(248, 113, 113, .16); color: #fca5a5; }
  [data-theme="dark"] .cal-pop { background: #1b263a; box-shadow: var(--shadow-lg), inset 0 0 0 1px #2c3b54; }
  [data-theme="dark"] .legend { color: #cbd5e1; }
  [data-theme="dark"] .slot.is-taken { box-shadow: 0 0 6px color-mix(in srgb, var(--c) 55%, transparent); }

  /* Журнал записи */
  [data-theme="dark"] .journal th, [data-theme="dark"] .journal td { border-bottom-color: rgba(255, 255, 255, .05); }
  [data-theme="dark"] .journal thead th { background: #0f1828; }
  [data-theme="dark"] .day-head th { border-top-color: var(--bg); }
  [data-theme="dark"] .day-wd { color: var(--muted); }
  [data-theme="dark"] .load-bar { background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); }
  [data-theme="dark"] .day-count.lvl-full { color: #fca5a5; }
  [data-theme="dark"] .seat-btn { background: rgba(255, 255, 255, .05); border-color: rgba(255, 255, 255, .14); }
  [data-theme="dark"] .seat-btn:hover:not(:disabled) { background: rgba(45, 212, 191, .12); }
  [data-theme="dark"] .note, [data-theme="dark"] .entry-comment { color: #cbd5e1; }
  [data-theme="dark"] .chip { background: rgba(255, 255, 255, .08); }
  [data-theme="dark"] .row:hover td { background: rgba(45, 212, 191, .1) !important; }

  /* «Коллега заполняет» — тёплый янтарь, приглушённый для тёмного фона */
  @keyframes busy-pulse-dark { 0%, 100% { background-color: #4a3410; } 50% { background-color: #3a2a0e; } }
  [data-theme="dark"] tr.is-busy td { animation-name: busy-pulse-dark; }
  [data-theme="dark"] tr.is-busy .num, [data-theme="dark"] .busy-label { color: #fcd34d; }
  [data-theme="dark"] .presence-note,
  [data-theme="dark"] .conflict { background: rgba(251, 191, 36, .12); color: #fcd34d; border-color: rgba(251, 191, 36, .3); }
  [data-theme="dark"] .merged { background: rgba(52, 211, 153, .12); color: #6ee7b7; }
  [data-theme="dark"] .patient-note { background: rgba(52, 211, 153, .12); color: #6ee7b7; border-color: rgba(52, 211, 153, .3); }
  [data-theme="dark"] .patient-note--warn { background: rgba(248, 113, 113, .12); color: #fca5a5; border-color: rgba(248, 113, 113, .35); }
  [data-theme="dark"] .lookup { background: #16213a; }
  [data-theme="dark"] .tag--holiday { background: rgba(248, 113, 113, .16); color: #fca5a5; }
  [data-theme="dark"] .tag--workday { background: rgba(96, 165, 250, .16); color: #93c5fd; }
  [data-theme="dark"] .cal-day.is-holiday { background: repeating-linear-gradient(135deg, #2a1418 0 8px, #22121a 8px 16px); }
  [data-theme="dark"] .cal-day.is-holiday .cal-num, [data-theme="dark"] .cal-day.is-holiday .cal-closed, [data-theme="dark"] .cal-special { color: #fca5a5; }
  [data-theme="dark"] .cal-special--work { color: #93c5fd; }
  [data-theme="dark"] .anest-chip { background: rgba(165, 180, 252, .14); color: #c7d2fe; border-color: rgba(165, 180, 252, .28); }
  [data-theme="dark"] .quick-user.is-open { box-shadow: 0 0 0 3px rgba(45, 212, 191, .18); }
  [data-theme="dark"] .avatar--lg { color: #5eead4; }

  /* TOTP (двухфакторная защита) */
.totp-qr { display: flex; justify-content: center; margin: 1rem 0; }
.totp-qr svg { width: 200px; height: 200px; border: 8px solid #fff; border-radius: 12px; background: #fff; }
.totp-manual { margin: .8rem 0; }
.totp-manual summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.totp-secret { display: block; margin-top: .5rem; padding: .6rem .8rem; background: var(--surface-2); border-radius: 8px; font-family: monospace; font-size: 1.05rem; letter-spacing: .08em; word-break: break-all; user-select: all; }

/* История изменений */
  [data-theme="dark"] .history .entry { background: var(--surface-2); }
  [data-theme="dark"] .badge { background: #1e293b; color: #cbd5e1; }
  [data-theme="dark"] .badge--create, [data-theme="dark"] .badge--restore { background: rgba(52, 211, 153, .15); color: #6ee7b7; }
  [data-theme="dark"] .badge--update, [data-theme="dark"] .badge--capacity { background: rgba(165, 180, 252, .15); color: #c7d2fe; }
  [data-theme="dark"] .badge--delete, [data-theme="dark"] .badge--danger, [data-theme="dark"] .badge--login_failed { background: rgba(248, 113, 113, .15); color: #fca5a5; }
  [data-theme="dark"] .changes .old { text-decoration-color: rgba(248, 113, 113, .5); }

  /* Вход */
  [data-theme="dark"] body:not(:has(.topbar)) {
    background: radial-gradient(1200px 600px at 10% -10%, rgba(45, 212, 191, .22) 0%, transparent 60%),
      radial-gradient(900px 500px at 110% 110%, rgba(99, 102, 241, .22) 0%, transparent 60%), var(--bg);
  }
}
