/* ClinRef — Clinical Referral Portal — Core Styles */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --teal-900: #0a2e35;
  --teal-700: #0d4a56;
  --teal-500: #0e7490;
  --teal-400: #0ea5c9;
  --teal-100: #e0f4f8;
  --teal-50:  #f0fafc;

  --slate-900: #0f172a;
  --slate-700: #334155;
  --slate-500: #64748b;
  --slate-300: #cbd5e1;
  --slate-100: #f1f5f9;
  --slate-50:  #f8fafc;

  --white: #ffffff;

  --status-new:      #0e7490;
  --status-new-bg:   #e0f4f8;
  --status-opened:   #d97706;
  --status-opened-bg:#fef3c7;
  --status-actioned: #059669;
  --status-actioned-bg:#d1fae5;
  --status-complete: #7c3aed;
  --status-complete-bg:#ede9fe;
  --status-action:   #dc2626;
  --status-action-bg:#fee2e2;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

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

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--slate-50);
  color: var(--slate-900);
  min-height: 100vh;
}

/* ── AUTH SCREENS ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--teal-900) 0%, var(--teal-700) 100%);
  padding: 24px;
}

.auth-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo .brand {
  font-size: 22px;
  font-weight: 700;
  color: var(--teal-700);
  letter-spacing: -0.3px;
}

.auth-logo .sub {
  font-size: 13px;
  color: var(--slate-500);
  margin-top: 4px;
}

.auth-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--slate-900);
  margin-bottom: 6px;
}

.auth-sub {
  font-size: 14px;
  color: var(--slate-500);
  margin-bottom: 28px;
}

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

.sidebar {
  width: 240px;
  background: var(--teal-900);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo .brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -0.2px;
}

.sidebar-logo .sub {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(255,255,255,0.35);
  padding: 8px 8px 6px;
  margin-top: 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.nav-item.active { background: var(--teal-500); color: var(--white); }

.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-item.active .icon { opacity: 1; }

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user .user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
}

.sidebar-user .user-role {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  margin-top: 2px;
}

.sidebar-user .logout-btn {
  margin-top: 10px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}

.sidebar-user .logout-btn:hover { color: rgba(255,255,255,0.9); }

.main-content {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--slate-300);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--slate-900);
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.page-body { padding: 28px; }

/* ── CARDS ── */
.card {
  background: var(--white);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--slate-900);
}

.card-body { padding: 22px; }

/* ── STATS ROW ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--slate-900);
  line-height: 1;
}

.stat-value.teal { color: var(--teal-500); }
.stat-value.amber { color: var(--status-opened); }
.stat-value.green { color: var(--status-actioned); }
.stat-value.red { color: var(--status-action); }

/* ── STATUS PILLS ── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-pill::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.pill-new      { background: var(--status-new-bg);      color: var(--status-new); }
.pill-opened   { background: var(--status-opened-bg);   color: var(--status-opened); }
.pill-actioned { background: var(--status-actioned-bg); color: var(--status-actioned); }
.pill-complete { background: var(--status-complete-bg); color: var(--status-complete); }
.pill-action   { background: var(--status-action-bg);   color: var(--status-action); }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--slate-500);
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-300);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--slate-100);
  transition: background 0.1s;
  cursor: pointer;
}

tbody tr:hover { background: var(--teal-50); }
tbody tr.unread td { font-weight: 600; }
tbody tr.unread td:first-child::before {
  content: '';
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--teal-400);
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

tbody td {
  padding: 12px 14px;
  color: var(--slate-700);
  vertical-align: middle;
}

/* ── FORMS ── */
.form-section {
  margin-bottom: 32px;
}

.form-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--teal-700);
  padding-bottom: 10px;
  border-bottom: 2px solid var(--teal-100);
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field.full { grid-column: 1 / -1; }

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-700);
  letter-spacing: 0.2px;
}

label .required { color: var(--status-action); margin-left: 2px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--slate-300);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--slate-900);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.12);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

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

.char-count {
  font-size: 11px;
  color: var(--slate-500);
  text-align: right;
  margin-top: 2px;
}

.char-count.warn { color: var(--status-opened); }
.char-count.over { color: var(--status-action); }

/* ── CLINICAL TABLE ── */
.clinical-table-wrap { overflow-x: auto; margin-top: 8px; }

.clinical-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.clinical-table th {
  background: var(--teal-900);
  color: rgba(255,255,255,0.85);
  padding: 9px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.clinical-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--slate-100);
  vertical-align: middle;
}

.clinical-table tr:nth-child(even) td { background: var(--slate-50); }

.clinical-table .eye-label {
  font-weight: 700;
  color: var(--teal-700);
  font-size: 13px;
  white-space: nowrap;
  padding-left: 10px;
}

.clinical-table select,
.clinical-table input {
  padding: 6px 8px;
  font-size: 13px;
  min-width: 80px;
}

/* ── FILE UPLOAD ── */
.upload-zone {
  border: 2px dashed var(--slate-300);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
  position: relative;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--teal-500);
  background: var(--teal-50);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon { font-size: 28px; margin-bottom: 8px; }

.upload-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--slate-700);
}

.upload-sub {
  font-size: 12px;
  color: var(--slate-500);
  margin-top: 4px;
}

.file-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--slate-50);
  border: 1px solid var(--slate-300);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.file-item-name { color: var(--slate-700); font-weight: 500; }
.file-item-size { color: var(--slate-500); font-size: 12px; }

.file-remove {
  background: none;
  border: none;
  color: var(--status-action);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background: var(--teal-500); color: var(--white); }
