/* ===================================================================
   Stetho Clinical Platform — Base Application Styles
   ===================================================================
   Color palette (medical / clinical — blue-based):
     --stetho-primary:      #1565c0   (blue 800)
     --stetho-primary-dark: #0d47a1   (blue 900)
     --stetho-accent:       #1976d2   (blue 700)
     --stetho-accent-light: #42a5f5   (blue 400)
     --stetho-surface:      #f4f7fb   (cool off-white)
     --stetho-surface-alt:  #e8f0fe   (light blue tint)
     --stetho-text:         #1e2a36   (near-black)
     --stetho-text-muted:   #5a6a7a   (muted blue-grey)
     --stetho-border:       #e3e8ef   (light border)
     --stetho-danger:       #d32f2f   (clinical red)
     --stetho-warning:      #f59e0b   (amber)
     --stetho-success:      #2e7d32   (green)
   =================================================================== */

:root {
    --stetho-primary: #1565c0;
    --stetho-primary-dark: #0d47a1;
    --stetho-accent: #1976d2;
    --stetho-accent-light: #42a5f5;
    --stetho-surface: #f4f7fb;
    --stetho-surface-alt: #e8f0fe;
    --stetho-text: #1e2a36;
    --stetho-text-muted: #5a6a7a;
    --stetho-border: #e3e8ef;
    --stetho-danger: #d32f2f;
    --stetho-warning: #f59e0b;
    --stetho-success: #2e7d32;
}

/* ── Reset / base ──────────────────────────────────────────────────── */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif;
    font-size: 14.5px;
    color: var(--stetho-text);
    background-color: #ffffff;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* ── Typography ────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    color: var(--stetho-primary);
    margin-top: 0;
    line-height: 1.3;
}

h1 { font-size: 1.85rem; font-weight: 700; margin-bottom: 12px; }
h2 { font-size: 1.5rem;  font-weight: 600; margin-bottom: 10px; }
h3 { font-size: 1.2rem;  font-weight: 600; margin-bottom: 8px; }
h4 { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; color: var(--stetho-text); }
h5 { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; color: var(--stetho-text); }
h6 { font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--stetho-text-muted); }

/* FluentUI form labels — larger for clinical readability */
fluent-text-field::part(label),
fluent-text-area::part(label),
fluent-number-field::part(label),
fluent-select::part(label),
fluent-combobox::part(label),
fluent-date-picker::part(label),
fluent-time-picker::part(label),
fluent-checkbox::part(label),
fluent-radio-group::part(label),
fluent-search::part(label) {
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--stetho-text);
    letter-spacing: 0.01em;
}

/* Required field indicator */
fluent-text-field[required]::part(label)::after,
fluent-select[required]::part(label)::after,
fluent-number-field[required]::part(label)::after {
    content: " *";
    color: var(--stetho-danger);
    font-weight: 600;
}

/* Consistent paragraph and body text */
p {
    line-height: 1.6;
    margin-bottom: 8px;
}

/* Small / caption text */
.text-caption {
    font-size: 0.75rem;
    color: var(--stetho-text-muted);
    line-height: 1.4;
}

/* Section label (above card groups) */
.section-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--stetho-text-muted);
    margin-bottom: 8px;
}

a {
    color: var(--stetho-accent);
    text-decoration: none;
}

a:hover {
    color: var(--stetho-primary);
    text-decoration: underline;
}

/* ── Focus ring (accessibility) ────────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--stetho-accent);
    outline-offset: 2px;
}

/* ── Scrollbar (Chromium / Edge) ───────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--stetho-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--stetho-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--stetho-text-muted);
}

/* ── Validation ────────────────────────────────────────────────────── */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--stetho-success);
}

.invalid {
    outline: 1px solid var(--stetho-danger);
}

