:root {
  --bg-primary: #0a0e14;
  --bg-secondary: #111820;
  --bg-card: #161e28;
  --bg-elevated: #1c2534;
  --border: #1e2d3d;
  --border-bright: #2a3f55;

  --text-primary: #e8f0f8;
  --text-secondary: #7a9ab8;
  --text-muted: #4a6a88;

  --red: #e84040;
  --yellow: #f0a030;
  --green: #30c060;
  --blue: #3090e8;
  --blue-dim: #1a4a78;

  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;
  --font-body: 'IBM Plex Sans', Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --nav-height: 70px;
  --nav-safe-height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  --header-height: 56px;
  --tap-min: 48px;

  --specialty-primary: var(--blue);
  --specialty-secondary: var(--blue);
  --specialty-bg: var(--bg-primary);
  --specialty-card-border: var(--border);
  --specialty-header-bg: var(--bg-secondary);
  --specialty-badge: var(--blue);
  --specialty-badge-text: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Keyboard users should never lose their place in the dark theme. */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
  box-shadow: 0 0 0 2px var(--bg-primary);
}

:where(input, select, textarea) {
  max-width: 100%;
}

.clinical-validation-error {
  color: #ff8f8f;
  font-size: 0.8125rem;
  line-height: 1.4;
  margin-top: 4px;
}

@media (max-width: 700px) {
  .patient-bar { flex-wrap: wrap; }
  .patient-bar > * { min-width: min(100%, 140px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

body.auth-pending > :not(#auth-root),
body.auth-signed-out > :not(#auth-root) {
  display: none !important;
}

#auth-root {
  position: relative;
  z-index: 10000;
}

.auth-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 0%, rgba(232, 64, 64, 0.16), transparent 42%), #0a0e14;
  color: #f4f7fa;
  font-family: 'IBM Plex Sans', sans-serif;
}

.auth-landing {
  width: min(760px, 100%);
  text-align: center;
}

.auth-brand {
  margin: 0 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2vw, 18px);
  font: 700 clamp(36px, 7vw, 60px)/1 'JetBrains Mono', monospace;
  letter-spacing: -0.05em;
}

.auth-brand img {
  width: clamp(64px, 11vw, 96px);
  height: clamp(64px, 11vw, 96px);
  object-fit: contain;
  flex: 0 0 auto;
}

.auth-eyebrow {
  color: #e84040;
  font:
    700 12px/1.4 'JetBrains Mono',
    monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.auth-title {
  margin: 24px auto 12px;
  max-width: 680px;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.1;
}

.auth-copy {
  max-width: 620px;
  margin: 0 auto;
  color: #aeb8c4;
  font-size: 17px;
  line-height: 1.6;
}

.auth-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 30px;
  flex-wrap: wrap;
}

.auth-primary,
.auth-secondary,
.auth-account-button,
.auth-menu button {
  border: 0;
  cursor: pointer;
  font:
    600 14px/1 'IBM Plex Sans',
    sans-serif;
}

.auth-primary,
.auth-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 150px;
  padding: 15px 22px;
  border-radius: 10px;
  text-decoration: none;
}

.auth-primary {
  background: #e84040;
  color: #fff;
}
.auth-primary:hover {
  background: #fa5050;
}

.auth-secondary {
  border: 1px solid #34404e;
  background: #151c25;
  color: #f4f7fa;
}

.auth-note {
  margin-top: 34px;
  color: #727f8d;
  font-size: 12px;
}

.auth-account {
  position: relative;
}

.auth-account-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e84040;
  color: #fff;
}

.auth-menu {
  position: absolute;
  top: 44px;
  right: 0;
  width: 300px;
  max-width: min(300px, calc(100vw - 24px));
  max-height: min(680px, calc(100dvh - 64px));
  overflow-y: auto;
  padding: 10px;
  border: 1px solid #2a3542;
  border-radius: 12px;
  background: #151c25;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  overscroll-behavior: contain;
  z-index: 1000;
}

