:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --primary: #0d9488;
  --primary-700: #0f766e;
  --primary-50: #ecfdf5;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 10px 30px -12px rgba(15, 23, 42, .22);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .35);
  --radius: 16px;
  --radius-sm: 10px;
  --status-libre: #16a34a;
  --status-ocupada: #dc2626;
  --status-reservada: #d97706;
  --status-mantenimiento: #64748b;
  font-synthesis: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 500px at 100% -10%, rgba(13, 148, 136, .10), transparent 60%),
    radial-gradient(900px 460px at -10% 0%, rgba(37, 99, 235, .08), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

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

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid rgba(13, 148, 136, .35);
  outline-offset: 2px;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px 48px;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  margin-bottom: 8px;
  background: rgba(238, 242, 247, .82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(203, 213, 225, .65);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(145deg, #14b8a6, #0d9488 55%, #0f766e);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px -8px rgba(13, 148, 136, .8);
  flex: none;
}

.brand-logo svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -.02em;
}

.brand-text p {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-credit {
  display: block;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: .8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.live-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  flex: none;
}

.live-status.online .live-dot {
  background: var(--status-libre);
  box-shadow: 0 0 0 0 rgba(22, 163, 74, .5);
  animation: pulse 2.2s infinite;
}

.live-status.online { color: #15803d; }
.live-status.offline { color: var(--danger); }
.live-status.offline .live-dot { background: var(--danger); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  max-width: 180px;
  transition: border-color .15s, background .15s;
}

.user-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip:hover { border-color: var(--primary); color: var(--primary-700); }
.user-chip .icon { width: 16px; height: 16px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  flex: none;
}

.icon-btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.icon-btn:active { transform: scale(.96); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 16px;
  flex-wrap: wrap;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1 1 300px;
  min-width: 220px;
  padding: 0 12px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}

.search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .14);
}

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

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 14px;
}

