/* ================================================================
   Noetarist Health — Brand Stylesheet
   Slate and burgundy on light background.
   Dark mode via [data-theme="dark"].
   ================================================================ */

/* ── Fonts ────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=DM+Sans:wght@300;400;500&display=swap');

/* ── Light mode (default) ─────────────────────────────────────── */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f5f5f5;
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --text: #34495E;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #6B1D2A;
  --accent-light: #8B3040;
  --accent-bg: #fdf2f4;

  --green: #22c55e;
  --green-bg: #f0fdf4;
  --amber: #f59e0b;
  --amber-bg: #fffbeb;
  --red: #ef4444;
  --red-bg: #fef2f2;
  --blue: #3b82f6;
  --blue-bg: #eff6ff;

  --font-heading: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;

  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);

  --sidebar-width: 260px;
}

/* ── Dark mode ────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22252f;
  --border: #2a2e3a;
  --border-light: #1e2230;
  --text: #e4e4e7;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --accent: #a04050;
  --accent-light: #c06070;
  --accent-bg: #1f1520;

  --green-bg: #0a1f0e;
  --amber-bg: #1a1508;
  --red-bg: #1f0a0a;
  --blue-bg: #0a1424;

  --shadow: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.3;
}

h1 { font-size: 1.8rem; margin-bottom: 0.5rem; }
h2 { font-size: 1.35rem; margin-bottom: 0.4rem; }
h3 { font-size: 1.1rem; margin-bottom: 0.3rem; }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { color: var(--accent-light); }

/* ── Layout shell ─────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-brand img {
  width: 32px;
  height: 32px;
}

.sidebar-brand-text {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--text);
}

.sidebar-brand-text span {
  color: var(--accent);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.sidebar-nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-bg);
  font-weight: 500;
}

.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-nav a.active svg { opacity: 1; }

.sidebar-section-label {
  padding: 1rem 1.25rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 500;
}

.sidebar-footer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-footer-actions a {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s;
}
.theme-toggle:hover { border-color: var(--text-muted); }

/* ── Mobile sidebar ───────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

.hamburger {
  display: none;
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 101;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  cursor: pointer;
  color: var(--text);
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .hamburger { display: block; }

  .main-content { margin-left: 0 !important; }
}

/* ── Main content ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem 2.5rem;
  max-width: 960px;
}

@media (max-width: 1200px) {
  .main-content { padding: 1.5rem 1.5rem; }
}

@media (max-width: 768px) {
  .main-content { padding: 3.5rem 1rem 1.5rem; }
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.card-header h2 {
  font-size: 1.1rem;
  margin-bottom: 0;
}

.card-header .badge {
  font-size: 0.75rem;
}

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

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

td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

tr:hover td { background: var(--surface-hover); }

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
}

.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }
.badge-red    { background: var(--red-bg);   color: var(--red); }
.badge-blue   { background: var(--blue-bg);  color: var(--blue); }
.badge-muted  { background: var(--surface-hover); color: var(--text-muted); }

/* ── Progress bars ────────────────────────────────────────────── */
.progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  width: 100%;
}

.progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.progress-green  { background: var(--green); }
.progress-amber  { background: var(--amber); }
.progress-red    { background: var(--red); }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: var(--font-body);
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-light); color: #fff; }

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem;
}
.btn-ghost:hover { color: var(--text); }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font-body);
  transition: border-color 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Status indicators ────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.status-dot-green  { background: var(--green); }
.status-dot-amber  { background: var(--amber); }
.status-dot-red    { background: var(--red); }

/* ── Toast notifications ──────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  pointer-events: auto;
  animation: toast-in 0.3s ease;
  max-width: 360px;
}

.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--blue); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Empty states ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

/* ── Attention items (dashboard) ──────────────────────────────── */
.attention-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-light);
}
.attention-item:last-child { border-bottom: none; }

.attention-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 0.55rem;
  flex-shrink: 0;
}

.attention-text {
  font-size: 0.9rem;
  flex: 1;
}

.attention-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* ── Lab traffic light ────────────────────────────────────────── */
.lab-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
}

.lab-in-range     { background: var(--green-bg); color: var(--green); }
.lab-borderline   { background: var(--amber-bg); color: var(--amber); }
.lab-out-of-range { background: var(--red-bg);   color: var(--red); }

/* ── Sparkline (SVG) ──────────────────────────────────────────── */
.sparkline svg {
  display: block;
  width: 100%;
  height: 80px;
}

.sparkline-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.sparkline-area {
  fill: var(--accent-bg);
  opacity: 0.5;
}

.sparkline-dot {
  fill: var(--accent);
}

.sparkline-ref {
  stroke: var(--text-faint);
  stroke-width: 1;
  stroke-dasharray: 4 2;
}

/* ── Login page ───────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-md);
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-brand h1 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.login-brand h1 span { color: var(--accent); font-weight: 400; }

.login-brand p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.login-error {
  background: var(--red-bg);
  color: var(--red);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.login-btn {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

/* ── Page header ──────────────────────────────────────────────── */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  color: var(--text);
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.2rem;
}

/* ── Stat grid ────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

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

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-family: var(--font-heading);
  color: var(--text);
  line-height: 1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Detail list ──────────────────────────────────────────────── */
.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.9rem;
}

.detail-label {
  color: var(--text-muted);
  font-weight: 500;
}

/* ── HTMX loading ─────────────────────────────────────────────── */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request .btn {
  opacity: 0.6;
  pointer-events: none;
}

/* ── Utilities ────────────────────────────────────────────────── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-right { text-align: right; }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
