/* ===== CSS Variables ===== */
:root {
  --bg: #0f0f0e;
  --surface: #1a1a18;
  --card: #222220;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #a0c8e6;
  --accent-dim: rgba(160, 200, 230, 0.15);
  --text: #e8e8e4;
  --text-secondary: #888;
  --danger: #e6a0a0;
  --success: #c8e6a0;
}

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

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ===== Login Page ===== */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-title {
  font-family: 'DM Serif Display', serif;
  font-size: 28px;
  color: var(--accent);
  margin-bottom: 32px;
}

.login-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== Inputs ===== */
.input-field {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.input-field::placeholder {
  color: var(--text-secondary);
}

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

/* ===== Buttons ===== */
.btn-primary {
  padding: 12px 24px;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover {
  opacity: 0.85;
}

.btn-secondary {
  padding: 12px 24px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s;
}

.btn-secondary:hover {
  border-color: var(--text-secondary);
}

.btn-danger {
  padding: 12px 24px;
  background: var(--danger);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-danger:hover {
  opacity: 0.85;
}

/* ===== Error Messages ===== */
.error-msg {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  display: none;
}

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

/* ===== Admin Layout ===== */
.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 24px 20px;
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  list-style: none;
}

.nav-item {
  padding: 10px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-item:hover {
  background: var(--accent-dim);
  color: var(--text);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-right: 3px solid var(--accent);
}

.nav-item.disabled {
  opacity: 0.35;
  pointer-events: none;
  cursor: default;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.sidebar-footer .logout-btn {
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  transition: color 0.2s;
}

.sidebar-footer .logout-btn:hover {
  color: var(--danger);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.main-inner {
  max-width: 1200px;
  margin: 0 auto;
}

/* ===== Page Headers ===== */
.page-title {
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
  color: var(--text);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

/* ===== Stat Cards ===== */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-family: 'DM Serif Display', serif;
  font-size: 28px;
  color: var(--text);
}

.stat-card.alert {
  border-color: var(--danger);
}

.stat-card.alert .stat-value {
  color: var(--danger);
}

/* ===== Tables ===== */
.table-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

tr:last-child td {
  border-bottom: none;
}

tr.clickable {
  cursor: pointer;
  transition: background 0.15s;
}

tr.clickable:hover {
  background: var(--accent-dim);
}

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

.table-action {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.table-action:hover {
  color: var(--text);
  background: var(--accent-dim);
}

/* ===== Search ===== */
.search-bar {
  width: 100%;
  max-width: 320px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar::placeholder {
  color: var(--text-secondary);
}

.search-bar:focus {
  border-color: var(--accent);
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success {
  background: rgba(200, 230, 160, 0.15);
  color: var(--success);
}

.badge-muted {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.visible,
.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
}

.modal-title {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  margin-bottom: 20px;
  color: var(--text);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 10px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===== Detail Page ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  background: none;
  border: none;
  margin-bottom: 16px;
  cursor: pointer;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.detail-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-value {
  font-size: 15px;
  color: var(--text);
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state .empty-text {
  font-size: 15px;
}

/* ===== Section Visibility ===== */
.section {
  display: none;
}

.section.active {
  display: block;
}

/* Consultation & Medical Record */
.consultation-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.consultation-card:hover { border-color: var(--accent); }

.review-section {
  background: var(--surface);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.review-section h4 {
  font-family: 'DM Serif Display', serif;
  margin: 0 0 12px;
  font-size: 16px;
}

.review-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.review-item:last-child { border-bottom: none; }
.review-item input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; }
.review-item .current-value { color: var(--text-secondary); font-size: 12px; }
.review-item .new-value { color: var(--text); }

.review-conflict {
  border-left: 3px solid #c4a000;
  padding-left: 12px;
  background: rgba(196, 160, 0, 0.08);
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: 13px;
}
.review-conflict .conflict-previous { color: var(--text-secondary); text-decoration: line-through; }
.review-conflict .conflict-current { color: var(--text); font-weight: 500; }
.review-conflict .conflict-suggestion { color: var(--accent); font-size: 12px; font-style: italic; }

.record-section {
  margin-bottom: 24px;
}
.record-section h4 {
  font-family: 'DM Serif Display', serif;
  font-size: 15px;
  margin: 0 0 8px;
  color: var(--accent);
}
.record-field {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 14px;
}
.record-field .field-label {
  color: var(--text-secondary);
  min-width: 120px;
  flex-shrink: 0;
}
.record-field .field-value { color: var(--text); }

.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 48px;
  color: var(--text-secondary);
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