.auth-menu-name,
.auth-menu-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-menu-name {
  color: #f4f7fa;
  font-weight: 600;
}

.auth-menu-email {
  margin: 4px 0 10px;
  color: #8d99a6;
  font-size: 12px;
}

.auth-menu button {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: #252f3b;
  color: #f4f7fa;
}

.auth-menu button:disabled,
.auth-primary:disabled,
.auth-secondary:disabled {
  cursor: wait;
  opacity: 0.6;
}

.auth-profile-divider {
  height: 1px;
  margin: 10px 0;
  background: #2a3542;
}

.auth-profile-title {
  margin-bottom: 8px;
  color: #e84040;
  font:
    700 11px/1.4 'JetBrains Mono',
    monospace;
  letter-spacing: 0.12em;
}

.auth-profile-readonly,
.auth-profile-plan {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 7px 0;
  color: #8d99a6;
  font-size: 12px;
}

.auth-profile-readonly strong,
.auth-profile-plan strong {
  overflow: hidden;
  color: #f4f7fa;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-profile-field {
  display: grid;
  gap: 5px;
  margin: 9px 0;
  color: #aeb8c4;
  font-size: 12px;
}

.auth-profile-field select {
  width: 100%;
  border: 1px solid #34404e;
  border-radius: 7px;
  padding: 8px 9px;
  background: #0f151d;
  color: #f4f7fa;
  font:
    500 13px 'IBM Plex Sans',
    sans-serif;
}

.auth-profile-field select:disabled {
  cursor: wait;
  opacity: 0.65;
}

.auth-menu .auth-profile-manage {
  margin: 6px 0;
  border: 1px solid #34404e;
  background: transparent;
  color: #f4f7fa;
}

.profile-migration-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 8, 12, 0.84);
}

.profile-migration-dialog {
  width: min(420px, 100%);
  border: 1px solid #34404e;
  border-radius: 16px;
  padding: 24px;
  background: #151c25;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  color: #f4f7fa;
}

