/* =============================================================================
   TENSOR Med — Component library
   =============================================================================
   Depends on tokens.css being loaded first (this file consumes its custom
   properties). Every component is a single class or data-variant combo —
   no deep selector chains, no utility-first fragmentation.

   Rules applied here:
     * All colours resolve via tokens (never hex literal)
     * 4 px spacing grid; two radii (4/8) only
     * Focus-visible always shows the brand focus ring
     * Every interactive element has an explicit hover + active + disabled state
     * Dense by default (medical UI is information-heavy; wasted space = slower scan)
   ============================================================================= */


/* =============================================================================
   LAYOUT PRIMITIVES
   ============================================================================= */

.page-shell {
    max-width: var(--page-max-width);
    margin: 0 auto;
    padding: 0 var(--s-6);
}
.content-shell {
    max-width: var(--content-max-width);
    margin: 0 auto;
}

.stack-1 > * + * { margin-top: var(--s-1); }
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.stack-6 > * + * { margin-top: var(--s-6); }

.row { display: flex; gap: var(--s-3); align-items: center; }
.row-gap-4 { gap: var(--s-4); }
.row-gap-6 { gap: var(--s-6); }
.row-wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }


/* =============================================================================
   TYPOGRAPHY
   ============================================================================= */

.h1 {
    font-size: var(--text-2xl);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin: 0;
}
.h2 {
    font-size: var(--text-xl);
    font-weight: var(--fw-semibold);
    line-height: var(--lh-tight);
    color: var(--text-primary);
    margin: 0;
}
.h3 {
    font-size: var(--text-lg);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
    margin: 0;
}
.section-label {
    font-size: var(--text-xs);
    font-weight: var(--fw-medium);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0;
}
.body { font-size: var(--text-body); color: var(--text-secondary); }
.caption { font-size: var(--text-sm); color: var(--text-muted); }
.metadata {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-feature-settings: var(--ffs-tabular);
}
.mono {
    font-family: var(--font-mono);
    font-feature-settings: var(--ffs-tabular);
}


/* =============================================================================
   NAVIGATION BAR
   ============================================================================= */

.nav {
    height: var(--nav-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--s-6);
    gap: var(--s-6);
    position: sticky;
    top: 0;
    z-index: 20;
}
.nav-brand { display: inline-flex; align-items: center; text-decoration: none; }
.nav-links { display: flex; gap: var(--s-5); flex: 1; }
.nav-link {
    font-size: var(--text-body);
    color: var(--text-secondary);
    text-decoration: none;
    padding: var(--s-2) var(--s-1);
    border-bottom: 2px solid transparent;
    transition: color var(--motion-fast), border-color var(--motion-fast);
}
.nav-link:hover { color: var(--text-primary); }
.nav-link.is-active {
    color: var(--brand-blue);
    border-bottom-color: var(--brand-blue);
    font-weight: var(--fw-medium);
}
.nav-tail { display: flex; gap: var(--s-3); align-items: center; }


/* =============================================================================
   BUTTONS
   ============================================================================= */

.button {
    --btn-bg:        var(--brand-blue);
    --btn-fg:        var(--text-inverse);
    --btn-border:    transparent;
    --btn-bg-hover:  var(--brand-blue-hover);
    --btn-bg-active: var(--brand-blue-active);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-height: 36px;
    padding: 0 var(--s-4);
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: 1px solid var(--btn-border);
    border-radius: var(--r-sm);
    font: var(--fw-medium) var(--text-body)/1 var(--font-family);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
    user-select: none;
}
.button:hover:not(:disabled)  { background: var(--btn-bg-hover); }
.button:active:not(:disabled) { background: var(--btn-bg-active); }
.button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Secondary — outlined blue */
.button[data-variant="secondary"] {
    --btn-bg:        var(--surface);
    --btn-fg:        var(--brand-blue);
    --btn-border:    var(--brand-blue);
    --btn-bg-hover:  var(--brand-blue-tint);
    --btn-bg-active: var(--brand-blue-tint);
}

/* Ghost — no border, blue text */
.button[data-variant="ghost"] {
    --btn-bg:        transparent;
    --btn-fg:        var(--brand-blue);
    --btn-border:    transparent;
    --btn-bg-hover:  var(--brand-blue-tint);
    --btn-bg-active: var(--surface-sunken);
}

/* Quiet — grey ghost for low-emphasis actions (cancel, dismiss) */
.button[data-variant="quiet"] {
    --btn-bg:        transparent;
    --btn-fg:        var(--text-secondary);
    --btn-border:    transparent;
    --btn-bg-hover:  var(--surface-alt);
    --btn-bg-active: var(--surface-sunken);
}

/* Danger — destructive actions */
.button[data-variant="danger"] {
    --btn-bg:        var(--adv-urgent-fg);
    --btn-fg:        var(--text-inverse);
    --btn-border:    transparent;
    --btn-bg-hover:  #7f1d1d;
    --btn-bg-active: #681616;
}

