/* MRAi base styles and UI kit components. Depends on tokens.css. */

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "tnum" 0;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img, svg { display: block; }
svg.icon { flex: none; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.mono { font-family: var(--font-mono); font-size: 0.93em; letter-spacing: 0; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.tnum { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.row { display: flex; align-items: center; gap: var(--sp-2); }
.grow { flex: 1 1 auto; min-width: 0; }

/* ------------------------------------------------------------------ button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control-h); padding: 0 var(--sp-4);
  border: 1px solid transparent; border-radius: var(--radius-md);
  font-size: var(--fs-md); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:disabled { opacity: 0.55; }
.btn[aria-busy="true"] { cursor: progress; }
.btn-sm { height: var(--control-h-sm); padding: 0 var(--sp-3); font-size: var(--fs-sm); gap: 6px; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }

.btn-primary { background: var(--accent); color: var(--text-on-accent); box-shadow: var(--shadow-1); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }

.btn-secondary { background: var(--surface-1); border-color: var(--border-strong); color: var(--text-primary); box-shadow: var(--shadow-1); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-secondary:active:not(:disabled) { background: var(--surface-3); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }
.btn-ghost:active:not(:disabled) { background: var(--surface-3); }

.btn-danger { background: var(--danger); color: #fff; box-shadow: var(--shadow-1); }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

/* ------------------------------------------------------------------ badge */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text);
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-urgent { background: var(--urgent-soft); color: var(--urgent-text); }
.badge-urgent .badge-dot { background: var(--urgent); }
.badge-attention { background: var(--attention-soft); color: var(--attention-text); }
.badge-attention .badge-dot { background: var(--attention); }
.badge-routine { background: var(--routine-soft); color: var(--routine-text); }
.badge-routine .badge-dot { background: var(--routine); }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }

/* ------------------------------------------------------------------ card */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-5);
}
.card-title { font-size: var(--fs-lg); margin-bottom: var(--sp-1); }
.card-desc { color: var(--text-secondary); margin-bottom: var(--sp-5); }

/* ------------------------------------------------------------------ table */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.table th {
  position: sticky; top: 0;
  background: var(--surface-1);
  text-align: left; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.row-link { cursor: pointer; transition: background-color var(--dur-fast) var(--ease); }
.table tr.row-link:hover { background: var(--surface-2); }
.table tr.row-link:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.table-empty { padding: var(--sp-2); }

/* ------------------------------------------------------------------ dialog */
.dialog {
  width: min(480px, calc(100vw - 2 * var(--sp-5)));
  max-height: calc(100vh - 2 * var(--sp-6));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: var(--shadow-3);
}
.dialog-sm { width: min(400px, calc(100vw - 2 * var(--sp-5))); }
.dialog-lg { width: min(640px, calc(100vw - 2 * var(--sp-5))); }
.dialog[open] { display: flex; flex-direction: column; animation: dialog-in var(--dur) var(--ease); }
.dialog::backdrop { background: var(--surface-overlay); animation: fade-in var(--dur) var(--ease); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-5) var(--sp-2);
}
.dialog-title { font-size: var(--fs-lg); }
.dialog-close { margin: -6px -8px -6px 0; }
.dialog-body { padding: var(--sp-2) var(--sp-5) var(--sp-5); color: var(--text-secondary); overflow-y: auto; }
.dialog-body > * + * { margin-top: var(--sp-3); }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-0);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ------------------------------------------------------------------ toast */
.toast-region {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 1000;
  display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(380px, calc(100vw - 2 * var(--sp-5)));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-2) var(--sp-3) var(--sp-4);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in var(--dur) var(--ease);
}
.toast-msg { flex: 1; padding-top: 5px; font-size: var(--fs-md); line-height: 1.4; }
.toast-icon { margin-top: 5px; color: var(--text-muted); }
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-danger { border-left-color: var(--danger); }
.toast-danger .toast-icon { color: var(--danger); }
.toast-attention { border-left-color: var(--attention); }
.toast-attention .toast-icon { color: var(--attention); }
.toast-leave { opacity: 0; transform: translateY(4px); transition: opacity 150ms, transform 150ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--sp-8) var(--sp-5);
}
.empty-compact { padding: var(--sp-5); }
.empty-icon {
  display: grid; place-items: center;
  width: 48px; height: 48px; margin-bottom: var(--sp-4);
  border-radius: var(--radius-lg);
  background: var(--accent-soft); color: var(--accent-text);
}
.empty-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.empty-body { max-width: 44ch; margin-top: var(--sp-1); color: var(--text-secondary); }
.empty-action { margin-top: var(--sp-5); }

/* ------------------------------------------------------------------ skeleton */
.skeleton { display: flex; flex-direction: column; gap: var(--sp-3); }
.skeleton-line, .skeleton-block {
  display: block; height: 12px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--skeleton-a) 0%, var(--skeleton-b) 50%, var(--skeleton-a) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
