/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* Navigation */
.main-nav {
  background: var(--primary);
  color: white;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-user {
  font-weight: 400;
  font-size: 0.85rem;
  opacity: 0.8;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-links a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: background 0.2s;
}

.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

.nav-logout button {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.8);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}

.nav-logout button:hover {
  background: rgba(255,255,255,0.1);
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.alert-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

/* Auth Pages */
.auth-page {
  max-width: 400px;
  margin: 60px auto;
  text-align: center;
}

.auth-page h1 {
  margin-bottom: 24px;
  font-size: 1.8rem;
}

.auth-form {
  background: var(--card-bg);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  text-align: left;
}

.auth-link {
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-light);
}

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

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s;
}

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

.form-group small {
  color: var(--text-light);
  font-size: 0.8rem;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-group {
  flex: 1;
}

.form-card {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.2s;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: var(--radius);
}

.btn-delete:hover {
  background: #fef2f2;
}

.inline-form {
  display: inline;
}

/* Page header */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Medications */
.medications-form {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.med-category-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.med-category-row:last-of-type {
  border-bottom: none;
  margin-bottom: 20px;
}

.med-category-label {
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 200px;
  flex-shrink: 0;
}

.med-category-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.med-select {
  flex: 1;
  max-width: 320px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: white;
}

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

.dosage-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dosage-input-num {
  width: 80px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  text-align: right;
}

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

.dosage-unit {
  color: var(--text-light);
  font-size: 0.9rem;
  font-weight: 500;
}

/* Readings Table */
.readings-history {
  margin-top: 32px;
}

.readings-history h2 {
  margin-bottom: 12px;
  font-size: 1.2rem;
}

.readings-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.readings-table th, .readings-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.readings-table th {
  background: #f1f5f9;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-light);
}

.bp-badge {
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.bp-normal-badge { background: #dcfce7; color: #166534; }
.bp-elevated-badge { background: #fef9c3; color: #854d0e; }
.bp-high-badge { background: #fee2e2; color: #991b1b; }
.bp-crisis { background: #991b1b; color: white; }
.bp-low-badge { background: #dbeafe; color: #1e40af; }

/* Calendar */
.calendar-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.calendar {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  overflow: hidden;
}

.calendar-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f1f5f9;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-light);
}

.calendar-header div {
  padding: 10px;
  text-align: center;
}

.calendar-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar-day {
  min-height: 80px;
  border: 1px solid var(--border);
  padding: 4px;
  font-size: 0.85rem;
}

.calendar-day.empty {
  background: #f8fafc;
}

.calendar-day.has-readings {
  background: #f0f9ff;
}

.day-number {
  font-weight: 600;
  color: var(--text-light);
  font-size: 0.8rem;
}

.mini-reading {
  font-size: 0.75rem;
  padding: 1px 4px;
  margin-top: 2px;
  border-radius: 3px;
}

.mini-reading.bp-normal { background: #dcfce7; }
.mini-reading.bp-elevated { background: #fef9c3; }
.mini-reading.bp-high { background: #fee2e2; }

.calendar-legend {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--text-light);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.bp-normal { background: #dcfce7; border: 1px solid #86efac; }
.legend-dot.bp-elevated { background: #fef9c3; border: 1px solid #fde047; }
.legend-dot.bp-high { background: #fee2e2; border: 1px solid #fca5a5; }

/* Trends */
.trends-controls {
  margin-bottom: 20px;
}

.trends-controls select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.chart-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 20px;
  position: relative;
  height: 400px;
}

.regimen-legend {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.85rem;
}

.regimen-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.regimen-color {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

/* BP Entry form */
.bp-form .form-row {
  margin-bottom: 0;
}

/* Utility */
.text-light { color: var(--text-light); font-size: 0.9rem; }

/* Patient context bar (physician view) */
.patient-context {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.patient-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.patient-tabs {
  display: flex;
  gap: 4px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.patient-tabs a {
  padding: 6px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-light);
  font-size: 0.85rem;
  transition: background 0.2s;
}

.patient-tabs a:hover { background: #f1f5f9; color: var(--text); }
.patient-tabs a.active { background: var(--primary); color: white; }

/* Start review bar */
.start-review-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

/* Review panel */
.review-panel {
  background: #fffbeb;
  border: 2px solid #f59e0b;
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #fef3c7;
}

.review-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.review-badge {
  background: #f59e0b;
  color: white;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.autosave-status {
  font-size: 0.8rem;
  color: #16a34a;
}

.review-actions {
  display: flex;
  gap: 8px;
}

.review-body {
  padding: 16px;
  transition: max-height 0.3s, padding 0.3s;
}

.review-body.collapsed {
  max-height: 0;
  padding: 0 16px;
  overflow: hidden;
}

.soap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.soap-field label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.soap-field textarea {
  width: 100%;
  min-height: 100px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.soap-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Invitation rows */
.invitation-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.invitation-row:last-child { border-bottom: none; }

.invitation-actions {
  display: flex;
  gap: 8px;
}

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

.btn-danger:hover {
  background: #b91c1c;
}

/* Clinical notes */
.note-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.soap-display { }

.soap-section {
  margin-bottom: 12px;
}

.soap-section h4 {
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.soap-section p {
  font-size: 0.9rem;
  white-space: pre-wrap;
}

/* Responsive */
@media (max-width: 768px) {
  .nav-links {
    gap: 0;
  }

  .nav-links a {
    padding: 8px 6px;
    font-size: 0.8rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .med-category-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .med-category-label {
    min-width: unset;
  }

  .med-category-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .med-select {
    max-width: none;
  }

  .calendar-day {
    min-height: 60px;
  }

  .chart-container {
    height: 300px;
  }
}