.profile-migration-kicker {
  margin-bottom: 10px;
  color: #e84040;
  font:
    700 11px/1.4 'JetBrains Mono',
    monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.profile-migration-dialog h2 {
  margin: 0 0 12px;
  font:
    700 22px/1.2 'JetBrains Mono',
    monospace;
}

.profile-migration-dialog p {
  margin: 8px 0;
  color: #aeb8c4;
  font-size: 14px;
  line-height: 1.5;
}

.profile-migration-actions {
  display: grid;
  gap: 9px;
  margin-top: 20px;
}

.profile-migration-actions .auth-primary,
.profile-migration-actions .auth-secondary {
  width: 100%;
}

.profile-migration-dialog small {
  display: block;
  margin-top: 14px;
  color: #727f8d;
  font-size: 11px;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: min(100%, 480px);
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

#app-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 100%;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.app-logo {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.app-logo img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex: 0 0 auto;
}

.app-logo .accent {
  color: var(--red);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.icon-btn:active {
  opacity: 0.7;
}

#screen-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--nav-safe-height);
  -webkit-overflow-scrolling: touch;
}

.screen {
  display: none;
  padding: 16px;
  animation: fadeIn 150ms ease;
}
.screen.active {
  display: block;
}

.screen-loading-status {
  padding: 28px 12px;
  color: var(--text-secondary);
  text-align: center;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#bottom-nav {
  height: var(--nav-safe-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  min-height: var(--tap-min);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
  padding: 4px 2px;
}

.nav-item.active {
  color: var(--blue);
}
.nav-item:active {
  opacity: 0.7;
}

.nav-item.nav-action-pending::after,
.sidebar-nav-item.nav-action-pending::after {
  content: '';
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: navActionSpin 0.7s linear infinite;
  pointer-events: none;
}

@keyframes navActionSpin {
  to { transform: rotate(360deg); }
}

.nav-code {
  color: var(--red) !important;
  font-weight: 700;
}

.nav-icon {
  font-size: 20px;
  line-height: 1;
}
.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  max-width: 100%;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition:
    border-color 0.15s,
    background 0.15s,
    transform 0.1s;
}

.card[style*='cursor:pointer']:hover,
.card[style*='cursor: pointer']:hover {
  border-color: var(--specialty-primary, var(--blue));
  background: var(--bg-elevated);
  transform: translateY(-1px);
}

.card-title {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-red {
  background: rgba(232, 64, 64, 0.15);
  color: var(--red);
  border: 1px solid rgba(232, 64, 64, 0.3);
}
.badge-yellow {
  background: rgba(240, 160, 48, 0.15);
  color: var(--yellow);
  border: 1px solid rgba(240, 160, 48, 0.3);
}
.badge-green {
  background: rgba(48, 192, 96, 0.15);
  color: var(--green);
  border: 1px solid rgba(48, 192, 96, 0.3);
}
.badge-blue {
  background: rgba(48, 144, 232, 0.15);
  color: var(--blue);
  border: 1px solid rgba(48, 144, 232, 0.3);
}
.badge-purple {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
  border: 1px solid rgba(168, 85, 247, 0.3);
}
.badge-orange {
  background: rgba(232, 130, 10, 0.15);
  color: #e8820a;
  border: 1px solid rgba(232, 130, 10, 0.3);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--tap-min);
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  opacity: 0.75;
}
.btn-primary {
  background: var(--blue);
  color: #fff;
  width: 100%;
}
.btn-danger {
  background: var(--red);
  color: #fff;
  width: 100%;
}
.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

input,
select,
textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  padding: 12px 14px;
  width: 100%;
  min-height: var(--tap-min);
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}
input::placeholder {
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.section-header {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 20px 0 10px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.quick-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 80px;
  transition:
    border-color 0.15s,
    background 0.15s;
  -webkit-tap-highlight-color: transparent;
  color: inherit;
  font-family: inherit;
  width: 100%;
}

.quick-item:active {
  background: var(--bg-elevated);
  border-color: var(--blue-dim);
}
.quick-item-icon {
  font-size: 22px;
}
.quick-item-label {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--text-secondary);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

#search-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 999;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

#search-overlay.hidden {
  display: none;
}

.search-loading-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-secondary);
  text-align: center;
}

.search-loading-state button {
  min-height: 44px;
  padding: 8px 20px;
  color: var(--blue);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.search-input-wrap {
  flex: 1;
  position: relative;
}

.search-input-wrap input {
  padding-left: 40px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search-results {
  flex: 1;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: none;
  color: inherit;
  font-family: inherit;
  text-align: left;
  width: 100%;
}

.search-result-item,
.search-result-item:hover,
.search-result-item:visited {
  text-decoration: none;
  color: inherit;
}

.search-result-item:active {
  opacity: 0.7;
}
.search-result-name {
  font-size: 15px;
  font-weight: 500;
}
.search-result-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.right-panel-chip,
.right-panel-quick,
.recent-chip,
.desktop-search-item {
  color: inherit;
  font-family: inherit;
  border: 0;
}

button.card {
  width: 100%;
  color: inherit;
  font-family: inherit;
  text-align: left;
}

#resus-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#resus-overlay.hidden {
  display: none;
}

.resus-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.resus-protocol-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 40px;
}

.resus-step-counter {
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 6px;
}

.resus-main-action {
  margin-top: 24px;
  background: rgba(232, 64, 64, 0.15);
  border: 2px solid var(--red);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
}

.resus-action-text {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.resus-action-sub {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 8px;
}

.resus-drug-line {
  margin-top: 20px;
  background: rgba(48, 144, 232, 0.1);
  border: 1px solid var(--blue-dim);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--blue);
}

.resus-next-step {
  margin-top: 16px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
}

.resus-next-step span {
  color: rgba(255, 255, 255, 0.7);
}

