: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', monospace;
  --font-body: 'IBM Plex Sans', sans-serif;

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

  --nav-height: 70px;
  --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;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

#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;
}

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

.app-logo {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-primary);
}

.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-height);
  -webkit-overflow-scrolling: touch;
}

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

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

#bottom-nav {
  height: var(--nav-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;
}

.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;
}

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

.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; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.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 { border-color: var(--blue); }
input::placeholder { color: var(--text-muted); }

.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;
}

.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; }

#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-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-bottom: 1px solid var(--border);
  cursor: pointer;
}

.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; }

#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); }