.btn-primary:hover { background: var(--teal-700); }

.btn-secondary {
  background: var(--white);
  color: var(--slate-700);
  border: 1.5px solid var(--slate-300);
}
.btn-secondary:hover { border-color: var(--teal-500); color: var(--teal-500); }

.btn-danger { background: var(--status-action); color: var(--white); }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

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

/* ── CHANGE LOG ── */
.changelog {
  border: 1px solid var(--slate-300);
  border-radius: var(--radius);
  overflow: hidden;
}

.changelog-header {
  padding: 12px 16px;
  background: var(--slate-50);
  border-bottom: 1px solid var(--slate-300);
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-700);
}

.changelog-entry {
  padding: 12px 16px;
  border-bottom: 1px solid var(--slate-100);
  font-size: 13px;
}

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

.changelog-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.changelog-time { color: var(--slate-500); font-size: 12px; }
.changelog-user { font-weight: 600; color: var(--slate-700); }

.changelog-change { color: var(--slate-600); }

.changelog-diff {
  display: inline-flex;
  gap: 6px;
  margin-top: 4px;
  font-size: 12px;
}

.diff-old {
  background: #fee2e2;
  color: #991b1b;
  padding: 1px 6px;
  border-radius: 3px;
  text-decoration: line-through;
}

.diff-new {
  background: #d1fae5;
  color: #065f46;
  padding: 1px 6px;
  border-radius: 3px;
}

/* ── ALERTS ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-info    { background: var(--teal-50); color: var(--teal-700); border: 1px solid var(--teal-100); }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

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

.modal {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
  transform: translateY(12px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--slate-500);
  padding: 0;
  line-height: 1;
}

.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--slate-100); display: flex; gap: 10px; justify-content: flex-end; }

/* ── TABS ── */
.tabs { display: flex; border-bottom: 2px solid var(--slate-300); margin-bottom: 24px; gap: 0; }

.tab {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--slate-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: 'Inter', sans-serif;
}

.tab:hover { color: var(--teal-500); }
.tab.active { color: var(--teal-700); border-bottom-color: var(--teal-500); font-weight: 600; }

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

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--slate-500);
}

.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state .empty-title { font-size: 16px; font-weight: 600; color: var(--slate-700); margin-bottom: 6px; }
.empty-state .empty-sub { font-size: 14px; }

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.25s ease;
  max-width: 340px;
}

.toast-success { background: #065f46; color: white; }
.toast-error   { background: #991b1b; color: white; }
.toast-info    { background: var(--teal-700); color: white; }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
  }

  .sidebar.open { transform: translateX(0); }

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

  .topbar { padding: 0 16px; }

  .page-body { padding: 16px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .form-grid-2,
  .form-grid-3 { grid-template-columns: 1fr; }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--slate-700);
    font-size: 22px;
  }

  .modal { max-width: 100%; }
}

@media (min-width: 769px) {
  .menu-toggle { display: none; }
}

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

.sidebar-overlay.open { display: block; }

/* ── UTILITY ── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--slate-500); }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }
.hidden { display: none !important; }

.divider {
  border: none;
  border-top: 1px solid var(--slate-300);
  margin: 24px 0;
}

/* ── CLINREF BRAND MARK ── */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;700&display=swap');

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 32px;
}

.clinref-mark {
  width: 72px;
  height: 72px;
}

.clinref-svg {
  width: 72px;
  height: 72px;
  overflow: visible;
}

.clinref-wordmark {
  font-family: 'Montserrat', sans-serif;
  font-size: 26px;
  letter-spacing: 0.5px;
  line-height: 1;
}

.clinref-clin {
  font-weight: 300;
  color: #0f172a;
}

.clinref-ref {
  font-weight: 700;
  color: #0e7490;
}

.clinref-byline {
  font-family: 'Montserrat', sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2px;
  color: #8BBF4D;
}

/* Draw animations */
.draw-c {
  stroke-dasharray: 160;
  stroke-dashoffset: 160;
  animation: drawStrokePath 0.7s cubic-bezier(0.4,0,0.2,1) 0.3s forwards;
}

.draw-rv {
  stroke-dasharray: 50;
  stroke-dashoffset: 50;
  animation: drawStrokePath 0.35s cubic-bezier(0.4,0,0.2,1) 0.85s forwards;
}

.draw-rb {
  stroke-dasharray: 65;
  stroke-dashoffset: 65;
  animation: drawStrokePath 0.35s cubic-bezier(0.4,0,0.2,1) 1.05s forwards;
}

.draw-rl {
  stroke-dasharray: 38;
  stroke-dashoffset: 38;
  animation: drawStrokePath 0.3s cubic-bezier(0.4,0,0.2,1) 1.25s forwards;
}

@keyframes drawStrokePath {
  to { stroke-dashoffset: 0; }
}

.fade-up {
  opacity: 0;
  transform: translateY(6px);
  animation: brandFadeUp 0.5s ease 1.6s forwards;
}

.fade-up-2 {
  opacity: 0;
  transform: translateY(6px);
  animation: brandFadeUp 0.5s ease 1.8s forwards;
}

@keyframes brandFadeUp {
  to { opacity: 1; transform: translateY(0); }
}

/* Sidebar mark */
.sidebar-mark {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-mark .brand {
  font-family: 'Montserrat', sans-serif;
  font-size: 16px;
  letter-spacing: 0.3px;
  color: white;
}

.sidebar-mark .sub {
  font-family: 'Montserrat', sans-serif;
  font-size: 9px;
  letter-spacing: 1.5px;
}
