
:root {
  --bg: #3f4144;
  --bg-2: #4a4c50;
  --card: #4a4c50;
  --card-soft: #56595d;
  --text: #f4f5f6;
  --muted: #d1d5d8;
  --border: rgba(255,255,255,.10);
  --shadow: rgba(0,0,0,.26);
  --success: #8cc63f;
  --danger: #e4572e;
  --patient: #5bc0de;
  --op: #f39c12;
  --analgesia: #e4572e;
  --coanalgesia: #8cc63f;
  --pacu: #69c3d7;
  --topbar-grad-1: #37393c;
  --topbar-grad-2: #2c2e31;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, #383a3d 100%);
  color: var(--text);
}
a { color: inherit; }
.topbar {
  background: linear-gradient(135deg, var(--topbar-grad-1) 0%, var(--topbar-grad-2) 100%);
  border-bottom: none;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 6px 22px rgba(0,0,0,.28);
}
.topbar::after {
  content: '';
  display: block;
  height: 4px;
  background: linear-gradient(90deg, #e4572e 0 25%, #f39c12 25% 50%, #5bc0de 50% 75%, #8cc63f 75% 100%);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: .95rem 1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.brand { font-weight: 800; letter-spacing: .02em; color: #fff; }
nav { display: flex; flex-wrap: wrap; gap: .7rem; }
nav a { color: #fff; text-decoration: none; padding: .55rem .8rem; border-radius: 12px; background: rgba(255,255,255,.08); }
.container { max-width: 1100px; margin: 1rem auto; padding: 0 1rem 2rem; }
.card, .auth-card {
  background: linear-gradient(180deg, rgba(255,255,255,.06) 0%, rgba(255,255,255,.035) 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 1rem;
  box-shadow: 0 10px 28px var(--shadow);
  backdrop-filter: blur(2px);
}
.app-card { padding-bottom: 6rem; }
.section-card {
  border-radius: 22px;
  padding: 1rem;
  margin-top: 1rem;
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}
.section-patient { background: linear-gradient(180deg, rgba(91,192,222,.18) 0%, rgba(91,192,222,.08) 100%); }
.section-op { background: linear-gradient(180deg, rgba(243,156,18,.18) 0%, rgba(243,156,18,.08) 100%); }
.section-analgesia { background: linear-gradient(180deg, rgba(228,87,46,.18) 0%, rgba(228,87,46,.08) 100%); }
.section-pacu { background: linear-gradient(180deg, rgba(140,198,63,.16) 0%, rgba(91,192,222,.08) 100%); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .9rem; }
.section-tag { display: inline-flex; padding: .35rem .6rem; border-radius: 999px; background: rgba(255,255,255,.10); font-size: .8rem; font-weight: 700; color: #fff; }
.card + .card { margin-top: 1rem; }
.card-header-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
h1 { font-size: 1.45rem; margin: 0 0 .35rem; }
h2 { font-size: 1.08rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 .75rem; }
label { display: block; font-size: .95rem; font-weight: 700; }
input, textarea, button { width: 100%; font: inherit; }
input, textarea {
  margin-top: .35rem;
  padding: .95rem 1rem;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.92);
  color: #1f1f1f;
  min-height: 56px;
}
textarea { min-height: 96px; resize: vertical; }
button, .button-link {
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e4572e 0%, #c8441f 100%);
  color: #fff; border: none; border-radius: 16px; padding: 1rem 1.1rem;
  text-decoration: none; text-align: center; font-weight: 800; cursor: pointer; min-height: 54px;
  box-shadow: 0 10px 22px rgba(228,87,46,.24);
}
.button-link.secondary, .slim { background: linear-gradient(135deg, #666a6e 0%, #4e5256 100%); box-shadow: none; }
.slim { min-height: 42px; padding: .7rem .9rem; border-radius: 12px; }
.form-grid { display: grid; gap: .9rem; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.compact-grid { margin-bottom: 1rem; }
.touch-group { margin-top: 1rem; }
.touch-label { margin-bottom: .55rem; font-size: .95rem; font-weight: 800; color: #fff; }
.touch-grid { display: grid; gap: .65rem; }
.touch-grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.touch-grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.touch-grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.touch-option { position: relative; display: block; }
.touch-option input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.touch-option span {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 64px; padding: .9rem .8rem;
  border-radius: 18px; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.10); font-weight: 700; line-height: 1.2; color: #fff;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.touch-option input:active + span { transform: scale(.98); }
.section-patient .touch-option input:checked + span { background: linear-gradient(135deg, #5bc0de 0%, #43a9c8 100%); color: #fff; border-color: transparent; box-shadow: 0 10px 22px rgba(91,192,222,.28); }
.section-op .touch-option input:checked + span { background: linear-gradient(135deg, #f39c12 0%, #d8890b 100%); color: #fff; border-color: transparent; box-shadow: 0 10px 22px rgba(243,156,18,.28); }
.section-analgesia .touch-option input:checked + span { background: linear-gradient(135deg, #e4572e 0%, #c8441f 100%); color: #fff; border-color: transparent; box-shadow: 0 10px 22px rgba(228,87,46,.28); }
.section-pacu .touch-option input:checked + span { background: linear-gradient(135deg, #8cc63f 0%, #76ad2b 100%); color: #fff; border-color: transparent; box-shadow: 0 10px 22px rgba(140,198,63,.28); }
.touch-option-checkbox input:checked + span { background: linear-gradient(135deg, #8cc63f 0%, #76ad2b 100%); color: #fff; }
.dual-drug-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.drug-card { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.10); border-radius: 20px; padding: 1rem; }
.alert { border-radius: 16px; padding: .95rem 1rem; margin-bottom: 1rem; font-weight: 700; border: 1px solid rgba(255,255,255,.08); }
.alert.error { background: rgba(228,87,46,.18); color: #fff; }
.alert.success { background: rgba(140,198,63,.18); color: #fff; }
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: min(100%, 460px); }
.small { font-size: .9rem; color: var(--muted); }
.actions { margin-top: 1rem; }
.sticky-actions { position: fixed; left: 0; right: 0; bottom: 0; padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(63,65,68,0) 0%, rgba(63,65,68,.94) 26%, rgba(63,65,68,1) 100%); z-index: 25; }
.primary-save { max-width: 1100px; margin: 0 auto; }
code { background: rgba(255,255,255,.10); padding: .15rem .35rem; border-radius: 6px; }
.mobile-case-list { display: grid; gap: .9rem; }
.case-row-card { border: 1px solid var(--border); border-radius: 20px; padding: .95rem; background: linear-gradient(180deg, rgba(255,255,255,.08) 0%, rgba(255,255,255,.04) 100%); }
.case-row-top { display: flex; justify-content: space-between; gap: .75rem; margin-bottom: .65rem; font-size: .95rem; }
.case-badges { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: .7rem; }
.badge { display: inline-flex; align-items: center; padding: .3rem .6rem; border-radius: 999px; background: rgba(228,87,46,.18); color: #fff; font-size: .8rem; font-weight: 800; }
.badge-soft { background: rgba(91,192,222,.16); color: #fff; }
.case-meta { display: grid; gap: .35rem; font-size: .92rem; color: #fff; }
.case-meta span { display: inline-block; min-width: 56px; color: var(--muted); font-weight: 700; }
.case-actions { margin-top: .75rem; }
.empty-state { padding: 1rem; text-align: center; background: rgba(255,255,255,.05); border: 1px dashed var(--border); border-radius: 18px; }
@media (max-width: 840px) {
  .form-grid.two, .dual-drug-grid, .touch-grid-4, .touch-grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  .topbar-inner, .card-header-row { align-items: stretch; flex-direction: column; }
  nav { width: 100%; }
  nav a, .button-link { width: 100%; }
  .container { padding: 0 .75rem 2rem; }
  .card, .auth-card, .section-card, .drug-card { border-radius: 18px; }
  .touch-grid-2, .touch-grid-3, .touch-grid-4, .form-grid.two, .dual-drug-grid { grid-template-columns: 1fr; }
  .touch-option span { min-height: 60px; }
}
.compact-top-gap { margin-top: 1rem; }
.single-strong-right .drug-card:last-child .touch-grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 840px) { .single-strong-right .drug-card:last-child .touch-grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 620px) { .single-strong-right .drug-card:last-child .touch-grid-4 { grid-template-columns: 1fr; } }

.stats-card { margin-bottom: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .9rem; margin-top: .8rem; }
.stat-box { border-radius: 20px; padding: 1rem; border: 1px solid rgba(255,255,255,.10); }
.stat-value { font-size: 1.45rem; font-weight: 900; margin-bottom: .25rem; }
.stat-label { color: var(--muted); font-size: .9rem; font-weight: 700; }
.stat-red { background: linear-gradient(180deg, rgba(228,87,46,.22), rgba(228,87,46,.08)); }
.stat-blue { background: linear-gradient(180deg, rgba(91,192,222,.22), rgba(91,192,222,.08)); }
.stat-green { background: linear-gradient(180deg, rgba(140,198,63,.22), rgba(140,198,63,.08)); }
.stat-orange { background: linear-gradient(180deg, rgba(243,156,18,.22), rgba(243,156,18,.08)); }
.stats-table-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .9rem; margin-top: 1rem; }
.mini-table-card { border-radius: 20px; padding: 1rem; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.10); overflow-x: auto; }
.mini-table { width: 100%; border-collapse: collapse; }
.mini-table th, .mini-table td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid rgba(255,255,255,.08); font-size: .92rem; }
.mini-table th { color: var(--muted); font-size: .82rem; }
.touch-option-pacu-checkbox input:checked + span { background: linear-gradient(135deg, #8cc63f 0%, #76ad2b 100%); }
@media (max-width: 840px) { .stat-grid, .stats-table-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 620px) { .stat-grid, .stats-table-grid { grid-template-columns: 1fr; } }

/* v5 adjustments */
.topbar {
  position: static;
}
.container {
  margin-top: .8rem;
}
.hero-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
}
.compact-stat-grid {
  grid-template-columns: repeat(4, minmax(0,1fr));
}
.compact-case-list {
  display: grid;
  gap: .75rem;
}
.compact-case-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: .85rem .95rem;
  background: linear-gradient(180deg, rgba(255,255,255,.08) 0%, rgba(255,255,255,.04) 100%);
}
.compact-row-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem .55rem;
  min-width: 0;
}
.compact-row-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.compact-row-actions form { margin: 0; }
.compact-id {
  font-weight: 900;
  color: #fff;
}
.compact-date {
  color: var(--muted);
  font-size: .92rem;
}
.compact-pill {
  display: inline-flex;
  align-items: center;
  padding: .28rem .55rem;
  border-radius: 999px;
  background: rgba(228,87,46,.18);
  font-size: .8rem;
  font-weight: 800;
}
.compact-pill.soft {
  background: rgba(91,192,222,.14);
}
.compact-text {
  font-size: .9rem;
  color: #fff;
}
.compact-text.muted {
  color: var(--muted);
}
.pagination {
  display: flex;
  gap: .75rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
.top-pagination {
  justify-content: flex-end;
}
.bottom-pagination {
  margin-top: 1rem;
}
.pagination-info {
  color: var(--muted);
  font-weight: 700;
}
.button-link.danger, button.button-link.danger, .delete-button {
  background: linear-gradient(135deg, #8f2f20 0%, #6f2015 100%);
  box-shadow: none;
}
.stats-table-grid-wide {
  grid-template-columns: repeat(2, minmax(0,1fr));
}
.span-2 {
  grid-column: span 2;
}
@media (max-width: 840px) {
  .compact-case-row {
    flex-direction: column;
    align-items: stretch;
  }
  .compact-row-actions {
    justify-content: stretch;
  }
  .compact-row-actions > *, .compact-row-actions form {
    flex: 1 1 0;
  }
  .compact-row-actions .button-link, .compact-row-actions button {
    width: 100%;
  }
}
@media (max-width: 620px) {
  .compact-stat-grid,
  .stats-table-grid-wide {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: span 1;
  }
  .top-pagination {
    justify-content: center;
  }
}
