/* ============================================================
   MEDEX — Medical Exam Tracker  |  styles.css
   ============================================================ */

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

:root {
  --primary:        #1565c0;
  --primary-light:  #e3f2fd;
  --primary-dark:   #0d47a1;
  --green:          #2e7d32;
  --red:            #c62828;
  --orange:         #ef6c00;
  --grey-line:      #9e9e9e;
  --bg:             #f0f4f8;
  --surface:        #ffffff;
  --border:         #e0e0e0;
  --text:           #212121;
  --text-muted:     #757575;
  --radius:         8px;
  --shadow:         0 2px 8px rgba(0,0,0,0.10);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.14);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
  background: var(--primary);
  color: white;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  flex: 1;
  user-select: none;
}

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

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

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

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }

.btn-ghost {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1.5px solid rgba(255,255,255,0.5);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.22); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; padding: 11px; }

/* ============================================================
   TABS
   ============================================================ */
.tab-nav {
  background: white;
  display: flex;
  border-bottom: 2px solid var(--border);
  padding: 0 20px;
  position: sticky;
  top: 56px;
  z-index: 90;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.tab-btn {
  padding: 13px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tab-btn:hover  { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-pane         { display: none; padding: 24px 20px; }
.tab-pane.active  { display: block; }

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: white;
  cursor: pointer;
  min-width: 190px;
  font-family: inherit;
  color: var(--text);
}
.filter-select:focus { outline: none; border-color: var(--primary); }

.charts-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ============================================================
   CHARTS GRID
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(460px, 1fr));
  gap: 24px;
}

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

/* ============================================================
   CHART CARD
   ============================================================ */
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-wrapper {
  padding: 16px 16px 10px;
  height: 290px;
  position: relative;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.no-data-msg {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-style: italic;
}

.explanation-box {
  background: var(--primary-light);
  border-top: 1px solid #bbdefb;
  padding: 12px 16px;
  font-size: 0.83rem;
  color: #1a237e;
  line-height: 1.55;
}

.explanation-box strong {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--primary);
  margin-bottom: 5px;
  font-weight: 700;
}

.explanation-box strong:not(:first-child) {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid #bbdefb;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  grid-column: 1 / -1;
}
.empty-icon { font-size: 3rem; margin-bottom: 14px; }
.empty-state p { margin-bottom: 6px; line-height: 1.6; }

/* ============================================================
   SECTION HEADER
   ============================================================ */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.section-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

/* ============================================================
   CATALOG TABLE
   ============================================================ */
.catalog-table-wrapper {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  border: 1px solid var(--border);
}

.catalog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.catalog-table th {
  background: #f8f9fa;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.catalog-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.catalog-table tr:last-child td { border-bottom: none; }
.catalog-table tr:hover td { background: #fafafa; }

.measure-id-chip {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: monospace;
  background: #f0f0f0;
  padding: 1px 6px;
  border-radius: 4px;
  margin-top: 3px;
  display: inline-block;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.73rem;
  font-weight: 500;
  white-space: nowrap;
  margin: 1px 2px;
}

.badge-blue  { background: var(--primary-light); color: var(--primary); }
.badge-green { background: #e8f5e9; color: var(--green); }
.badge-grey  { background: #f0f0f0; color: var(--text-muted); }

.ref-text { color: var(--orange); font-weight: 500; font-size: 0.85rem; }

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

.btn-icon {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: 4px;
  border: 1px solid;
  cursor: pointer;
  background: transparent;
  transition: background 0.12s;
  font-family: inherit;
  font-weight: 500;
}

.btn-icon.edit   { color: var(--primary); border-color: var(--primary); }
.btn-icon.edit:hover { background: var(--primary-light); }
.btn-icon.delete { color: var(--red); border-color: var(--red); }
.btn-icon.delete:hover { background: #ffebee; }

/* ============================================================
   ADD OBSERVATION FORM
   ============================================================ */
.add-form-container {
  max-width: 600px;
  margin: 0 auto;
  background: white;
  padding: 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.add-form-container h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 22px;
  color: var(--primary);
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 10px;
}

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

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21,101,192,0.08);
}

.form-group textarea { resize: vertical; }

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

.hint {
  display: block;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ============================================================
   MEASURE PREVIEW
   ============================================================ */
.measure-preview {
  background: #f0faf8;
  border: 1.5px solid #b2dfdb;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}

.preview-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.preview-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.preview-value {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

.preview-explanation {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #b2dfdb;
  color: #00695c;
  font-size: 0.83rem;
  line-height: 1.55;
}

/* ============================================================
   RECENT OBSERVATIONS
   ============================================================ */
#recent-obs-container {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 2px solid var(--border);
}

#recent-obs-container h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.obs-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  background: #fafafa;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  transition: background 0.12s;
}

.obs-item:hover { background: #f0f4f8; }

.obs-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.obs-dot.in-range  { background: var(--green); }
.obs-dot.out-range { background: var(--red); }

.obs-date  { font-size: 0.84rem; color: var(--text-muted); }
.obs-value { font-weight: 700; font-size: 0.9rem; margin-left: auto; }

.obs-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: #bdbdbd;
  font-size: 0.9rem;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.12s;
}
.obs-delete:hover { color: var(--red); }

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  cursor: pointer;
}

.modal-box {
  position: relative;
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

.modal-header h3 { font-size: 1.05rem; font-weight: 600; }

.modal-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  padding: 5px;
  border-radius: 4px;
  line-height: 1;
}
.modal-close-btn:hover { background: #f5f5f5; color: var(--text); }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: white;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 400;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  pointer-events: none;
  white-space: nowrap;
}

.toast.hidden  { display: none; }
.toast.success { background: #2e7d32; color: white; }
.toast.error   { background: var(--red); color: white; }
.toast.info    { background: var(--primary); color: white; }

/* ============================================================
   ALL-OBSERVATIONS TABLE
   ============================================================ */
.all-obs-container {
  margin: 0 20px 28px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.all-obs-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
}

.all-obs-header span:first-child {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.all-obs-filters {
  display: flex;
  gap: 10px;
  padding: 10px 18px;
  flex-wrap: wrap;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
}

.all-obs-table-wrap {
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
}

.all-obs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.all-obs-table thead th {
  background: #f8f9fa;
  padding: 9px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.all-obs-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.all-obs-table tr:last-child td { border-bottom: none; }
.all-obs-table tr:hover td { background: #fafafa; }

.all-obs-table .measure-name {
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.all-obs-table .measure-name:hover { color: var(--primary); text-decoration: underline; }

.val-in  { color: var(--green); font-weight: 700; }
.val-out { color: var(--red);   font-weight: 700; }

.all-obs-table .ref-cell {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.all-obs-empty {
  text-align: center;
  padding: 28px;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.875rem;
}

.obs-inline-input {
  padding: 4px 7px;
  border: 1.5px solid var(--primary);
  border-radius: 5px;
  font-size: 0.875rem;
  font-family: inherit;
  background: #e3f2fd;
  color: var(--text);
}
.obs-inline-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(21,101,192,0.12);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 520px) {
  .form-row,
  .form-row-3      { grid-template-columns: 1fr; }
  .navbar-actions  { gap: 5px; }
  .btn-sm          { font-size: 0.74rem; padding: 5px 8px; }
  .tab-btn         { padding: 12px 14px; font-size: 0.82rem; }
  .add-form-container { padding: 18px; }
}