.resus-timer {
  font-family: var(--font-mono);
  font-size: 36px;
  font-weight: 700;
  color: var(--yellow);
  text-align: center;
  margin-top: 20px;
}

.resus-nav {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: auto;
  padding-top: 20px;
}

.hidden {
  display: none !important;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}
.text-center {
  text-align: center;
}
.text-red {
  color: var(--red);
}
.text-yellow {
  color: var(--yellow);
}
.text-green {
  color: var(--green);
}
.text-blue {
  color: var(--blue);
}
.text-muted {
  color: var(--text-muted);
}
.mono {
  font-family: var(--font-mono);
}

/* Desktop mode specific fixes */
.mobile-only-flex {
  display: flex;
}
.header-search-desktop {
  display: none;
}
.header-layout-toggle {
  display: flex;
}

/* Desktop layout applies whenever .desktop-mode is active, regardless of screen width */
.desktop-mode #app {
  width: 100%;
  max-width: 100%;
  flex-direction: row;
  padding-top: 64px; /* Space for fixed header */
}

.desktop-mode #app-header {
  height: 64px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

.desktop-mode .header-inner {
  max-width: 1600px;
  margin: 0 auto;
}

.desktop-mode .mobile-only-flex {
  display: none !important;
}

.desktop-mode .header-search-desktop {
  display: flex;
  align-items: center;
  position: relative;
  width: 400px;
  margin: 0 auto;
}

.desktop-mode .header-search-desktop input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 8px 16px 8px 40px;
  width: 100%;
  height: 40px;
  font-size: 14px;
  min-height: auto;
  transition: all 0.2s ease;
}

.desktop-mode .header-search-desktop input:focus {
  border-color: var(--specialty-primary, var(--blue));
  box-shadow: 0 0 0 1px rgba(var(--specialty-primary-rgb, 48, 144, 232), 0.3);
}

.desktop-mode .search-icon-inline {
  position: absolute;
  left: 14px;
  font-size: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.desktop-mode #desktop-search-results {
  position: absolute;
  top: 48px;
  left: 0;
  width: 100%;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 200;
}

.desktop-mode .desktop-search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.desktop-mode .desktop-search-item:hover {
  background: var(--bg-elevated);
}

.desktop-mode .desktop-search-name {
  font-size: 14px;
  font-weight: 600;
}

.desktop-mode .desktop-search-sub {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.desktop-mode #bottom-nav {
  display: none;
}

.desktop-mode #sidebar-nav {
  display: flex;
}

.desktop-mode #screen-container {
  padding-bottom: 0;
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.desktop-mode .screen {
  width: 100%;
  max-width: 900px;
  padding: 32px;
  margin: 0 auto;
}

/* Multi-column grid updates */
.desktop-mode .quick-grid {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.desktop-mode .drug-list,
.desktop-mode .score-list,
.desktop-mode .diagnosis-list,
.desktop-mode .protocol-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

.desktop-mode .drug-list .card,
.desktop-mode .score-list .card,
.desktop-mode .diagnosis-list .card,
.desktop-mode .protocol-list .card {
  margin-bottom: 0 !important;
  max-width: none !important;
}

/* Reset single column for detail views */
.desktop-mode #screen-drugs .card,
.desktop-mode #screen-calculators .score-field,
.desktop-mode #screen-more .dx-section-body,
.desktop-mode #screen-more .card,
.desktop-mode #screen-protocols .proto-detail-step {
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

.desktop-mode #screen-drugs h2,
.desktop-mode #screen-drugs .section-header,
.desktop-mode #screen-calculators h2,
.desktop-mode #screen-calculators .section-header,
.desktop-mode #screen-more h2,
.desktop-mode #screen-more .section-header,
.desktop-mode #screen-protocols h2,
.desktop-mode #screen-protocols .section-header,
.desktop-mode #screen-drugs .patient-bar,
.desktop-mode #screen-calculators .patient-bar,
.desktop-mode #screen-protocols .patient-bar,
.desktop-mode #screen-drugs .detail-back,
.desktop-mode #screen-calculators .detail-back,
.desktop-mode #screen-more .detail-back,
.desktop-mode #screen-protocols .detail-back {
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

/* Modals center in viewport */
.desktop-mode .onboarding-content {
  max-width: 600px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.desktop-mode #specialty-selector > div {
  max-width: 600px !important;
}

.sidebar-nav {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: none;
  flex-direction: column;
  padding: 0 0 20px 0;
  height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  display: none; /* Only show in very tall mode if we want, or keep it hidden if header has it */
}

.onboarding-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
  color: var(--text-primary);
  font: 700 24px/1 var(--font-mono);
  letter-spacing: -0.04em;
}