.skeleton-block { height: 100%; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ------------------------------------------------------------------ metric */
.metric {
  display: flex; flex-direction: column; gap: var(--sp-1);
  min-width: 0;
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  text-align: left;
}
.metric-button { cursor: pointer; transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease); }
.metric-button:hover { border-color: var(--border-strong); }
.metric.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.metric-label { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-secondary); font-weight: var(--fw-medium); }
.metric-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.metric-value { font-size: var(--fs-3xl); font-weight: var(--fw-semibold); line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.metric-hint { font-size: var(--fs-xs); color: var(--text-muted); }
.metric-urgent .metric-dot { background: var(--urgent); }
.metric-attention .metric-dot { background: var(--attention); }
.metric-routine .metric-dot { background: var(--routine); }
.metric-success .metric-dot { background: var(--success); }
.metric-danger .metric-dot { background: var(--danger); }
.metric-urgent .metric-value { color: var(--urgent-text); }

/* ------------------------------------------------------------------ field */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--sp-4); }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-primary); }
.field-optional { color: var(--text-muted); font-weight: var(--fw-regular); }
.field-hint { font-size: var(--fs-sm); color: var(--text-muted); }
.field-error { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--danger-text); }
.input, .select, .textarea {
  width: 100%; height: var(--control-h);
  padding: 0 var(--sp-3);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
textarea.input, .textarea { height: auto; min-height: 80px; padding: var(--sp-2) var(--sp-3); resize: vertical; }
.input::placeholder { color: var(--text-muted); }
.input:hover, .select:hover { border-color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-muted); }
.select {
  appearance: none; padding-right: var(--sp-7);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ------------------------------------------------------------------ tabs */
.tabs-list { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); }
.tab {
  position: relative;
  height: 40px; padding: 0 var(--sp-3);
  background: none; border: 0; border-radius: var(--radius-md) var(--radius-md) 0 0;
  color: var(--text-secondary); font-weight: var(--fw-medium);
}
.tab:hover { color: var(--text-primary); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--accent-text); }
.tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: var(--sp-2); right: var(--sp-2); bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--accent);
}
.tabs-panel:focus-visible { border-radius: var(--radius-md); }

/* ------------------------------------------------------------------ menu */
.menu { position: relative; display: inline-flex; }
.menu-pop {
  position: absolute; top: calc(100% + 6px); z-index: 200;
  min-width: 200px; padding: var(--sp-1);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  animation: menu-in var(--dur-fast) var(--ease);
}
.menu-end { right: 0; }
.menu-start { left: 0; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%;
  height: 34px; padding: 0 var(--sp-3);
  background: none; border: 0; border-radius: var(--radius-md);
  color: var(--text-primary); text-align: left; font-size: var(--fs-md);
}
.menu-item svg { color: var(--text-muted); }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--surface-2); box-shadow: none; }
.menu-item:disabled { color: var(--text-muted); }
.menu-item-danger, .menu-item-danger svg { color: var(--danger-text); }
.menu-sep { height: 1px; margin: var(--sp-1) 0; background: var(--border); }
.menu-header { padding: var(--sp-2) var(--sp-3) var(--sp-3); }

/* ------------------------------------------------------------------ page scaffolding */
.page { max-width: 1280px; margin: 0 auto; padding: var(--sp-6) var(--sp-6) var(--sp-8); }
.page-narrow { max-width: 720px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.page-title { font-size: var(--fs-2xl); }
.page-desc { margin-top: var(--sp-1); color: var(--text-secondary); }
.page-actions { display: flex; gap: var(--sp-2); }
.section + .section { margin-top: var(--sp-6); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* ------------------------------------------------------------------ wordmark */
.wordmark { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--text-primary); text-decoration: none; }
.wordmark:hover { text-decoration: none; }
.wordmark-text { font-size: 19px; font-weight: var(--fw-bold); letter-spacing: -0.02em; line-height: 1; }
.wordmark-ai { color: var(--accent); }
[data-theme="dark"] .wordmark-ai { color: var(--accent-text); }
.wordmark-sub {
  padding-left: var(--sp-3); margin-left: var(--sp-1);
  border-left: 1px solid var(--border-strong);
  font-size: var(--fs-sm); color: var(--text-muted); line-height: 18px; white-space: nowrap;
}
.logo-mark .logo-eye, .logo-mark .logo-iris, .logo-mark .logo-mid { stroke: var(--accent); }
.logo-mark .logo-iris { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.logo-mark .logo-lesion { fill: var(--lesion); }
[data-theme="dark"] .logo-mark .logo-eye, [data-theme="dark"] .logo-mark .logo-iris, [data-theme="dark"] .logo-mark .logo-mid { stroke: var(--accent-text); }
