:root {
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0eb;
  --surface: #ffffff;
  --page: #f4f8fb;
  --primary: #1d5f9f;
  --primary-dark: #123d67;
  --teal: #1ba7a6;
  --amber: #f4b740;
  --green: #2f9b72;
  --gray: #7a8494;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.prebeta-banner {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  color: #17324d;
  background: #d9edf7;
  border-bottom: 1px solid #b6d6e8;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.02em;
}

.identity-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid #b6d6e8;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0;
}

.identity-pill:hover,
.identity-pill:focus {
  color: var(--primary-dark);
  background: #ffffff;
}

.account-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 10px 28px 0;
}

.account-bar form {
  margin: 0;
}

.app-version-footer {
  color: #6b7280;
  font-size: 0.75rem;
  padding: 0 28px 16px;
  text-align: right;
}

a {
  text-decoration: none;
}

.page-shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 28px;
}

.app-header,
.toolbar-panel,
.table-panel,
.form-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(23, 32, 51, 0.07);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 26px;
  margin-bottom: 18px;
}

.app-header h1,
.form-card h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.date-pill {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
  font-weight: 650;
}

.toolbar-panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  margin-bottom: 16px;
}

.day-nav,
.filters,
.toolbar-actions,
.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.custom-combobox {
  position: relative;
}

.custom-combobox-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  max-height: 248px;
  overflow-y: auto;
  padding: 6px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.custom-combobox-option {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-weight: 400;
  text-align: left;
}

.custom-combobox-option:hover,
.custom-combobox-option.is-active {
  color: var(--primary-dark);
  background: #eef6fc;
}

.custom-combobox-empty,
.custom-combobox-hint {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.filters {
  justify-content: flex-end;
}

.add-button {
  white-space: nowrap;
}

.toolbar-actions {
  justify-content: flex-end;
}

.counter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.counter-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 76px;
  padding: 16px 18px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
}

.counter-card span {
  color: var(--muted);
  font-weight: 650;
}

.counter-card strong {
  font-size: 1.8rem;
  line-height: 1;
}

.counter-waiting {
  border-left-color: var(--amber);
}

.counter-admitted {
  border-left-color: var(--green);
}

.counter-completed {
  border-left-color: var(--gray);
}

.table-panel {
  overflow: hidden;
}

.visit-table {
  margin: 0;
  min-width: 1120px;
}

.visit-table th {
  padding: 14px 12px;
  background: #eef4f8;
  color: var(--primary-dark);
  font-size: 0.86rem;
  text-align: center;
  white-space: nowrap;
}

.visit-table td {
  padding: 13px 12px;
  border-color: #e5ebf1;
}

.visit-row.status-admitted,
.visit-row.status-treatment,
.visit-row.status-doctor {
  background: #f6faf8;
  color: #53605c;
}

.visit-row.status-completed {
  background: #e7ebef;
  color: #596273;
}

.visit-row.status-completed td {
  background: #e7ebef;
}

.visit-row.status-completed strong,
.visit-row.status-completed .study-number {
  color: #344054;
}

.visit-row.status-completed .order-number,
.visit-row.status-completed .care-box {
  background: #f7f8fa;
  border-color: #cdd5df;
}

