:root {
  --bg: #1c140b;
  --surface: #271c10;
  --surface-2: #332515;
  --border: #4d3820;
  --text: #fbf4e8;
  --muted: #cbb799;
  --ochre: #d99b26;
  --ochre-bright: #f2b749;
  --ochre-deep: #9e6514;
  --emerald: #10b981;
  --amber: #f59e0b;
  --orange: #f97316;
  --red: #ef4444;
  --sky: #38bdf8;
  --radius: 14px;
  --nav-h: 68px;
}

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

html, body {
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

.hidden {
  display: none !important;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(28, 20, 11, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.header-inner {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: linear-gradient(135deg, var(--ochre-bright), var(--ochre-deep));
  color: #1c140b;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 5px 8px;
  border-radius: 8px;
}

.brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--muted);
}

.mode-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ochre-bright);
}

/* Main & Views */
.app-main {
  max-width: 740px;
  margin: 0 auto;
  padding: 14px 14px 24px;
}

.view {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.view.active {
  display: flex;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h2 {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.hint-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(242, 183, 73, 0.14);
  color: var(--ochre-bright);
  border: 1px solid rgba(242, 183, 73, 0.3);
}

.muted-text {
  font-size: 0.82rem;
  color: var(--muted);
}

.mt-sm { margin-top: 10px; }
.mt-md { margin-top: 14px; }

/* Grids & Fields */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

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

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

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field > span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.traffic-light {
  font-size: 0.9rem;
  line-height: 1;
}

.field > span strong {
  color: var(--ochre-bright);
}

.field input,
.field select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.98rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
  border-color: var(--ochre-bright);
  box-shadow: 0 0 0 2px rgba(242, 183, 73, 0.2);
}

.field.field-uncertain input {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.12);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.22);
}

.field.field-uncertain > span {
  color: #fca5a5;
}

.input-with-btn {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.input-with-btn input {
  flex: 1 1 160px;
}

/* Upload Box */
.upload-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 14px;
  background: var(--surface-2);
  border: 1.5px dashed var(--ochre);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.upload-box:hover {
  background: #3d2c19;
  border-color: var(--ochre-bright);
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.upload-icon {
  font-size: 1.8rem;
}

.upload-placeholder strong {
  font-size: 0.9rem;
  color: var(--text);
}

.upload-placeholder small {
  font-size: 0.76rem;
  color: var(--muted);
}

.upload-thumbs {
  display: flex;
  justify-content: center;
  width: 100%;
}

.upload-thumbs img {
  max-height: 220px;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: contain;
}

/* Buttons */
.actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.actions-row .btn-primary,
.actions-row .btn-secondary {
  flex: 1;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button,
.file-btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 11px;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 11px 16px;
  transition: transform 0.08s ease, opacity 0.15s ease, background-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--ochre-bright), var(--ochre));
  color: #1c140b;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--ochre-bright);
  border: 1px solid var(--ochre);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

/* Status & Alerts */
.status-msg {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.status-msg.warn {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fde68a;
}

.status-msg.error {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.status-msg.ok {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.38);
  color: #a7f3d0;
}

/* WHO Box */
.who-box {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.who-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.who-badge {
  font-size: 0.8rem;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
}

.who-badge.optimal,
.who-badge.normal {
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
}

.who-badge.high-normal {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

.who-badge.grade1 {
  background: rgba(249, 115, 22, 0.2);
  color: #fdba74;
}

.who-badge.grade2,
.who-badge.grade3,
.who-badge.hypotension {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.pp-badge {
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
}

.who-desc {
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Details */
.extra-details summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--ochre-bright);
  font-weight: 600;
  padding: 4px 0;
}

/* History & Dashboard */
.last-reading-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ochre-bright);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.last-reading-strip strong {
  color: var(--ochre-bright);
  font-size: 0.9rem;
}

.chart-container {
  width: 100%;
  min-height: 210px;
}

.chart-empty {
  padding: 32px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.84rem;
}

.chart-toggles,
.filter-pills {
  display: flex;
  gap: 6px;
}

.chart-toggle-btn,
.filter-btn {
  padding: 5px 10px;
  font-size: 0.76rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.chart-toggle-btn[aria-pressed="true"],
.filter-btn.active {
  background: rgba(242, 183, 73, 0.18);
  color: var(--ochre-bright);
  border-color: var(--ochre);
}

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

.avg-card {
  padding: 12px;
  text-align: center;
}

.avg-kicker {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

.avg-val-row {
  margin: 4px 0 2px;
}

.avg-val {
  font-size: 1.35rem;
  color: var(--ochre-bright);
  font-weight: 800;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-date {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.history-values {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.history-bp {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
}

.history-pulse {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ochre-bright);
}

.history-meta {
  font-size: 0.76rem;
  color: var(--muted);
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(28, 20, 11, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 30;
}

.nav-btn {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 0;
  flex-direction: column;
  gap: 3px;
  padding: 8px 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

.nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.nav-btn.active {
  color: var(--ochre-bright);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--ochre);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-width: 90vw;
  text-align: center;
}
