/* ===================================================
   BP Monitor — Styles
   Soft medical white theme with clean typography
   =================================================== */

:root {
  --bg: #f4f7f8;
  --bg-card: #ffffff;
  --bg-input: #f0f4f5;
  --text-primary: #1a2e35;
  --text-secondary: #5e7a82;
  --text-muted: #94aab0;
  --accent: #3a8a9e;
  --accent-light: #e1f0f4;
  --accent-dark: #2a6e80;
  --success: #4caf7d;
  --success-light: #e6f5ed;
  --warning: #e6a23c;
  --warning-light: #fdf2e0;
  --danger: #e25c5c;
  --danger-light: #fde8e8;
  --border: #e2eaec;
  --shadow-sm: 0 1px 3px rgba(26,46,53,0.06);
  --shadow-md: 0 4px 12px rgba(26,46,53,0.08);
  --shadow-lg: 0 8px 24px rgba(26,46,53,0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- Screens --- */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* --- PIN Screen --- */
.pin-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  background: linear-gradient(170deg, #f4f7f8 0%, #e1f0f4 100%);
}

.pin-icon {
  margin-bottom: 1rem;
  opacity: 0.85;
}

.pin-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.pin-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  min-height: 1.4em;
}

.pin-dots {
  display: flex;
  gap: 14px;
  margin-bottom: 2rem;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  transition: all 0.2s;
}

.pin-dot.filled {
  background: var(--accent);
  transform: scale(1.1);
}

.pin-dot.error {
  border-color: var(--danger);
  background: var(--danger);
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 12px;
  margin-bottom: 1.5rem;
}

.pin-key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}

.pin-key:active {
  background: var(--accent-light);
  transform: scale(0.95);
}

.pin-key-del, .pin-key-bio {
  border: none;
  background: transparent;
  box-shadow: none;
  color: var(--text-secondary);
}

.pin-biometric-btn {
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 0.5rem;
}

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 56px;
}

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

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.menu-btn, .back-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  display: flex;
  align-items: center;
}

.header-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  background: var(--accent-light);
  transition: background 0.2s;
}

.profile-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.profile-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-dark);
}

/* --- Side Menu --- */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,46,53,0.3);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.menu-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.side-menu {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100%;
  background: var(--bg-card);
  z-index: 100;
  transition: left 0.3s ease;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.side-menu.open {
  left: 0;
}

.menu-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.menu-header h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.menu-profiles {
  list-style: none;
  padding: 8px 0;
}

.menu-profiles li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s;
}

.menu-profiles li:hover, .menu-profiles li.active {
  background: var(--accent-light);
}

.menu-profiles li.active .profile-avatar {
  background: var(--accent-dark);
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.menu-actions {
  list-style: none;
  padding: 8px 0;
}

.menu-actions li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.menu-actions li:hover {
  background: var(--bg-input);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 100px;
}

/* --- Today Card --- */
.today-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.today-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.today-date {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.today-slots {
  display: flex;
  gap: 10px;
}

.slot {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.slot-icon {
  font-size: 1rem;
}

.slot-status {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 6px;
}

.slot-status.done {
  background: var(--success-light);
  color: var(--success);
}

.slot-status.pending {
  background: var(--warning-light);
  color: var(--warning);
}

/* --- Input Card --- */
.input-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.input-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.period-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.period-btn {
  flex: 1;
  padding: 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.period-btn.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent-dark);
}

.input-fields {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 16px;
}

.input-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.input-group input {
  width: 100%;
  padding: 12px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: center;
  transition: border-color 0.2s;
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent);
  background: #fff;
}

.input-group input.invalid {
  border-color: var(--danger);
  background: var(--danger-light);
}

.input-unit {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
}

.input-separator {
  font-size: 1.6rem;
  font-weight: 300;
  color: var(--text-muted);
  padding-bottom: 18px;
}

.input-pulse {
  margin-left: 8px;
}

.save-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(58,138,158,0.25);
}

.save-btn:active {
  transform: scale(0.98);
  background: var(--accent-dark);
}

.save-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --- History --- */
.history-section {
  margin-top: 4px;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

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

.history-day {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.history-day-header {
  padding: 10px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
}

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

.history-entry:last-child {
  border-bottom: none;
}

.history-entry:active {
  background: var(--bg-input);
}

.history-period {
  font-size: 1.1rem;
}

.history-values {
  flex: 1;
}

.history-bp {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

.history-bp .bp-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font);
  font-weight: 500;
  margin-left: 4px;
}

.history-pulse {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.history-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

.history-actions {
  display: flex;
  gap: 4px;
}

.history-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
  transition: all 0.15s;
}

.history-edit-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.loading-placeholder, .empty-placeholder {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.bp-category {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
}

.bp-normal { background: var(--success-light); color: var(--success); }
.bp-elevated { background: var(--warning-light); color: var(--warning); }
.bp-high { background: var(--danger-light); color: var(--danger); }

/* --- Export Screen --- */
.export-content {
  padding-top: 24px;
}

.export-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
}

.export-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
}

.export-select {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  outline: none;
  appearance: none;
  cursor: pointer;
}

.export-btn {
  margin-top: 12px;
}

.export-status {
  text-align: center;
  padding: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* --- Settings --- */
.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.settings-card h4 {
  font-size: 0.95rem;
  font-weight: 600;
  width: 100%;
}

.settings-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  flex: 1;
}

.settings-btn {
  padding: 8px 16px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.settings-btn:active {
  background: var(--accent-light);
}

.settings-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text-primary);
  margin-top: 6px;
  outline: none;
}

.settings-input:focus {
  border-color: var(--accent);
}

.settings-note {
  width: 100%;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Toggle */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 26px;
  transition: 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,46,53,0.4);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-message {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.modal-cancel {
  background: var(--bg-input);
  color: var(--text-secondary);
}

.modal-confirm {
  background: var(--accent);
  color: #fff;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* --- Safe area for notch phones --- */
@supports (padding-top: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
  .main-content {
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }
}
