/* =========================================================
   EchoTemplate – Clinical UI Stylesheet
   ========================================================= */

/* ---------------------------------------------------------
   Variables
   --------------------------------------------------------- */
:root {
  --primary:        #1a6fa4;
  --primary-dark:   #145a87;
  --primary-light:  #e8f4fd;
  --surface:        #ffffff;
  --bg:             #f0f4f8;
  --bg-alt:         #e8eef5;
  --border:         #cdd7e3;
  --border-focus:   #1a6fa4;
  --text:           #1a2535;
  --text-muted:     #5a6e82;
  --success:        #16a34a;
  --success-light:  #dcfce7;
  --warning:        #d97706;
  --warning-light:  #fef3c7;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --info-light:     #dbeafe;
  --header-h:       56px;
  --tab-nav-h:      46px;
  --radius:         6px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.10);
  --shadow:         0 2px 8px rgba(0,0,0,.14);
  --shadow-lg:      0 8px 24px rgba(0,0,0,.18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Courier New", Courier, monospace;
}

/* ---------------------------------------------------------
   Reset / Base
   --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 600; }

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

/* ---------------------------------------------------------
   Loading Screen
   --------------------------------------------------------- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------
   Buttons
   --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon { padding: 6px; line-height: 1; }

/* ---------------------------------------------------------
   Form controls (shared)
   --------------------------------------------------------- */
.field-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.field-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(26,111,164,.15);
}
.field-input.auto-populated {
  border-color: #2563eb;
  background: var(--info-light);
}
.field-textarea { resize: vertical; min-height: 72px; }

/* ---------------------------------------------------------
   Auth / Login
   --------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a3a5c 0%, #1a6fa4 100%);
}

.auth-card {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 40px 44px;
  width: 380px;
  max-width: 95vw;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo h1 {
  font-size: 22px;
  color: var(--primary);
  letter-spacing: -.3px;
}
.auth-logo p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.auth-card .form-group {
  margin-bottom: 16px;
}
.auth-card label {
  display: block;
  font-weight: 500;
  margin-bottom: 5px;
  font-size: 13px;
}
.auth-card .field-input { padding: 9px 12px; }
.auth-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 10px;
  margin-top: 4px;
}
.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
  text-align: center;
}

/* ---------------------------------------------------------
   App Header
   --------------------------------------------------------- */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.header-brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.2px;
  white-space: nowrap;
}
.header-brand span {
  font-weight: 300;
  opacity: .75;
  font-size: 12px;
  display: block;
  letter-spacing: 0;
}

.header-sep { flex: 1; }

.header-exam-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.header-exam-info .patient-name { font-weight: 600; font-size: 15px; }
.header-exam-info .exam-meta { font-size: 11px; opacity: .8; }

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

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  opacity: .9;
}
.header-user .user-name { font-weight: 500; }

.btn-header {
  background: rgba(255,255,255,.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
}
.btn-header:hover { background: rgba(255,255,255,.28); }
.btn-header.btn-sign { background: rgba(22,163,74,.7); border-color: rgba(22,163,74,.9); }
.btn-header.btn-sign:hover { background: rgba(22,163,74,.85); }
.btn-header.btn-amend { background: rgba(217,119,6,.7); border-color: rgba(217,119,6,.9); }
.btn-header.btn-amend:hover { background: rgba(217,119,6,.85); }
.btn-header:disabled { opacity: .4; cursor: not-allowed; }

.save-status {
  font-size: 12px;
  opacity: .8;
}
.save-status.saved { color: #a7f3d0; }
.save-status.error { color: #fca5a5; }

/* ---------------------------------------------------------
   Status badges
   --------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-draft       { background: var(--bg-alt); color: var(--text-muted); }
.badge-in_progress { background: var(--info-light); color: #1d4ed8; }
.badge-completed   { background: var(--info-light); color: #1d4ed8; }
.badge-signed      { background: var(--success-light); color: #166534; }
.badge-amended     { background: var(--warning-light); color: #92400e; }
.badge-admin       { background: #fae8ff; color: #7e22ce; }
.badge-cardiologist { background: var(--primary-light); color: var(--primary-dark); }
.badge-active      { background: var(--success-light); color: #166534; }
.badge-inactive    { background: var(--danger-light); color: #991b1b; }

/* ---------------------------------------------------------
   Dashboard layout
   --------------------------------------------------------- */
.dashboard-layout {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.patient-panel {
  width: 300px;
  min-width: 220px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  flex-shrink: 0;
}

.exam-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.panel-header h2 { font-size: 14px; flex: 1; }

.search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 10px 14px;
  width: calc(100% - 28px);
  font-size: 13px;
}
.search-input:focus { outline: none; border-color: var(--border-focus); }

.patient-list {
  flex: 1;
  overflow-y: auto;
}

.patient-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg-alt);
  transition: background .1s;
}
.patient-item:hover { background: var(--bg); }
.patient-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }
.patient-item .p-name { font-weight: 600; font-size: 13px; }
.patient-item .p-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state p { margin: 8px 0 0; font-size: 13px; }

