:root {
  --bg: #f4f7f8;
  --panel: #ffffff;
  --ink: #162029;
  --muted: #687783;
  --line: #dce5e8;
  --primary: #116a71;
  --primary-strong: #0b4f55;
  --accent: #b84a3a;
  --success: #217a55;
  --warning: #a46800;
  --danger: #a73838;
  --shadow: 0 18px 50px rgba(14, 38, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(244, 247, 248, 0.84), rgba(244, 247, 248, 0.88)),
    url('/assets/fondo_clinica.jpg') center / cover fixed no-repeat,
    var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 18px 32px 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand-block {
  grid-column: 2;
  display: grid;
  justify-items: center;
  gap: 5px;
  text-align: center;
}

.clinic-logo {
  display: block;
  width: min(190px, 42vw);
  max-height: 76px;
  object-fit: contain;
}

.login-logo {
  display: block;
  justify-self: center;
  width: min(210px, 64vw);
  max-height: 92px;
  object-fit: contain;
}

.topbar h1,
.section-heading h2,
.login-box h2,
.drawer-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.session-tools,
.board-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.session-tools {
  grid-column: 3;
  justify-self: end;
}

.workflow-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.workflow-switcher span {
  white-space: nowrap;
}

.workflow-switcher select {
  min-height: 36px;
  min-width: 130px;
  padding: 6px 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
}

.status-muted {
  color: var(--muted);
  background: #f6f8f9;
}

.status-ready {
  color: var(--success);
  background: #edf8f3;
  border-color: #bbdfcf;
}

.status-error {
  color: var(--danger);
  background: #fff1f1;
  border-color: #edb8b8;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px 32px 36px;
}

.admission-panel,
.board-panel {
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admission-panel {
  align-self: start;
  padding: 22px;
}

.board-panel {
  padding: 22px;
  min-width: 0;
}

.section-heading {
  margin-bottom: 18px;
}

.board-heading {
  justify-content: space-between;
  flex-wrap: wrap;
}

.last-sync {
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #c7d4d8;
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #ffffff;
}

input:focus,
select:focus,
button:focus {
  outline: 3px solid rgba(17, 106, 113, 0.22);
  outline-offset: 2px;
}

.primary-button,
.secondary-button,
.move-button,
.panel-remove-button,
.history-button,
.icon-button {
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  padding: 10px 14px;
}

.primary-button:hover,
.move-button:hover {
  background: var(--primary-strong);
}

.secondary-button,
.history-button {
  color: var(--primary);
  background: #ffffff;
  border-color: #9fcbd0;
  padding: 9px 12px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  padding: 0;
  color: var(--primary);
  background: #ffffff;
  border-color: #9fcbd0;
  font-size: 22px;
  line-height: 1;
}

.form-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.form-message.error {
  color: var(--danger);
}

.form-message.ok {
  color: var(--success);
}

.admin-panel {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.station-admin {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.station-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.station-row {
  display: grid;
  grid-template-columns: 1fr 94px;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.station-name,
.station-status {
  margin: 0;
}

.station-name {
  font-size: 14px;
  font-weight: 800;
}

.station-status {
  font-size: 12px;
  font-weight: 700;
}

.station-status.active {
  color: var(--success);
}

.station-status.inactive {
  color: var(--danger);
}

.station-toggle-button {
  min-height: 34px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.station-toggle-button.deactivate {
  color: var(--danger);
  background: #ffffff;
  border: 1px solid #e0a5a5;
}

.station-toggle-button.activate {
  color: var(--success);
  background: #ffffff;
  border: 1px solid #91c6ae;
}

.station-toggle-button:disabled {
  cursor: not-allowed;
  color: var(--muted);
  border-color: var(--line);
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
  min-height: 440px;
}

.state-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfb;
}

.state-column header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.state-column h3 {
  margin: 0;
  font-size: 16px;
}

.count-badge {
  min-width: 30px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--primary);
  background: #e4f2f4;
  text-align: center;
  font-weight: 700;
}

.patient-list {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px;
}

.patient-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #cfdde1;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.patient-card[data-final="true"] {
  border-left-color: var(--success);
}

.patient-name {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.patient-doc,
.patient-time {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 112px 44px;
  gap: 8px;
}

.move-actions {
  display: grid;
  gap: 6px;
}

.move-button,
.panel-remove-button {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  padding: 8px 10px;
  font-size: 13px;
}

.panel-remove-button {
  color: var(--danger);
  background: #ffffff;
  border-color: #e0a5a5;
}

.move-button.discharge {
  background: var(--success);
  border-color: var(--success);
}

.move-button:disabled {
  cursor: not-allowed;
  color: #63727b;
  background: #eef2f3;
  border-color: #d6e0e3;
}

.history-button {
  min-width: 44px;
  padding: 0;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
  font-size: 14px;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(11, 31, 37, 0.58);
}

.login-overlay[hidden] {
  display: none;
}

.login-box {
  display: grid;
  gap: 14px;
  width: min(100%, 420px);
  padding: 26px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(100%, 460px);
  transform: translateX(100%);
  transition: transform 180ms ease;
  background: #ffffff;
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
}

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

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.history-content {
  display: grid;
  gap: 12px;
  padding: 18px 24px 30px;
  overflow: auto;
  max-height: calc(100vh - 102px);
}

.history-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.history-state {
  margin: 0;
  font-weight: 800;
}

.history-meta,
.history-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(11, 31, 37, 0.32);
}

.transfer-modal {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 180ms ease, transform 180ms ease;
}

.transfer-modal.open {
  opacity: 1;
  transform: scale(1);
}

.transfer-modal.closing {
  opacity: 0;
  transform: scale(0.98);
}

.transfer-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(100%, 480px);
  overflow: hidden;
  padding: 28px 28px 24px;
  border: 1px solid rgba(17, 106, 113, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 26px 70px rgba(11, 31, 37, 0.28);
  text-align: center;
  animation: transferPop 360ms ease both;
}

.transfer-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: #ffffff;
  background: var(--primary);
  font-size: 30px;
  font-weight: 900;
  animation: transferPulse 900ms ease-in-out infinite;
}

.transfer-card h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.transfer-card p {
  margin: 0;
}

.transfer-card #transferMessage {
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
}

.transfer-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 5px;
  width: 100%;
  background: var(--primary);
  transform-origin: left;
  animation: transferProgress 2s linear both;
}

@keyframes transferPop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes transferPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes transferProgress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .board {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar,
  .layout {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .session-tools {
    grid-column: 1;
    justify-self: stretch;
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .brand-block {
    grid-column: 1;
    justify-self: center;
  }

  .board {
    grid-template-columns: 1fr;
  }

  .card-actions {
    grid-template-columns: 1fr;
  }

  .history-button {
    width: 100%;
  }
}