/* Sizes */
.button[data-size="sm"] { min-height: 28px; padding: 0 var(--s-3); font-size: var(--text-sm); }
.button[data-size="lg"] { min-height: 44px; padding: 0 var(--s-5); font-size: var(--text-lg); }

/* When a loading ring sits on the primary (filled blue) button, it inherits
   white via the `data-tint="white"` filter so the shape character is preserved. */
.button .ring { --ring-size: 14px; }


/* =============================================================================
   FORMS
   ============================================================================= */

.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field-label {
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    color: var(--text-primary);
}
.field-hint  { font-size: var(--text-xs); color: var(--text-muted); }
.field-error { font-size: var(--text-xs); color: var(--adv-urgent-fg); }

.input, .textarea, .select {
    width: 100%;
    min-height: 36px;
    padding: 0 var(--s-3);
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    font: var(--fw-regular) var(--text-body)/1.4 var(--font-family);
    transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}
.textarea { padding: var(--s-2) var(--s-3); min-height: 88px; resize: vertical; line-height: var(--lh-body); }
.input::placeholder, .textarea::placeholder { color: var(--text-disabled); }

.input:hover:not(:disabled),
.textarea:hover:not(:disabled),
.select:hover:not(:disabled) {
    border-color: var(--text-muted);
}
.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible {
    border-color: var(--brand-blue);
    box-shadow: var(--focus-ring);
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
    border-color: var(--adv-urgent-fg);
}
.input:disabled, .textarea:disabled, .select:disabled {
    background: var(--surface-sunken);
    color: var(--text-disabled);
    cursor: not-allowed;
}

.checkbox, .radio {
    width: 16px; height: 16px;
    accent-color: var(--brand-blue);
    cursor: pointer;
}


/* =============================================================================
   CARDS
   ============================================================================= */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-none);
    padding: var(--s-5);
}
.card[data-elevation="1"] { box-shadow: var(--shadow-sm); }
.card[data-elevation="2"] { box-shadow: var(--shadow-md); }

.card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: var(--s-3);
    gap: var(--s-3);
}
.card-title { font-size: var(--text-lg); font-weight: var(--fw-semibold); color: var(--text-primary); margin: 0; }
.card-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.card-divider { border: 0; border-top: 1px solid var(--border); margin: var(--s-4) 0; }


/* =============================================================================
   BADGES / CHIPS
   ============================================================================= */

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    padding: 2px var(--s-2);
    font-size: var(--text-xs);
    font-weight: var(--fw-medium);
    border-radius: var(--r-sm);
    background: var(--surface-alt);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.chip[data-variant="urgent"] {
    background: var(--adv-urgent-bg);
    color: var(--adv-urgent-fg);
    border-color: var(--adv-urgent-border);
}
.chip[data-variant="strong"] {
    background: var(--adv-strong-bg);
    color: var(--adv-strong-fg);
    border-color: var(--adv-strong-border);
}
.chip[data-variant="preference"] {
    background: var(--adv-preference-bg);
    color: var(--adv-preference-fg);
    border-color: var(--adv-preference-border);
}
.chip[data-variant="info"] {
    background: var(--adv-info-bg);
    color: var(--adv-info-fg);
    border-color: var(--adv-info-border);
}
.chip[data-variant="remission"]  { color: var(--status-remission);  }
.chip[data-variant="active"]     { color: var(--status-high);       }

/* Status dot (for patient list / inline disease-activity state) */
.status-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--status-unknown);
}
.status-dot[data-status="remission"]    { background: var(--status-remission); }
.status-dot[data-status="low"]          { background: var(--status-low-activity); }
.status-dot[data-status="moderate"]     { background: var(--status-moderate); }
.status-dot[data-status="high"]         { background: var(--status-high); }


/* =============================================================================
   ADVISORY STRIP — Phase 2 output rendered UI-side
   ============================================================================= */

.advisory-strip {
    display: flex;
    gap: var(--s-3);
    align-items: flex-start;
    padding: var(--s-3) var(--s-4);
    background: var(--adv-info-bg);
    color: var(--adv-info-fg);
    border: 1px solid var(--adv-info-border);
    border-left: 4px solid var(--adv-info-fg);
    border-radius: var(--r-sm);
}
.advisory-strip[data-severity="urgent"] {
    background: var(--adv-urgent-bg);
    color: var(--adv-urgent-fg);
    border-color: var(--adv-urgent-border);
    border-left-color: var(--adv-urgent-fg);
}
.advisory-strip[data-severity="strong"] {
    background: var(--adv-strong-bg);
    color: var(--adv-strong-fg);
    border-color: var(--adv-strong-border);
    border-left-color: var(--adv-strong-fg);
}
.advisory-strip[data-severity="preference"] {
    background: var(--adv-preference-bg);
    color: var(--adv-preference-fg);
    border-color: var(--adv-preference-border);
    border-left-color: var(--adv-preference-fg);
}

