/* Parley Neurotech Brand Colors */
:root {
    --parley-electric-blue: #00A8FF;
    --parley-navy-blue: #1B365D;
    --parley-silver-gray: #5C6B7F;
    --parley-white: #FFFFFF;
    --parley-black: #1a1a1a;
    --error-red: #D32F2F;
    --success-green: #4CAF50;

    /* Semantic status tokens (FAB4-MAINT-01) — the re-skin contract.
       Templates reference these via var(--…); change a value here and every
       status badge/banner across the portal follows. Values are the exact hex
       that templates used before the 2026-07-07 sweep (value-preserving).
       See docs/THEMING.md before editing. */
    --status-success: #2e7d32;
    --status-success-bg: #e8f5e9;
    --status-error: #c62828;
    --status-error-bg: #ffebee;
    --status-info: #1565c0;
    --status-info-bg: #e3f2fd;
    --status-warning: #f57f17;
    --status-warning-bg: #fff8e1;
    --status-warning-strong: #e65100;
    --status-warning-strong-bg: #fff3e0;
    --surface-muted: #f5f5f5;
    --border-muted: #e0e0e0;
    --text-muted: #666666;

    /* Role-specific theme colors */
    --theme-patient-primary: #00A8FF;        /* Light/Electric Blue */
    --theme-patient-secondary: #0096E6;
    --theme-patient-bg: #E8F7FF;

    --theme-audiologist-primary: #1B365D;    /* Navy Blue */
    --theme-audiologist-secondary: #2a4a7f;
    --theme-audiologist-bg: #E8ECF2;

    --theme-provider-primary: #8E9AAF;       /* Silver Gray */
    --theme-provider-secondary: #6B7A94;
    --theme-provider-bg: #F5F6F8;

    --theme-admin-primary: #1a1a1a;          /* Black */
    --theme-admin-secondary: #333333;
    --theme-admin-bg: #F0F0F0;

    --theme-superuser-primary: #D32F2F;      /* Red */
    --theme-superuser-secondary: #B71C1C;
    --theme-superuser-bg: #FFEBEE;
}

/* Role-specific body classes */
body.theme-patient {
    --theme-primary: var(--theme-patient-primary);
    --theme-secondary: var(--theme-patient-secondary);
    --theme-bg: var(--theme-patient-bg);
}

body.theme-audiologist {
    --theme-primary: var(--theme-audiologist-primary);
    --theme-secondary: var(--theme-audiologist-secondary);
    --theme-bg: var(--theme-audiologist-bg);
}

body.theme-provider {
    --theme-primary: var(--theme-provider-primary);
    --theme-secondary: var(--theme-provider-secondary);
    --theme-bg: var(--theme-provider-bg);
}

body.theme-admin {
    --theme-primary: var(--theme-admin-primary);
    --theme-secondary: var(--theme-admin-secondary);
    --theme-bg: var(--theme-admin-bg);
}

body.theme-superuser {
    --theme-primary: var(--theme-superuser-primary);
    --theme-secondary: var(--theme-superuser-secondary);
    --theme-bg: var(--theme-superuser-bg);
}

/* Themed header for role-specific styling */
body.theme-patient header { background-color: var(--theme-patient-primary); }
body.theme-audiologist header { background-color: var(--theme-audiologist-primary); }
body.theme-provider header { background-color: var(--theme-provider-primary); color: var(--parley-navy-blue); }
body.theme-admin header { background-color: var(--theme-admin-primary); }
body.theme-superuser header { background-color: var(--theme-superuser-primary); }

/* Provider header needs navy text for contrast with silver background */
body.theme-provider header .user-info { color: var(--parley-navy-blue); }
body.theme-provider header .user-info a { color: var(--parley-navy-blue); }

/* Themed navigation for role-specific styling */
body.theme-patient nav { background-color: var(--theme-patient-secondary); }
body.theme-audiologist nav { background-color: var(--theme-audiologist-secondary); }
body.theme-provider nav { background-color: var(--theme-provider-secondary); }
body.theme-admin nav { background-color: var(--theme-admin-secondary); }
body.theme-superuser nav { background-color: var(--theme-superuser-secondary); }

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    background-color: var(--parley-white);
    color: var(--parley-navy-blue);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Neuron background textures (toggled via SystemSettings) */
body.light-neuron-bg {
    background-image: url('../images/lightNeuron_bkgrnd.png');
    background-repeat: repeat;
    background-color: var(--parley-white);
}

body.ocean-neuron-bg {
    background-image: url('../images/oceanNeuron_bkgrnd.png');
    background-repeat: repeat-x;
    background-size: auto 100vh;
    background-attachment: fixed;
    background-color: #1576b8;
    min-height: 100vh;
}

/* Header */
header {
    background-color: var(--parley-navy-blue);
    color: var(--parley-white);
    padding: 20px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 24px;
    font-weight: 700;
}

.user-info {
    font-size: 14px;
}