.validation-message {
    color: var(--stetho-danger);
    font-size: 0.8rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* FluentUI field-level validation styles */
.field-error {
    color: var(--stetho-danger);
    font-size: 0.8rem;
    margin-top: 4px;
    padding: 2px 0;
}

.field-success {
    color: var(--stetho-success);
    font-size: 0.8rem;
    margin-top: 4px;
}

/* Validation summary (top of form) */
.validation-summary {
    background: #fde7e9;
    border: 1px solid #f5c6cb;
    border-left: 3px solid var(--stetho-danger);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    color: #721c24;
}

.validation-summary ul {
    margin: 4px 0 0 0;
    padding-left: 20px;
}

.validation-summary li {
    margin-bottom: 2px;
}

/* Required indicator for custom labels */
.required-indicator::after {
    content: " *";
    color: var(--stetho-danger);
    font-weight: 600;
}

/* FluentUI component validation state overrides */
fluent-text-field.invalid,
fluent-select.invalid,
fluent-number-field.invalid,
fluent-combobox.invalid {
    --accent-fill-rest: var(--stetho-danger);
    outline: 1px solid var(--stetho-danger);
    border-radius: 4px;
}

fluent-text-field.valid.modified,
fluent-select.valid.modified,
fluent-number-field.valid.modified {
    --accent-fill-rest: var(--stetho-success);
    outline: 1px solid var(--stetho-success);
    border-radius: 4px;
}

/* ── Blazor error boundary ─────────────────────────────────────────── */
.blazor-error-boundary {
    background: var(--stetho-danger);
    padding: 1rem 1rem 1rem 3.7rem;
    color: #ffffff;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* ── Utility classes ───────────────────────────────────────────────── */
.text-muted {
    color: var(--stetho-text-muted) !important;
}

.bg-surface {
    background-color: var(--stetho-surface);
}

.border-bottom {
    border-bottom: 1px solid var(--stetho-border);
}

.fluent-soft-bg {
    background: radial-gradient(circle at 80% 20%, #edf3ff, transparent 60%), linear-gradient(135deg, #ffffff, #eef4ff);
}

/* ── FluentDataGrid — Global Enhancements ─────────────────────────── */

/* Alternating row stripes */
fluent-data-grid-row:nth-child(even) {
    background: #f8fafe;
}

fluent-data-grid-row:hover {
    background: var(--stetho-surface-alt) !important;
}

/* Header styling */
fluent-data-grid-row[row-type="header"],
fluent-data-grid-row[row-type="sticky-header"] {
    background: #eef3f9;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #37474f;
    border-bottom: 2px solid var(--stetho-border);
}

/* Cell padding and borders */
fluent-data-grid-cell {
    font-size: 0.85rem;
    padding: 4px 12px;
    border-bottom: 1px solid #eef1f5;
    color: var(--stetho-text);
}

/* Compact row height for dense clinical data */
fluent-data-grid-row {
    min-height: unset;
    height: auto;
}

/* Paginator styling */
fluent-data-grid + .fluent-paginator,
.fluent-paginator {
    margin-top: 8px;
    padding: 8px 0;
    border-top: 1px solid var(--stetho-border);
}

/* ── Page header pattern ──────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 16px;
    border-bottom: 2px solid var(--stetho-border);
    margin-bottom: 20px;
}

.page-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

/* Page title text */
.page-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--stetho-primary);
    margin: 0;
    line-height: 1.3;
}

/* Section title (within cards/panels) */
.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--stetho-primary);
    margin: 0 0 12px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--stetho-border);
}

/* Subsection title (smaller, no border) */
.subsection-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--stetho-text);
    margin: 0 0 8px 0;
}

/* ── Card container for form sections ─────────────────────────────── */
.form-card {
    background: #ffffff;
    border: 1px solid var(--stetho-border);
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 16px;
}

.form-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--stetho-primary);
    margin: 0 0 14px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--stetho-border);
    letter-spacing: 0.01em;
}

/* ── Two-column form layout ───────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 24px;
}

.form-grid-full {
    grid-column: 1 / -1;
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Grid action icon buttons ─────────────────────────────────────── */
.grid-action-btn {
    min-width: auto !important;
    padding: 2px 6px !important;
    cursor: pointer;
}
.grid-action-btn img {
    width: 16px;
    height: 16px;
    opacity: 0.65;
    transition: opacity 0.15s;
}
.grid-action-btn:hover img {
    opacity: 1;
}

/* ── Grid toolbar / quick filter bar ─────────────────────────────── */
.grid-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--stetho-surface);
    border: 1px solid var(--stetho-border);
    border-radius: 8px 8px 0 0;
    border-bottom: none;
    flex-wrap: wrap;
}

.grid-toolbar + fluent-data-grid {
    border: 1px solid var(--stetho-border);
    border-radius: 0 0 8px 8px;
}

.grid-toolbar .toolbar-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--stetho-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-right: 4px;
    white-space: nowrap;
}

.grid-toolbar fluent-search {
    min-width: 200px;
}

.grid-count {
    font-size: 0.8rem;
    color: var(--stetho-text-muted);
    margin-left: auto;
    white-space: nowrap;
}