.advisory-title { font-weight: var(--fw-semibold); font-size: var(--text-body); line-height: 1.35; color: inherit; }
.advisory-body  { font-size: var(--text-sm); color: inherit; margin-top: 2px; line-height: var(--lh-body); }
.advisory-action {
    margin-top: var(--s-2);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    color: inherit;
}


/* =============================================================================
   TABLE (data-dense)
   ============================================================================= */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
}
.table thead th {
    text-align: left;
    font-size: var(--text-xs);
    font-weight: var(--fw-medium);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--border-strong);
    background: var(--surface);
    white-space: nowrap;
    position: sticky;
    top: 0;
}
.table tbody td {
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    color: var(--text-primary);
    line-height: var(--lh-dense);
}
.table tbody tr:hover td { background: var(--surface-alt); }
.table .num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: var(--ffs-tabular);
    text-align: right;
    white-space: nowrap;
}


/* =============================================================================
   TABS
   ============================================================================= */

.tabs {
    display: flex;
    gap: var(--s-4);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--s-4);
}
.tab {
    background: none;
    border: none;
    font: var(--fw-medium) var(--text-body)/1 var(--font-family);
    color: var(--text-secondary);
    padding: var(--s-3) 0;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color var(--motion-fast), border-color var(--motion-fast);
}
.tab:hover { color: var(--text-primary); }
.tab.is-active {
    color: var(--brand-blue);
    border-bottom-color: var(--brand-blue);
}


/* =============================================================================
   MODAL
   ============================================================================= */

.modal-scrim {
    position: fixed; inset: 0;
    background: rgba(10, 15, 26, 0.35);
    z-index: 50;
    display: flex; align-items: center; justify-content: center;
    padding: var(--s-4);
}
.modal {
    background: var(--surface);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-lg);
    max-width: 520px;
    width: 100%;
    padding: var(--s-6);
    max-height: 85vh;
    overflow: auto;
}
.modal-title { font-size: var(--text-xl); font-weight: var(--fw-semibold); margin: 0 0 var(--s-2); color: var(--text-primary); }
.modal-body  { color: var(--text-secondary); font-size: var(--text-body); line-height: var(--lh-body); }
.modal-footer {
    display: flex;
    gap: var(--s-2);
    justify-content: flex-end;
    margin-top: var(--s-5);
}


/* =============================================================================
   EMPTY STATE
   ============================================================================= */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-12) var(--s-6);
    background: var(--surface-alt);
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-md);
    text-align: center;
}
.empty-state .ring { --ring-size: 64px; }
.empty-state-title { font-size: var(--text-body); color: var(--text-secondary); font-weight: var(--fw-medium); }
.empty-state-caption { font-size: var(--text-xs); color: var(--text-muted); }


/* =============================================================================
   TIMELINE (treatment history, encounter list)
   ============================================================================= */

.timeline {
    position: relative;
    padding-left: var(--s-5);
}
.timeline::before {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    left: var(--s-2);
    width: 1px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding-bottom: var(--s-5);
}
.timeline-item::before {
    content: "";
    position: absolute;
    top: 4px;
    left: calc(-1 * var(--s-3) - 3px);
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--brand-blue);
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--brand-blue);
}
.timeline-date {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-feature-settings: var(--ffs-tabular);
    margin-bottom: 2px;
}
.timeline-title { font-weight: var(--fw-semibold); font-size: var(--text-body); color: var(--text-primary); }
.timeline-body  { color: var(--text-secondary); font-size: var(--text-sm); margin-top: 2px; }


/* =============================================================================
   TOAST
   ============================================================================= */

.toast-region {
    position: fixed;
    bottom: var(--s-6); right: var(--s-6);
    display: flex; flex-direction: column; gap: var(--s-2);
    z-index: 60;
    pointer-events: none;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow-lg);
    padding: var(--s-3) var(--s-4);
    font-size: var(--text-body);
    color: var(--text-primary);
    min-width: 260px;
    pointer-events: auto;
}
.toast[data-variant="success"] { border-left: 3px solid var(--status-low-activity); }
.toast[data-variant="error"]   { border-left: 3px solid var(--adv-urgent-fg); }
.toast[data-variant="info"]    { border-left: 3px solid var(--brand-blue); }

/* Phase 8 — skip link visible on focus for keyboard users */
.skip-link:focus {
    left: var(--s-4) !important;
    top: var(--s-4) !important;
    z-index: 10000;
    background: var(--surface);
    color: var(--brand-blue);
    padding: var(--s-2) var(--s-4);
    border: 2px solid var(--brand-blue);
    border-radius: var(--r-sm);
    font-weight: 600;
    text-decoration: none;
    box-shadow: var(--shadow-md);
}