/* Mobile hamburger button — hidden on desktop, shown in the @media block below. */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: 0;
    padding: 8px;
    cursor: pointer;
    margin-right: 8px;
}
.nav-hamburger span {
    display: block;
    width: 26px;
    height: 3px;
    background: var(--parley-white);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-hamburger.is-open span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.nav-hamburger.is-open span:nth-child(2) { opacity: 0; }
.nav-hamburger.is-open span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* Navigation */
nav {
    background-color: var(--parley-electric-blue);
    padding: 0;
}

nav ul {
    list-style: none;
    display: flex;
    margin: 0;
    padding: 0;
}

nav ul li {
    margin: 0;
}

nav ul li a {
    display: block;
    color: var(--parley-white);
    text-decoration: none;
    padding: 16px 24px;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.3s;
}

nav ul li a:hover,
nav ul li a.active {
    background-color: rgba(0, 0, 0, 0.15);
}

/* Sub-navigation bar (U-03: patient-specific links in a secondary row) */
nav.subnav {
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    padding: 0;
}

nav.subnav ul li a {
    padding: 10px 20px;
    font-size: 14px;
}

nav.subnav .subnav-label {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    font-size: 12px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* Patient name as a link in subnav — styled like a label but clickable */
nav.subnav .subnav-patient-name {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.75) !important;
}

nav.subnav .subnav-patient-name:hover,
nav.subnav .subnav-patient-name.active {
    color: var(--parley-white) !important;
    background: rgba(255, 255, 255, 0.1);
}

/* Navigation badge for unread counts */
.nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--parley-white);
    color: var(--parley-navy-blue);
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    padding: 0 6px;
}

/* Main Content */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px;
    flex: 1;
}

/* Login Page Specific */
.login-container {
    max-width: 450px;
    margin: 100px auto;
    padding: 40px;
    background: var(--parley-white);
    border: 1px solid rgba(142, 154, 175, 0.3);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    color: var(--parley-navy-blue);
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--parley-silver-gray);
    font-size: 16px;
}

/* Forms */
.form-group {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--parley-navy-blue);
    font-size: 14px;
}

input[type="text"],
input[type="password"],
input[type="email"] {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(142, 154, 175, 0.5);
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus {
    outline: none;
    border-color: var(--parley-electric-blue);
    box-shadow: 0 0 0 2px rgba(0, 168, 255, 0.1);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
    min-height: 44px;
    line-height: 20px;
}

.btn-primary {
    background-color: var(--parley-electric-blue);
    color: var(--parley-white);
    width: 100%;
}

.btn-primary:hover {
    background-color: #0096e6;
}

.btn-secondary {
    background-color: var(--parley-white);
    color: var(--parley-navy-blue);
    border: 2px solid var(--parley-navy-blue);
}

.btn-secondary:hover {
    background-color: var(--parley-navy-blue);
    color: var(--parley-white);
}

/* Shared action/navigation bar — bottom of patient-specific pages */
.action-bar {
    background: var(--parley-white);
    border: 1px solid rgba(142, 154, 175, 0.3);
    border-radius: 8px;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 24px;
}

.action-bar .btn {
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
    display: inline-block;
}

.action-bar .btn-secondary {
    background: rgba(142, 154, 175, 0.15);
    color: var(--parley-navy-blue);
}

.action-bar .btn-secondary:hover {
    background: rgba(142, 154, 175, 0.28);
    color: var(--parley-navy-blue);
}

/* Sort icons on table headers */
.sort-icon {
    margin-left: 4px;
    font-size: 0.82em;
    opacity: 0.45;
    display: inline-block;
    vertical-align: middle;
}
.sort-icon.sort-asc,
.sort-icon.sort-desc {
    opacity: 1;
    color: var(--parley-electric-blue);
}

/* Chat message link colours — ensure contrast on coloured bubble backgrounds */
.message.sent .msg-internal-link,
.message.sent .msg-external-link {
    color: rgba(255, 255, 255, 0.92) !important;
    text-decoration-color: rgba(255, 255, 255, 0.6) !important;
}

/* Messages/Alerts */
.messages {
    margin: 24px 0;
}

.alert {
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success {
    background-color: rgba(76, 175, 80, 0.1);
    border: 1px solid var(--success-green);
    color: #2e7d32;
}

.alert-error {
    background-color: rgba(211, 47, 47, 0.1);
    border: 1px solid var(--error-red);
    color: #c62828;
}

/* Dashboard Welcome Panel */
.welcome-panel {
    background: var(--parley-white);
    border: 1px solid rgba(142, 154, 175, 0.3);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 24px;
}

.welcome-panel h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--parley-navy-blue);
    margin-bottom: 8px;
}

.welcome-panel p {
    color: var(--parley-silver-gray);
    font-size: 14px;
    margin: 4px 0;
}

/* Quick Action Cards */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.action-card {
    background: var(--parley-white);
    border: 1px solid rgba(142, 154, 175, 0.3);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    transition: box-shadow 0.3s;
    cursor: pointer;
}

.action-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.action-card h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--parley-navy-blue);
    margin-bottom: 8px;
}

