/* Blood Pressure & Heart Rate Tracker — mobile-first styles */

/* Dark is the default theme; [data-theme="light"] below overrides it. */
:root {
  --color-bg: #0d0f13;
  --color-surface: #1c1f26;
  --color-text: #e8eaed;
  --color-muted: #97a0ad;
  --color-primary: #4f83f1;
  --color-primary-dark: #3b6fd8;
  --color-danger: #f0575a;
  --color-danger-dark: #d63b3b;
  --color-danger-bg: #3a1f22;
  --color-danger-border: #5c2a2f;
  --color-nav-active-bg: #1e293b;
  --color-border: #2e323c;
  --radius: 10px;
  --tap-height: 44px;
}

[data-theme="light"] {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-text: #1a1f2b;
  --color-muted: #5b6472;
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-danger-dark: #b91c1c;
  --color-danger-bg: #fdecec;
  --color-danger-border: #f5c2c2;
  --color-nav-active-bg: #eef2ff;
  --color-border: #d7dce3;
}

* {
  box-sizing: border-box;
}

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

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding: 16px;
}

.container {
  max-width: 640px;
  margin: 0 auto;
}

/* Sidebar navigation shell (authenticated pages only) */

body.app-body {
  padding: 0;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: 84px; /* clears the fixed bottom tab bar on mobile */
}

.sidebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.06);
  z-index: 10;
}

.sidebar-brand {
  display: none;
}

.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  min-height: 56px;
  padding: 6px 4px;
  color: var(--color-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  background: transparent;
}

.nav-link:active {
  background: transparent;
}

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

.nav-link.active {
  color: var(--color-primary);
}

@media (min-width: 768px) {
  .app-shell {
    flex-direction: row;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: auto;
    bottom: 0;
    width: 200px;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    border-top: none;
    border-right: 1px solid var(--color-border);
    box-shadow: 1px 0 4px rgba(0, 0, 0, 0.06);
    padding: 20px 0;
  }

  .sidebar-brand {
    display: block;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0 20px 20px;
  }

  .nav-link {
    flex: none; /* reset the mobile bottom-tab-bar's flex: 1 (equal-width row
                   items) — in the desktop column layout it would otherwise
                   stretch each link to fill the sidebar's full height. */
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    min-height: var(--tap-height);
    padding: 10px 20px;
    font-size: 0.95rem;
  }

  .nav-link.active {
    background: var(--color-nav-active-bg);
    border-right: 3px solid var(--color-primary);
  }

  .main-content {
    margin-left: 200px;
    padding: 24px;
    padding-bottom: 24px;
  }
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 16px;
}

h2 {
  font-size: 1.15rem;
  margin: 24px 0 12px;
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  margin-bottom: 20px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 8px;
}

.top-bar h1 {
  margin: 0;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 12px 0 4px;
  color: var(--color-muted);
}

label:first-child {
  margin-top: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"] {
  width: 100%;
  min-height: var(--tap-height);
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  -webkit-appearance: none;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-height);
  min-width: 44px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  text-decoration: none;
  touch-action: manipulation;
}

button:active,
.btn:active {
  background: var(--color-primary-dark);
}

button.secondary,
.btn.secondary {
  background: var(--color-border);
  color: var(--color-text);
}

button.danger,
.btn.danger {
  background: var(--color-danger);
}

button.danger:active,
.btn.danger:active {
  background: var(--color-danger-dark);
}

.btn-block {
  width: 100%;
  margin-top: 16px;
}

.error-message {
  color: var(--color-danger);
  background: var(--color-danger-bg);
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 0.9rem;
  display: none;
}

.error-message.visible {
  display: block;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  min-height: unset;
  width: 44px;
  padding: 0;
  background: transparent;
  color: var(--color-muted);
  font-size: 1.1rem;
  line-height: 1;
}

.password-toggle:active {
  background: transparent;
}

/* Safari renders its own built-in key/autofill icon inside password fields
   (::-webkit-credentials-auto-fill-button), anchored to the same right edge
   as our custom toggle. The two overlapping controls crash Safari's own
   autofill script (ReferenceError: Can't find variable: output) — hide
   Safari's icon since we provide our own show/hide toggle. */
input[type="password"]::-webkit-credentials-auto-fill-button,
input[type="password"]::-webkit-strong-password-auto-fill-button {
  visibility: hidden;
  display: none !important;
  pointer-events: none;
  position: absolute;
  right: 0;
}

.auth-links {
  margin-top: 16px;
  text-align: center;
  font-size: 0.95rem;
}

.auth-links a {
  color: var(--color-primary);
}

/* Table / history */

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 0;
  color: var(--color-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: unset;
  padding: 8px 6px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.sort-btn:active {
  background: transparent;
}

.sort-btn.active {
  color: var(--color-primary);
}

.sort-indicator {
  font-size: 0.75rem;
  min-width: 0.8em;
}

tbody td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody td input[type="number"],
tbody td input[type="datetime-local"] {
  min-height: 40px;
  font-size: 0.9rem;
  padding: 6px 8px;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions button {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

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

/* Delete confirmation */

.confirm-inline {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.confirm-text {
  font-size: 0.8rem;
  color: var(--color-muted);
  width: 100%;
}

@media (min-width: 480px) {
  body {
    padding: 24px;
  }

  .field-row.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
  }
}

/* Chart page: range filters, canvas, averages */

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.filter-btn {
  min-height: 38px;
  padding: 8px 14px;
  font-size: 0.85rem;
  background: var(--color-border);
  color: var(--color-text);
}

.filter-btn.active {
  background: var(--color-primary);
  color: #fff;
}

.chart-wrapper {
  position: relative;
  height: 320px;
}

.stat-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 20px;
}

.stat-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
}

@media (min-width: 480px) {
  .stat-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Theme toggle */

.theme-toggle {
  min-height: var(--tap-height);
  min-width: 44px;
  padding: 0;
  background: transparent;
  color: var(--color-text);
  font-size: 1.2rem;
  line-height: 1;
}

.theme-toggle:active {
  background: transparent;
}

/* The moon glyph (dark icon) is too low-contrast against a light background
   with no fill — give the button a subtle darker backing in light mode
   only. Dark mode's sun glyph is bright enough to stay transparent. */
[data-theme="light"] .theme-toggle {
  background: var(--color-muted);
}

[data-theme="light"] .theme-toggle:active {
  background: var(--color-text);
}

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

/* Icon-only row action buttons (Edit / Delete) */

.icon-btn {
  min-height: 38px;
  min-width: 38px;
  padding: 0;
  background: transparent;
  line-height: 1;
}

.icon-btn:active {
  background: transparent;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.btn-edit {
  color: var(--color-primary);
}

.btn-delete {
  color: var(--color-danger);
}