.search input::placeholder { color: #94a3b8; }

.search kbd {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  background: var(--surface-2);
}

.filters {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  max-width: 100%;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
  padding: 7px 11px;
  border-radius: 9px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.filter-btn:hover { background: var(--surface-3); color: var(--ink-soft); }
.filter-btn.active { background: var(--ink); color: #fff; }

.filter-btn .count {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, .22);
}

.filter-btn.active .count { background: rgba(255, 255, 255, .22); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 42px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s;
}

.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; }

.btn.primary {
  background: linear-gradient(135deg, #0d9488, #0f766e);
  color: #fff;
  box-shadow: 0 10px 22px -12px rgba(13, 148, 136, .9);
}

.btn.primary:hover { background: linear-gradient(135deg, #0f9f92, #0d6b64); }

.btn.ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn.ghost:hover { background: var(--surface-3); }

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.danger:hover { background: #b91c1c; }

.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Summary ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.summary-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--ink-soft);
  flex: none;
}

.summary-icon .icon { width: 20px; height: 20px; }

.summary-card[data-tone="total"] .summary-icon { background: #eff6ff; color: #2563eb; }
.summary-card[data-tone="category"] .summary-icon { background: #ccfbf1; color: #0f766e; }
.summary-card[data-tone="history"] .summary-icon { background: #fef3c7; color: #b45309; }

.summary-value {
  font-size: 24px;
  font-weight: 780;
  letter-spacing: -.03em;
  line-height: 1.05;
}

.summary-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ---------- Board ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(430px, 1fr));
  gap: 16px;
  align-items: start;
}

.category {
  --accent: var(--primary);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border-top: 4px solid var(--accent);
  animation: fade-in .25s ease both;
}

.category-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}

.chevron {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  flex: none;
  transition: background .15s, color .15s;
}

.chevron:hover { background: var(--surface-3); color: var(--ink); }
.chevron .icon { width: 16px; height: 16px; transition: transform .18s ease; transform: rotate(90deg); }
.is-collapsed > .category-head .chevron .icon,
.is-collapsed > .subcat-head .chevron .icon { transform: rotate(0deg); }

.cat-info {
  flex: 1;
  min-width: 0;
}

.cat-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.cat-title h2 {
  font-size: 16.5px;
  font-weight: 730;
  letter-spacing: -.015em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

.cat-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.mini-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s, border-color .15s;
}

.mini-btn .icon { width: 15px; height: 15px; }
.mini-btn:hover { background: var(--surface-3); color: var(--ink); border-color: var(--line); }
.mini-btn.danger:hover { background: var(--danger-50); color: var(--danger); border-color: #fecaca; }
.mini-btn.accent:hover { background: var(--primary-50); color: var(--primary-700); border-color: #99f6e4; }

.occ-bar {
  height: 4px;
  background: var(--surface-3);
  overflow: hidden;
}

.occ-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width .4s ease;
}

.category-body {
  padding: 14px 16px 16px;
  display: grid;
  gap: 10px;
}

.is-collapsed > .category-body,
.is-collapsed > .subcat-body { display: none; }

/* ---------- Subcategories ---------- */
.subcat {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
}

.subcat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px 9px 8px;
}

.subcat-info {
  flex: 1;
  min-width: 0;
}

.subcat-title {
  display: flex;
  align-items: center;
  gap: 7px;
}

.subcat-title h3 {
  font-size: 13.5px;
  font-weight: 680;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subcat-title .branch {
  width: 14px;
  height: 14px;
  color: var(--accent);
  opacity: .7;
  flex: none;
}

.subcat-count {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.subcat-body {
  padding: 0 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-body > .subcat-body {
  padding: 0;
}

.nested {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

/* ---------- Beds ---------- */
.bed {
  --status: var(--primary);
  position: relative;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(150px, 1.35fr);
  gap: 12px;
  align-items: stretch;
  cursor: pointer;
  padding: 9px 11px 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--status);
  background: var(--surface);
  text-align: left;
  transition: transform .12s ease, box-shadow .15s ease, border-color .15s;
  min-width: 0;
}

.bed:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.bed[data-status="libre"] { --status: var(--status-libre); }
.bed[data-status="ocupada"] { --status: var(--status-ocupada); }
.bed[data-status="reservada"] { --status: var(--status-reservada); }
.bed[data-status="mantenimiento"] { --status: var(--status-mantenimiento); }

.bed-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.bed-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.bed-num {
  font-size: 14px;
  font-weight: 760;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bed-delete {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  flex: none;
  transition: background .15s, color .15s, border-color .15s;
}

.bed-delete .icon { width: 14px; height: 14px; }
.bed-delete:hover { background: var(--danger-50); color: var(--danger); border-color: #fecaca; }

.badge {
  font-size: 9.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
  flex: none;
}

.badge-libre { background: #dcfce7; color: #15803d; }
.badge-ocupada { background: #fee2e2; color: #b91c1c; }
.badge-reservada { background: #fef3c7; color: #b45309; }
.badge-mantenimiento { background: #e2e8f0; color: #475569; }

.bed-patient {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bed-patient.muted { color: #94a3b8; font-weight: 500; font-style: italic; }

.bed-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 8px;
  font-size: 10.5px;
  color: var(--muted);
}

.bed-meta span { white-space: nowrap; }

.bed-evo {
  --evo-date-w: 62px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding-left: 12px;
  border-left: 1px dashed var(--line);
}

.bed-evo-head {
  display: grid;
  grid-template-columns: var(--evo-date-w) 1fr auto;
  align-items: center;
  gap: 6px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--line);
  font-size: 9.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.evo-col-date { white-space: nowrap; }
.evo-col-text { white-space: nowrap; }

.bed-history-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  padding: 0 6px;
  border: none;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--primary-700);
  font-size: 10px;
  font-weight: 700;
  transition: background .15s, color .15s;
}

.bed-history-btn:hover { background: var(--primary); color: #fff; }
.bed-history-btn .icon { width: 13px; height: 13px; }

.evo-count {
  font-size: 9.5px;
  font-weight: 750;
}

.bed-evolution-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.evo-entry {
  display: grid;
  grid-template-columns: var(--evo-date-w) 1fr;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  font-size: 11px;
  line-height: 1.35;
}

.evo-date {
  flex: none;
  font-weight: 700;
  color: var(--primary-700);
  white-space: nowrap;
}

.evo-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
}

.evo-empty {
  grid-column: 1 / -1;
  color: #94a3b8;
  font-style: italic;
}

.evo-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 1px;
  padding: 4px 6px;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
  transition: border-color .15s, color .15s, background .15s;
}

.evo-add:hover { border-color: var(--primary); color: var(--primary-700); background: var(--primary-50); }
.evo-add .icon { width: 12px; height: 12px; }

.bed.is-updated {
  animation: bed-flash 1.8s ease;
}

.category.is-new,
.subcat.is-new {
  animation: bed-flash 2.4s ease;
}

.add-bed {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 52px;
  border-radius: 11px;
  border: 1.5px dashed var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  transition: border-color .15s, color .15s, background .15s;
}

.add-bed .icon { width: 15px; height: 15px; }
.add-bed:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }

.add-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border-radius: 11px;
  border: 1.5px dashed var(--line-strong);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
  transition: border-color .15s, color .15s, background .15s;
}

.add-sub .icon { width: 15px; height: 15px; }
.add-sub:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }

/* ---------- Empty state ---------- */
.empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  border-radius: var(--radius);
  border: 1.5px dashed var(--line-strong);
  background: rgba(255, 255, 255, .5);
  text-align: center;
}

.empty .icon { width: 42px; height: 42px; color: var(--line-strong); }
.empty h2 { font-size: 17px; font-weight: 700; }
.empty p { color: var(--muted); font-size: 13.5px; max-width: 420px; }

/* ---------- Footer ---------- */
.footer-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 26px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.pulse-mini {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-libre);
  animation: pulse 2.2s infinite;
}

/* ---------- Drawer ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .35);
  z-index: 60;
  opacity: 0;
  transition: opacity .2s ease;
}

.drawer-backdrop.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 92vw);
  background: var(--surface);
  z-index: 61;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  transition: transform .26s cubic-bezier(.4, 0, .2, 1);
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 { font-size: 17px; font-weight: 730; }
.drawer-head p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.activity-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 24px;
}

.activity-item {
  display: flex;
  gap: 11px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--surface-3);
}

.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--ink-soft);
  flex: none;
}

.activity-icon .icon { width: 16px; height: 16px; }
.activity-item[data-type="bed"] .activity-icon,
.activity-item[data-type="update"] .activity-icon { background: #eff6ff; color: #2563eb; }
.activity-item[data-type="category"] .activity-icon,
.activity-item[data-type="create"] .activity-icon { background: var(--primary-50); color: var(--primary-700); }
.activity-item[data-type="delete"] .activity-icon,
.activity-item[data-type="failure"] .activity-icon { background: var(--danger-50); color: var(--danger); }
.activity-item[data-type="session"] .activity-icon { background: #f5f3ff; color: #7c3aed; }

.activity-body { flex: 1; min-width: 0; }

.activity-text {
  font-size: 13px;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.activity-text b { font-weight: 700; color: var(--ink); }

.activity-time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.activity-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px);
  animation: fade-in .15s ease;
}

.modal-card {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  animation: pop-in .18s cubic-bezier(.2, .9, .3, 1.2);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 { font-size: 17px; font-weight: 740; }

#modalForm {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.modal-body {
  padding: 18px 20px;
  display: grid;
  gap: 13px;
  overflow-y: auto;
}

.modal-message {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.modal-message strong { color: var(--ink); }

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-soft);
  letter-spacing: .01em;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  outline: none;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}

.field textarea {
  min-height: 76px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .14);
}

.field input[type="color"] {
  padding: 4px;
  height: 44px;
  cursor: pointer;
}

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

.form-error {
  margin: 0 20px 4px;
  padding: 9px 12px;
  border-radius: 9px;
  background: var(--danger-50);
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 600;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
}


/* ---------- Bed history ---------- */
.history-cta { display: flex; }
.history-cta .btn { width: 100%; justify-content: center; }

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-soft);
}

.history-count {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.timeline {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 2px;
}

.timeline-empty {
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.timeline-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  background: var(--surface-2);
}

.timeline-date {
  padding-top: 1px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--primary-700);
  white-space: nowrap;
}

.timeline-text {
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.timeline-meta {
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

.timeline-delete {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition: background .15s, color .15s;
}

.timeline-delete:hover { background: var(--danger-50); color: var(--danger); }
.timeline-delete .icon { width: 15px; height: 15px; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(420px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s cubic-bezier(.2, .9, .3, 1.2);
  pointer-events: auto;
  max-width: 100%;
}

.toast.error { background: #b91c1c; }
.toast .icon { width: 16px; height: 16px; }

/* ---------- Animations ---------- */
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .5); }
  70% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes bed-flash {
  0% { box-shadow: 0 0 0 0 rgba(13, 148, 136, .55); }
  35% { box-shadow: 0 0 0 4px rgba(13, 148, 136, .35); }
  100% { box-shadow: 0 0 0 0 rgba(13, 148, 136, 0); }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app { padding: 0 16px 40px; }
  .brand-text p { display: none; }
  .board { grid-template-columns: 1fr; }
  .toolbar { gap: 10px; }
  .search { flex: 1 1 100%; }
  .filters { order: 3; }
  .toolbar > .btn.primary { margin-left: auto; }
}

@media (max-width: 620px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-status { display: none; }
  .brand-text h1 { font-size: 16px; }
  .brand-logo { width: 38px; height: 38px; }
  .field-row { grid-template-columns: 1fr; }
  .user-chip { max-width: 120px; }
  .bed { grid-template-columns: 1fr; gap: 8px; }
  .bed-evo {
    border-left: 0;
    padding-left: 0;
    padding-top: 7px;
    border-top: 1px dashed var(--line);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