.action-card p {
    color: var(--parley-silver-gray);
    font-size: 14px;
}

/* Footer — pushed to bottom by flex layout on body */
footer {
    background-color: var(--parley-silver-gray);
    color: var(--parley-white);
    text-align: center;
    padding: 16px;
    font-size: 14px;
    margin-top: auto;
}

footer a {
    color: var(--parley-white);
    text-decoration: none;
    margin: 0 8px;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive table wrapper - use on parent div of wide tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    header {
        padding: 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    header .user-info {
        font-size: 13px;
    }

    nav ul {
        flex-wrap: wrap;
        gap: 4px;
    }

    nav ul li a {
        padding: 8px 12px;
        font-size: 13px;
    }

    .login-container {
        margin: 24px auto;
        padding: 24px;
    }

    /* Make table parent containers scrollable on mobile */
    .table-responsive,
    .container > div:has(> table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Stop the page from scrolling sideways WITHOUT breaking the sticky header. Use
       overflow-x:CLIP on the root — not hidden. `clip` clips overflow at the viewport edge
       but, unlike `hidden`, does NOT create a scroll container, so position:sticky on the
       header keeps working. This catches horizontal overflow from ANY element (cards, the
       nav, the device-prompt banner, fixed overlays) — clipping only at .container missed
       overflow from elements that live outside it. */
    html { overflow-x: clip; }
    /* Wide tables fit + scroll inside their own box (override fixed min-widths on mobile). */
    table { display: block; width: 100%; max-width: 100%; min-width: 0 !important; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    /* Long preformatted text / SQL / tracebacks and unbreakable strings wrap. */
    pre, code { white-space: pre-wrap; word-break: break-word; }
    .container, .welcome-panel, .action-card, .primary-card { overflow-wrap: anywhere; }

    /* Keep media + form controls inside the viewport */
    img, svg, video, canvas { max-width: 100%; height: auto; }
    input, textarea, select { max-width: 100%; box-sizing: border-box; }

    /* Collapse multi-column layouts (incl. inline-styled grids on the hyperparameters,
       admin, and analytics pages) to a single column so nothing overflows on mobile. */
    .quick-actions, .primary-actions, .wait-grid { grid-template-columns: 1fr !important; }
    [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

    /* Let inline space-between flex rows wrap instead of overflowing. */
    [style*="justify-content: space-between"] { flex-wrap: wrap; gap: 8px; }

    /* --- Structural overflow cure ---
       Flex/grid items default to min-width:auto, so a card with any wide or unbreakable
       content refuses to shrink and pushes past the viewport (boxes wider than the
       header/footer). Forcing min-width:0 lets them shrink to the column width. */
    .container { min-width: 0; }
    .quick-actions > *, .primary-actions > *, .wait-grid > *,
    .action-card, .primary-card, .welcome-panel, .wait-tile, .ship-card,
    .messages, .alert {
        min-width: 0;
        max-width: 100%;
    }

    /* --- Sticky header + hamburger nav (modern mobile pattern) --- */
    .nav-hamburger { display: flex; }
    header {
        position: sticky;
        top: 0;
        z-index: 200;
        padding: 12px 16px;
    }
    header .logo img { height: 32px; }

    /* Only the FIRST nav collapses behind the hamburger (the JS toggles that one). Any
       secondary nav (admin's second bar, the patient-context .subnav) stays in flow and
       simply wraps, so nothing becomes unreachable. */
    nav:first-of-type ul { display: none; }
    nav:first-of-type.nav-open ul {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: var(--header-h, 64px);
        left: 0;
        right: 0;
        max-height: calc(100vh - var(--header-h, 64px));
        overflow-y: auto;
        background-color: var(--parley-electric-blue);
        box-shadow: 0 10px 18px rgba(0, 0, 0, 0.25);
        z-index: 190;
        gap: 0;
    }
    nav:first-of-type.nav-open ul li a {
        padding: 14px 20px;
        font-size: 15px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }
    nav:not(:first-of-type) ul { flex-wrap: wrap; }

    /* Tame oversized inline headings on small screens. */
    h1 { font-size: 22px !important; }
    h2 { font-size: 19px !important; }
}

/* Narrow phones */
@media (max-width: 480px) {
    .container { padding: 12px; }
    header { padding: 12px; }
    .logo { font-size: 20px; }
    nav ul { flex-direction: column; }
    nav ul li a { padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
    .welcome-panel, .action-card, .primary-card { padding: 16px; }
    .btn, .btn-primary, .btn-secondary { width: 100%; box-sizing: border-box; }
}

/* Regulatory disclaimer (templates/partials/_regulatory_disclaimer.html).
   Shown on patient-facing therapy/measurement pages. Deliberately legible --
   muted, but not so faint it reads as hidden fine print. */
.regulatory-disclaimer {
    max-width: 900px;
    margin: 40px auto 24px auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border-muted);
    color: var(--parley-silver-gray);
    font-size: 13px;
    line-height: 1.6;
    text-align: center;
}