.onboarding-brand img {
  width: 52px;
  height: 52px;
  object-fit: contain;
}

.specialty-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-primary);
  font: 700 36px/1 var(--font-mono);
  letter-spacing: -0.05em;
}

.specialty-brand img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

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

@media (max-width: 520px) {
  .auth-brand {
    flex-direction: column;
    gap: 8px;
  }

  .app-logo {
    font-size: 17px;
    gap: 6px;
  }

  .app-logo img {
    width: 30px;
    height: 30px;
  }

  .auth-menu {
    position: fixed;
    top: calc(var(--header-height) + 4px);
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
    max-height: calc(100dvh - var(--header-height) - 12px);
  }

  .patient-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .patient-bar > * {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 380px) {
  .header-inner {
    padding: 0 8px;
  }

  .header-actions {
    gap: 0;
  }

  .icon-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 6px;
  }

  .app-logo {
    font-size: 15px;
    gap: 4px;
  }

  .app-logo img {
    width: 28px;
    height: 28px;
  }

  .nav-label {
    font-size: 9px;
    letter-spacing: 0;
  }
}

@media (max-width: 360px) {
  .quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 15px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition:
    background 0.15s,
    color 0.15s;
  position: relative;
}

.sidebar-nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.sidebar-nav-item.active {
  background: var(--specialty-primary, var(--blue));
  color: #fff;
}

.sidebar-nav-icon {
  font-size: 20px;
  width: 24px;
  text-align: center;
}

.sidebar-nav-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.desktop-right-panel {
  display: none;
}

@media (min-width: 1440px) {
  .desktop-mode .desktop-right-panel {
    display: block;
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    height: calc(100vh - 64px);
    position: sticky;
    top: 64px;
    padding: 20px;
    overflow-y: auto;
    flex-shrink: 0;
  }
}

.right-panel-chip,
.right-panel-quick {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.right-panel-quick {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.right-panel-chip:hover,
.right-panel-quick:hover {
  background: var(--bg-elevated);
  border-color: var(--specialty-primary, var(--blue));
}

/* Keep an explicit desktop preference usable on phones and small tablets. */
@media (max-width: 700px) {
  .desktop-mode #app {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex-direction: column;
    padding-top: 56px;
  }

  .desktop-mode #app-header {
    height: 56px;
    left: 0;
    right: 0;
  }

  .desktop-mode .header-inner {
    max-width: 100%;
    padding: 0 8px;
    gap: 4px;
  }

  .desktop-mode .app-logo {
    min-width: 0;
    gap: 6px;
    font-size: 17px;
  }

  .desktop-mode .header-search-desktop,
  .desktop-mode #sidebar-container,
  .desktop-mode #sidebar-nav {
    display: none !important;
  }

  .desktop-mode .mobile-only-flex {
    display: flex !important;
  }

  .desktop-mode .header-actions {
    flex: 0 0 auto;
    gap: 0;
  }

  .desktop-mode #bottom-nav {
    display: flex;
  }

  .desktop-mode #screen-container {
    width: 100%;
    min-width: 0;
    padding-bottom: var(--nav-safe-height);
    justify-content: flex-start;
  }

  .desktop-mode .screen {
    width: 100%;
    min-width: 0;
    padding: 20px 16px;
  }
}