.exam-list-wrap { flex: 1; overflow-y: auto; padding: 16px; }

/* Dashboard filter bar */
.exam-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.exam-filter-bar label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.filter-date-input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
}
.filter-date-input:focus { outline: none; border-color: var(--border-focus); }
.filter-toggle {
  display: flex;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.filter-toggle-btn {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--surface);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: background .1s, color .1s;
}
.filter-toggle-btn:hover { background: var(--bg); }
.filter-toggle-btn.active { background: var(--primary); color: #fff; }
.filter-spacer { flex: 1; }

.exam-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  display: flex;
  align-items: center;
  gap: 14px;
}
.exam-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--primary);
}
.exam-card-info { flex: 1; }
.exam-card-date { font-weight: 600; font-size: 14px; }
.exam-card-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* Header search input (dashboard) */
.header-search {
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 13px;
  width: 260px;
}
.header-search::placeholder { color: rgba(255,255,255,.5); }
.header-search:focus { outline: none; border-color: rgba(255,255,255,.5); background: rgba(255,255,255,.15); }

/* Exam list table */
.exam-table { cursor: default; }
.exam-table .exam-row { cursor: pointer; }
.exam-table .exam-row:hover td { background: var(--bg); }
.exam-table td.diagnosis-cell {
  color: var(--text-muted);
  font-size: 12px;
  max-width: 340px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------
   Exam split view
   --------------------------------------------------------- */
.exam-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.exam-split {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.form-panel {
  width: 50%;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* Tab navigation */
.tab-nav {
  display: flex;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.tab-nav::-webkit-scrollbar { height: 4px; }
.tab-nav::-webkit-scrollbar-thumb { background: var(--border); }

.tab-btn {
  padding: 0 18px;
  height: var(--tab-nav-h);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  flex-shrink: 0;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--surface);
}
.lock-badge {
  font-size: 0.75em;
  margin-left: 4px;
  opacity: 0.8;
  pointer-events: none;
}

/* Form fields area */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 40px;
}

.form-section {
  margin-bottom: 28px;
}
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--primary);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
  margin-bottom: 14px;
}

.section-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
}

.field-wrapper {
  margin-bottom: 12px;
}
.field-wrapper.hidden { display: none !important; }
.field-wrapper--full { grid-column: span 2; }

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 7px;
  color: var(--text);
}
.field-label .required { color: var(--danger); }

.meas-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--info-light);
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}

/* Radio / Checkbox groups */
.radio-group, .checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.radio-label, .checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .1s, border-color .1s;
  font-weight: 400;
}
.radio-label:hover, .checkbox-label:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}
.radio-label input, .checkbox-label input {
  margin: 2px 0 0;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.radio-label:has(input:checked),
.checkbox-label:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
}
.radio-text, .checkbox-text { line-height: 1.4; }
.radio-clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
  align-self: flex-start;
  opacity: 0.7;
}
.radio-clear-btn:hover { opacity: 1; text-decoration: underline; }

/* Preview panel */
.preview-header {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  gap: 10px;
  flex-shrink: 0;
}
.ws-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background .3s;
}
.ws-dot.connected { background: var(--success); }
.ws-dot.error { background: var(--danger); }

.preview-iframe {
  flex: 1;
  border: none;
  background: #fff;
  width: 100%;
}

.preview-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

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

.admin-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.admin-tab-btn {
  padding: 8px 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color .15s;
}
.admin-tab-btn:hover { color: var(--text); }
.admin-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Data tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--bg-alt);
  font-size: 13px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

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

/* Section card */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.section-card-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
}
.section-card-header h3 { flex: 1; font-size: 16px; }

/* ---------------------------------------------------------
   Modal
   --------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }

.modal {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  width: 860px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } }

.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}
.modal-header h3 { flex: 1; font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Modal form groups */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
}
.form-group .field-input { width: 100%; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ---------------------------------------------------------
   Toast notifications
   --------------------------------------------------------- */
#toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  min-width: 240px;
  max-width: 360px;
  animation: slideInRight .2s ease-out;
}
@keyframes slideInRight { from { transform: translateX(20px); opacity: 0; } }

.toast-info    { background: var(--primary); color: #fff; }
.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
.toast-msg { flex: 1; }

/* ---------------------------------------------------------
   Misc utilities
   --------------------------------------------------------- */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* Inline error */
.inline-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

/* Nav back link */
.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,.8);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background .1s;
  background: none;
  border: none;
}
.nav-back:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Password strength hint */
.pwd-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