/* ── Status badges ────────────────────────────────────────────────── */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.status-active   { background: #e8f5e9; color: #2e7d32; }
.status-inactive { background: #fafafa; color: #9e9e9e; }
.status-pending  { background: #fff8e1; color: #f57c00; }
.status-urgent   { background: #fbe9e7; color: #d32f2f; }
.status-complete { background: #e3f2fd; color: #1565c0; }

/* ── Hub/Module cards ────────────────────────────────────────────── */
.hub-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.hub-card {
    background: #ffffff;
    border: 1px solid var(--stetho-border);
    border-radius: 10px;
    padding: 20px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
}

.hub-card:hover {
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.12);
    border-color: var(--stetho-accent-light);
    transform: translateY(-2px);
}

.hub-card-icon {
    width: 36px;
    height: 36px;
    opacity: 0.7;
    filter: brightness(0) saturate(100%) invert(32%) sepia(85%) saturate(1200%) hue-rotate(196deg) brightness(95%) contrast(95%);
}

.hub-card h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--stetho-text);
}

.hub-card p {
    margin: 0;
    font-size: 0.78rem;
    color: var(--stetho-text-muted);
    line-height: 1.3;
}

/* ===================================================================
   Accessibility Enhancements
   =================================================================== */

/* ── Focus indicators ─────────────────────────────────────────────── */
fluent-button:focus-visible,
fluent-text-field:focus-visible,
fluent-select:focus-visible,
fluent-combobox:focus-visible,
fluent-number-field:focus-visible,
fluent-date-picker:focus-visible,
fluent-time-picker:focus-visible,
fluent-checkbox:focus-visible,
fluent-radio:focus-visible,
fluent-search:focus-visible,
fluent-tab:focus-visible {
    outline: 2px solid var(--stetho-accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Skip to main content (screen reader) ─────────────────────────── */
.skip-to-main {
    position: absolute;
    top: -100%;
    left: 16px;
    z-index: 10000;
    padding: 8px 16px;
    background: var(--stetho-primary);
    color: #ffffff;
    font-weight: 600;
    border-radius: 0 0 6px 6px;
    text-decoration: none;
    transition: top 0.2s;
}
.skip-to-main:focus {
    top: 0;
}

/* ── Screen reader only utility ───────────────────────────────────── */
.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;
}

/* ── High contrast mode (Windows / forced-colors) ─────────────────── */
@media (forced-colors: active) {
    .form-card {
        border: 2px solid CanvasText;
    }
    .form-card-title {
        border-bottom: 2px solid CanvasText;
        color: CanvasText;
    }
    .status-badge {
        border: 1px solid CanvasText;
    }
    fluent-data-grid-row[row-type="header"],
    fluent-data-grid-row[row-type="sticky-header"] {
        border-bottom: 2px solid CanvasText;
    }
    fluent-data-grid-cell {
        border-bottom: 1px solid CanvasText;
    }
    .hub-card {
        border: 2px solid CanvasText;
    }
    .grid-action-btn img {
        opacity: 1;
        forced-color-adjust: auto;
    }
    h1, h2, h3, h4, h5, h6 {
        color: CanvasText;
    }
}

/* ── Prefers high contrast (custom toggle support) ────────────────── */
@media (prefers-contrast: more) {
    :root {
        --stetho-border: #90a4ae;
        --stetho-text-muted: #37474f;
    }
    fluent-data-grid-cell {
        font-size: 0.9rem;
        border-bottom: 1px solid #90a4ae;
    }
    fluent-data-grid-row[row-type="header"],
    fluent-data-grid-row[row-type="sticky-header"] {
        font-size: 0.85rem;
        border-bottom: 2px solid #455a64;
    }
    .form-card {
        border: 1px solid #90a4ae;
    }
    .status-badge {
        font-weight: 600;
    }
}

/* ── Reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .hub-card:hover {
        transform: none;
    }
}

/* ── Keyboard navigation for dialog focus trap ────────────────────── */
fluent-dialog:focus-within {
    outline: none;
}
fluent-dialog fluent-button:focus-visible,
fluent-dialog fluent-text-field:focus-visible,
fluent-dialog fluent-select:focus-visible {
    outline: 2px solid var(--stetho-accent);
    outline-offset: 2px;
}

/* ───────────────────────────────────────────────────────────────────────────
   Order entry — shared bits (global, not scoped): the kind tags and filter
   chips are used by both OrderEntryPanel and the Doctor's Workbench order
   list, so they cannot live in either component's scoped stylesheet.
   Panel-specific layout stays in OrderEntryPanel.razor.css.
   ─────────────────────────────────────────────────────────────────────────── */
.oe-kind-tag {
    display: inline-block;
    flex-shrink: 0;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: .4px;
    padding: 2px 6px;
    border-radius: 3px;
    background: #eceff1;
    color: #455a64;
    min-width: 40px;
    text-align: center;
}

.oe-medication, .oe-drug { background: #e8f5e9; color: #2e7d32; }
.oe-lab                  { background: #e3f2fd; color: #1565c0; }
.oe-radiology, .oe-rad   { background: #ede7f6; color: #5e35b1; }
.oe-procedure, .oe-proc  { background: #fff3e0; color: #ef6c00; }
.oe-package, .oe-pkg-tag { background: #fce4ec; color: #ad1457; }
.oe-other                { background: #eceff1; color: #607d8b; }

.oe-chip {
    border: 1px solid #cfd8dc;
    background: #fff;
    color: #455a64;
    border-radius: 14px;
    padding: 3px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.oe-chip:hover { background: #eceff1; }

.oe-chip-on {
    background: var(--stetho-primary, #1565c0);
    border-color: var(--stetho-primary, #1565c0);
    color: #fff;
}