.visit-row {
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.order-cell {
  min-width: 122px;
  text-align: center;
}

.order-controls {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.order-number {
  display: inline-flex;
  width: 42px;
  height: 38px;
  align-items: center;
  justify-content: center;
  color: var(--primary-dark);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 1.05rem;
  font-weight: 800;
}

.order-number.empty {
  color: var(--muted);
}

.study-number {
  font-weight: 700;
  color: var(--primary-dark);
}

.status-badge {
  display: inline-flex;
  min-width: 104px;
  justify-content: center;
  align-items: center;
  padding: 7px 10px;
  border: 0;
  border-radius: 999px;
  font-weight: 750;
  font-size: 0.82rem;
}

.badge-scheduled {
  color: #475467;
  background: #eef1f4;
}

.badge-waiting {
  color: #6f4b00;
  background: #fff2c7;
}

.badge-admitted,
.badge-treatment,
.badge-doctor {
  color: #0f5b43;
  background: #dff5ed;
}

.badge-completed {
  color: #475467;
  background: #e3e7ec;
}

.status-dropdown .status-badge::after {
  content: "";
  width: 0;
  height: 0;
  margin-left: 8px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

.status-menu {
  min-width: 190px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-choice {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  border-radius: 6px;
}

.status-choice.active {
  color: var(--primary-dark);
  background: #eef6fc;
  font-weight: 700;
}

.status-dot {
  width: 12px;
  height: 12px;
  min-width: 12px;
  padding: 0;
  border-radius: 999px;
}

.care-pair {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.care-cell {
  min-width: 134px;
  white-space: nowrap;
}

.notify-cell {
  min-width: 74px;
  white-space: nowrap;
}

.tablet-cell {
  min-width: 92px;
  white-space: nowrap;
}

.care-toggle {
  display: flex;
  justify-content: center;
  flex: 0 0 auto;
}

.care-box {
  display: inline-grid;
  grid-template-columns: 14px auto;
  gap: 5px;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 32px;
  margin: 0;
  color: var(--primary-dark);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

.care-box input {
  width: 14px;
  height: 14px;
  accent-color: var(--teal);
}

.care-box span {
  font-size: 0.76rem;
}

.detail-toggle-cell {
  width: 34px;
  text-align: center;
}

.detail-toggle {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.detail-toggle .chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 140ms ease, color 140ms ease;
}

.detail-toggle.is-open .chevron {
  transform: rotate(-135deg);
}

.detail-toggle:hover,
.detail-toggle:focus {
  color: var(--primary);
  background: #eef6fc;
}

.detail-row td {
  background: #f8fbfd;
  padding: 0 14px 16px;
}

.detail-placeholder td {
  height: 0;
  padding: 0;
  border: 0;
}

.detail-row.is-hidden {
  display: none;
}

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.detail-panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.detail-panel dl {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 14px;
  margin: 0;
}

.detail-panel dt {
  color: var(--muted);
  font-weight: 650;
}

.detail-panel dd {
  margin: 0;
}

.history-panel {
  margin-top: 18px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.detail-actions form {
  margin: 0;
}

.history-list {
  margin: 8px 0 0;
  padding-left: 0;
  list-style: none;
}

.history-list li {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 18px;
  padding: 8px 0;
  border-top: 1px solid #edf1f5;
}

.history-list time {
  color: var(--primary-dark);
  font-weight: 750;
  white-space: nowrap;
}

.history-actor {
  color: var(--muted);
  font-weight: 650;
  white-space: nowrap;
}

.empty-state {
  padding: 42px;
  color: var(--muted);
  text-align: center;
}

.form-shell {
  display: flex;
  justify-content: center;
  padding: 36px 0;
}

.form-card {
  width: min(720px, 100%);
  padding: 26px;
}

.auth-shell {
  min-height: 62vh;
  align-items: center;
}

.auth-card {
  width: min(420px, 100%);
}

.form-card h1 {
  margin-bottom: 20px;
}

.presence-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 999px;
  background: #9ca3af;
}

.presence-dot.online {
  background: var(--green);
}

.auth-links {
  margin-top: 14px;
  text-align: center;
}

.account-details {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 14px;
  margin: 0 0 20px;
}

.account-details dt {
  color: var(--muted);
  font-weight: 650;
}

.account-details dd {
  margin: 0;
}

.user-toolbar {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 14px 16px;
}

.user-search-form {
  display: grid;
  grid-template-columns: minmax(260px, 520px) max-content;
  gap: 8px;
  align-items: center;
  justify-content: start;
}

.user-search-form .form-control {
  min-width: 0;
}

.message-stack {
  margin-bottom: 14px;
}

.account-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
}

.account-status-active {
  color: #0f5b43;
  background: #dff5ed;
}

.account-status-pending {
  color: #6f4b00;
  background: #fff2c7;
}

.account-status-disabled {
  color: #475467;
  background: #e3e7ec;
}

.table-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.table-actions form {
  margin: 0;
}

.search-offcanvas,
.staff-offcanvas {
  width: min(480px, 100vw);
}

.search-offcanvas .offcanvas-title,
.staff-offcanvas .offcanvas-title {
  font-size: 1.15rem;
  font-weight: 750;
}

.staff-section + .staff-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.staff-section h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 750;
}

.staff-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.staff-option-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.staff-option-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.staff-edit-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin: 0;
}

.staff-delete-form {
  margin: 0;
}

.staff-chip-form {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

.staff-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 8px 5px 10px;
  color: var(--primary-dark);
  background: #eef4f8;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 999px 0 0 999px;
  font-weight: 700;
}

.staff-remove-button {
  display: inline-flex;
  width: 30px;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  background: #eef4f8;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 999px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.staff-option-row .staff-remove-button {
  border-left: 1px solid var(--line);
  border-radius: 6px;
}

.staff-remove-button:hover,
.staff-remove-button:focus {
  color: #9b1c1c;
  background: #fdecec;
  border-color: #efc4c4;
}

.staff-add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.staff-empty {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.global-results {
  margin-top: 18px;
}

.result-count {
  margin-bottom: 12px;
  color: var(--muted);
}

.global-result-list {
  display: grid;
  gap: 10px;
}

.global-result {
  display: grid;
  gap: 3px;
  padding: 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.global-result span,
.global-result small {
  color: var(--muted);
}

.search-page-toolbar {
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(23, 32, 51, 0.07);
}

.search-page-form {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) repeat(4, minmax(150px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.search-summary {
  padding: 14px 16px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #fbfdfe;
}

.search-table {
  min-width: 1180px;
}

.drag-chosen {
  background: #ffffff !important;
  box-shadow: 0 16px 36px rgba(23, 32, 51, 0.18);
  transform: scale(1.01);
}

.drag-ghost {
  opacity: 0.55;
  background: #eaf5f8 !important;
}

.drag-active {
  cursor: grabbing;
}

@media (max-width: 1100px) {
  .toolbar-panel {
    grid-template-columns: 1fr;
  }

  .filters,
  .day-nav,
  .toolbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .page-shell {
    padding: 16px;
  }

  .app-header,
  .detail-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .counter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters > *,
  .day-nav > *,
  .toolbar-actions > *,
  .add-button,
  .search-page-form > *,
  .user-search-form > * {
    width: 100%;
  }

  .detail-panel dl {
    grid-template-columns: 1fr;
  }

  .account-details {
    grid-template-columns: 1fr;
  }

  .search-page-form {
    grid-template-columns: 1fr;
  }

  .user-search-form {
    grid-template-columns: 1fr;
  }

  .user-toolbar {
    width: 100%;
  }
}
