/* ==========================================================================
   Global Stylesheet for MesoMicro
   ========================================================================== */

/* --- Reset & Base Typography --- */
:root {
    --bp-sm: 640px;
    --bp-md: 768px;
    --bp-lg: 1024px;
    --bp-xl: 1440px;
    --sticky-nav-offset: 56px;
    --dashboard-header-height: 56px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0 0 60px 0;
    background: #eceff1;
    color: #333;
    transition: background-color 0.4s ease;
}

h1, h2, h3, h4 {
    margin-top: 0;
}

/* --- Top Navigation Bar --- */
.top-nav {
    background: #18181b;
    color: white;
    padding: 10px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    box-sizing: border-box;
    min-height: 56px;
    gap: 12px;
}

.navbar-brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 5px;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .navbar-brand-logo {
        width: 28px;
        height: 28px;
    }
}

.top-nav a.back-link {
    color: #f4f4f5;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 600;
    padding: 6px 12px;
    border: 1px solid #3f3f46;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}

.top-nav a.back-link:hover {
    background: #27272a;
}

/* --- Cross-Document View Transitions & Back Button Entrance Animation --- */
@media (prefers-reduced-motion: no-preference) {
    @view-transition {
        navigation: auto;
    }
    .top-nav,
    .report-top-bar {
        view-transition-name: meso-top-nav;
    }
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation-duration: 140ms;
    }
    .header-brand-lockup {
        view-transition-name: meso-brand-lockup;
    }
    .nav-back-btn,
    .top-nav a.back-link {
        view-transition-name: meso-back-btn;
    }
    .top-nav a.back-link.animate-from-dashboard,
    .nav-back-btn.animate-from-dashboard {
        animation: slideFromDashboard 220ms cubic-bezier(0.16, 1, 0.3, 1) both;
    }
}

.top-nav a.back-link.animate-from-dashboard,
.nav-back-btn.animate-from-dashboard {
    height: 34px !important;
    min-height: 34px !important;
    box-sizing: border-box !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    border-radius: 6px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    text-decoration: none !important;
    overflow: hidden !important;
    min-width: 0 !important;
}

@keyframes slideFromDashboard {
    0% {
        opacity: 0;
        transform: translateX(-8px);
        max-width: 0;
        padding-left: 0;
        padding-right: 0;
        margin-right: -12px;
        border-color: transparent;
    }
    100% {
        opacity: 1;
        transform: translateX(0);
        max-width: 160px;
        padding-left: 14px;
        padding-right: 14px;
        margin-right: 0;
        border-color: #3f3f46;
    }
}

@media (max-width: 768px) {
    .top-nav a.back-link.animate-from-dashboard,
    .nav-back-btn.animate-from-dashboard {
        height: 28px !important;
        min-height: 28px !important;
        font-size: 0.78rem !important;
        padding-top: 2px !important;
        padding-bottom: 2px !important;
    }

    @keyframes slideFromDashboard {
        0% {
            opacity: 0;
            transform: translateX(-8px);
            max-width: 0;
            padding-left: 0;
            padding-right: 0;
            margin-right: -6px;
            border-color: transparent;
        }
        100% {
            opacity: 1;
            transform: translateX(0);
            max-width: 120px;
            padding-left: 8px;
            padding-right: 8px;
            margin-right: 0;
            border-color: #3f3f46;
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .top-nav a.back-link.animate-from-dashboard,
    .nav-back-btn.animate-from-dashboard {
        animation: none !important;
        max-width: none !important;
        opacity: 1 !important;
        transform: none !important;
        margin-right: 0 !important;
        padding-left: 14px !important;
        padding-right: 14px !important;
        border-color: #3f3f46 !important;
    }
    @media (max-width: 768px) {
        .top-nav a.back-link.animate-from-dashboard,
        .nav-back-btn.animate-from-dashboard {
            padding-left: 8px !important;
            padding-right: 8px !important;
        }
    }
}

/* --- Desktop Coach Brand Layout with Back Link --- */
.coach-nav-brand.has-back-link {
    display: flex;
    align-items: center;
    gap: 12px;
}
.coach-nav-brand.has-back-link .coach-brand-left,
.coach-nav-brand.has-back-link .coach-brand-center,
.coach-nav-brand.has-back-link .coach-brand-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}
.coach-nav-brand.has-back-link .coach-brand-sep {
    display: inline;
}

/* --- Standardized Top Navigation Bar Buttons (Desktop & General) --- */
.top-nav > button:not(.floating-nav-toggle-btn):not(.floating-save-btn),
.top-nav .coach-nav-actions > button:not(.floating-nav-toggle-btn):not(.floating-save-btn),
.top-nav .public-nav-actions > button:not(.floating-nav-toggle-btn):not(.floating-save-btn),
.top-nav .btn,
.top-nav .btn-primary,
.top-nav .btn-ghost,
.top-nav .btn-outline,
.top-nav .back-link:not(.animate-from-dashboard),
.top-nav .export-dropdown-btn,
.top-nav .split-btn-main,
.top-nav .split-btn-dropdown,
.top-nav .public-nav-btn {
    height: 34px !important;
    min-height: 34px !important;
    box-sizing: border-box !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    padding: 6px 14px !important;
    border-radius: 6px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    text-decoration: none !important;
}

.top-nav [hidden],
.top-nav [style*="display: none"],
.top-nav [style*="display:none"] {
    display: none !important;
}

.nav-label-compact {
    display: none;
}

@media (min-width: 769px) {
    .top-nav {
        flex-wrap: nowrap !important;
    }
    .top-nav .coach-nav-brand {
        flex-wrap: nowrap !important;
        min-width: 0;
        flex: 1 1 auto;
        margin-right: 10px;
    }
    .top-nav .coach-nav-brand .coach-brand-right,
    .top-nav .coach-nav-brand .nav-subtitle {
        flex: 0 1 auto !important;
        min-width: 0 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    .top-nav .coach-nav-brand .nav-brand-title {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        min-width: 0 !important;
    }
    .top-nav .coach-nav-actions {
        flex-wrap: nowrap !important;
        flex: 0 0 auto;
        gap: 6px !important;
    }
}

@media (min-width: 769px) and (max-width: 1360px) {
    .top-nav .coach-nav-brand .coach-brand-right,
    .top-nav .coach-nav-brand .nav-subtitle {
        display: none !important;
    }
}

@media (min-width: 769px) and (max-width: 1800px) {
    .nav-label-full {
        display: none !important;
    }
    .nav-label-compact {
        display: inline !important;
    }
    .top-nav .coach-nav-actions .btn,
    .top-nav .coach-nav-actions .btn-primary,
    .top-nav .coach-nav-actions .btn-ghost,
    .top-nav .coach-nav-actions .btn-outline,
    .top-nav .coach-nav-actions .export-dropdown-btn,
    .top-nav .coach-nav-actions .split-btn-main {
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
    }
    .top-nav .coach-nav-brand .nav-user-label,
    .top-nav .coach-nav-right .nav-user-label {
        max-width: 110px;
    }
    .top-nav .coach-nav-brand .nav-single-org-name {
        max-width: 120px;
    }
    .top-nav .coach-nav-brand .nav-workspace-suborg-name {
        max-width: 115px;
    }
}

.top-nav .split-btn-group {
    height: 34px !important;
    display: inline-flex !important;
    align-items: stretch !important;
}

.top-nav .split-btn-main {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.top-nav .split-btn-dropdown {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
    padding: 6px 10px !important;
}

/* --- Buttons --- */
button {
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
}

.btn {
    background: #18181b;
    color: #fff;
    border: 1px solid #18181b;
    padding: 10px 18px;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn:hover:not(:disabled) {
    background: #3f3f46;
}

.btn-outline {
    background: transparent;
    color: #18181b;
    border: 1px solid #d4d4d8;
    border-radius: 4px;
    padding: 6px 12px;
    font-weight: 600;
    font-size: 0.9em;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-outline:hover:not(:disabled) {
    background: #e4e4e7;
}

.btn-primary {
    background: #3b82f6;
    color: #fff;
    border: 1px solid #3b82f6;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: bold;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
    border-color: #2563eb;
}

.btn-black {
    background: #0f172a;
    color: #fff;
    border: 1px solid #0f172a;
    padding: 8px 14px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-black:hover:not(:disabled) {
    background: #334155;
}

.btn-ghost {
    background: transparent;
    color: #475569;
    border: 1px solid #cbd5e1;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-ghost:hover:not(:disabled) {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #94a3b8;
}

.btn-ghost.danger:hover:not(:disabled) {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #ef4444;
}

.btn-danger {
    color: #ef4444;
    border-color: #fca5a5;
    background: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #ef4444;
}

.btn-icon {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 1.1em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: #fee2e2;
    color: #ef4444;
}

.btn-icon.duplicate:hover {
    background: #e0f2fe;
    color: #0284c7;
}

/* --- Common Containers & Layout --- */
.container {
    max-width: 1400px;
    margin: 20px auto;
    padding: 0 20px;
}

.banner-box {
    background: #fff;
    border: 1px solid #ccc;
    padding: 20px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

/* Two-column layout with sticky sidebar */
.main-col {
    flex: 1;
    min-width: 0;
}

.side-col {
    flex: 0 0 400px;
    width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: calc(var(--sticky-nav-offset, 56px) + 19px);
    height: calc(100vh - var(--sticky-nav-offset, 56px) - 44px);
    overflow-y: auto;
    align-self: flex-start;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

/* --- Common Form Inputs --- */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="url"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9em;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

textarea {
    resize: vertical;
}

.search-bar {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.9em;
    box-sizing: border-box;
}

.search-bar:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* --- Export & Print Dropdown --- */
.export-dropdown {
    position: relative;
    display: inline-block;
}

.export-dropdown-content {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 8px;
    background-color: #fff;
    width: 350px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0px 10px 25px rgba(0,0,0,0.15);
    z-index: 1001;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #cbd5e1;
    color: #333;
    transition: all 0.2s ease;
    transform: translateY(-5px);
}

.export-group-header {
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #0f172a;
    margin: 12px 0 6px 0;
    padding-bottom: 3px;
    border-bottom: 1.5px solid #e2e8f0;
}
.export-group-header:first-of-type {
    margin-top: 0;
}

.export-option-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 7px;
    font-size: 0.85rem;
    cursor: pointer;
    color: #334155;
    line-height: 1.35;
    user-select: none;
}
.export-option-label.nested {
    margin-left: 22px;
    font-size: 0.8rem;
    color: #64748b;
}
.export-option-label input[type="checkbox"],
.export-option-label input[type="radio"] {
    margin-top: 2px;
    cursor: pointer;
    accent-color: #10b981;
}
.export-option-label input[type="checkbox"]:disabled + span,
.export-option-label input[type="radio"]:disabled + span {
    opacity: 0.5;
    cursor: not-allowed;
}

.export-dropdown.active .export-dropdown-content {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

.export-dropdown-btn {
    background: #334155;
    color: white;
    border: 1px solid #475569;
    padding: 6px 14px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.85em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.export-dropdown-btn:hover {
    background: #475569;
}

/* --- Status Indicators & Badges --- */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.status-active { background-color: #10b981; }
.status-expired { background-color: #94a3b8; }
.status-future { background-color: #3b82f6; }
.status-inactive { background-color: #94a3b8; }

.badge {
    display: inline-block;
    background: #e0e7ff;
    color: #3730a3;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: bold;
}

/* --- Common UI States --- */
.changed-highlight {
    background-color: #e0f2fe !important;
    transition: background-color 0.5s ease;
}

.locked-mode {
    pointer-events: none;
    opacity: 0.6;
}

.error-banner,
.error-box {
    background: #fee2e2;
    border: 1px solid #ef4444;
    color: #b91c1c;
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 4px;
    display: none;
}

/* --- Track Mode Styles --- */
body.track-mode-active {
    background-color: #f0fdf4 !important;
}

.track-mode-active .hide-on-track {
    display: none !important;
}

.track-mode-toggle-btn {
    width: 100%;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 0.95em;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
    background: #2563eb !important;
    color: #ffffff !important;
    border: 1px solid #1d4ed8 !important;
}

.track-mode-toggle-btn:hover {
    background: #1d4ed8 !important;
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
    transform: translateY(-1px);
}

.track-mode-active .track-mode-toggle-btn {
    background: #059669 !important;
    color: #ffffff !important;
    border-color: #047857 !important;
    box-shadow: 0 2px 4px rgba(5, 150, 105, 0.25);
}

.track-mode-active .track-mode-toggle-btn:hover {
    background: #047857 !important;
    box-shadow: 0 4px 8px rgba(5, 150, 105, 0.35);
    transform: translateY(-1px);
}

.track-mode-toggle-btn:disabled,
.track-mode-toggle-btn.locked,
.track-mode-toggle-btn[disabled] {
    background: #94a3b8 !important;
    border-color: #64748b !important;
    color: #f1f5f9 !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    transform: none !important;
    opacity: 0.7;
}

.track-mode-toggle-btn:disabled:hover,
.track-mode-toggle-btn.locked:hover,
.track-mode-toggle-btn[disabled]:hover {
    background: #94a3b8 !important;
    border-color: #64748b !important;
    transform: none !important;
    box-shadow: none !important;
}

.track-mode-only-ui {
    display: none !important;
}

.track-mode-active .track-mode-only-ui {
    display: block !important;
}

.actual-input {
    color: #14532d !important;
    font-weight: bold !important;
    background-color: #ffffff !important;
    border: 1px solid #86efac !important;
}

.actual-input:focus {
    background-color: #ffffff !important;
    border-color: #10b981 !important;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2) !important;
}

.prescription-label {
    color: #6b7280;
    font-style: italic;
    font-size: 0.85em;
    display: block;
    margin-top: 2px;
}

.has-data-highlight {
    background-color: #dcfce7 !important;
    border-color: #86efac !important;
}

/* Locked non-performance fields in Track Mode */
.track-mode-active #appContainer input:not(.actual-input),
.track-mode-active #appContainer textarea:not(.actual-input),
.track-mode-active #appContainer select {
    background-color: #f1f5f9 !important;
    color: #64748b !important;
    cursor: not-allowed !important;
    border-color: #e2e8f0 !important;
    box-shadow: none !important;
    user-select: none;
}

.track-mode-active #appContainer .day-header input {
    background: rgba(255, 255, 255, 0.12) !important;
    color: rgba(255, 255, 255, 0.85) !important;
    cursor: not-allowed !important;
}

/* Prevent Drag & Drop in Track Mode */
.track-mode-active .draggable-row {
    cursor: default !important;
    user-select: text;
}

.track-mode-active .draggable-row:hover {
    cursor: default !important;
}

/* Markdown Tables (used in AI output / Magic Box feedback displays) */
.markdown-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.markdown-table {
    width: 100%;
    border-collapse: collapse !important;
    font-size: 0.85em;
    background: #ffffff;
    margin: 0;
}

.markdown-table th,
.markdown-table td {
    padding: 6px 10px !important;
    border: 1px solid #e2e8f0 !important;
    white-space: nowrap;
}

.markdown-table th {
    background: #f1f5f9 !important;
    position: static !important;
    box-shadow: none !important;
    font-weight: 600;
    color: #334155 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
}

.markdown-table tr:nth-child(even) td {
    background-color: #f8fafc;
}

.markdown-table tr:hover td {
    background-color: #f1f5f9;
}

/* --- Tab System --- */
.summary-tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 25px;
    border-bottom: 2px solid #e4e4e7;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.summary-tab-nav::-webkit-scrollbar {
    display: none;
}

.summary-tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 600;
    color: #71717a;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: -2px;
    border-radius: 4px 4px 0 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.summary-tab-btn:hover {
    color: #18181b;
    background: #e4e4e7;
}

.summary-tab-btn.active {
    color: #18181b;
    border-bottom-color: #18181b;
    background: #ffffff;
    font-weight: 700;
}

.summary-tab-pane {
    display: none;
}

.summary-tab-pane.active {
    display: block;
}

@media (prefers-reduced-motion: no-preference) {
    .summary-tab-pane.active,
    .settings-pane {
        animation: tabPaneFadeIn 130ms ease-out;
    }
}

@keyframes tabPaneFadeIn {
    from {
        opacity: 0;
        transform: translateY(3px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Analytics Dashboard Styles */
.analytics-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 22px; }
.analytics-dual-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; margin-bottom: 24px; align-items: start; }
@media (max-width: 640px) {
    .analytics-dual-grid { grid-template-columns: 1fr; }
}
.analytics-kpi-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.analytics-kpi-label { font-size: 0.78em; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #64748b; margin-bottom: 6px; }
.analytics-kpi-val { font-size: 1.85rem; font-weight: 800; line-height: 1.1; margin-bottom: 4px; color: #0f172a; }
.analytics-kpi-sub { font-size: 0.82em; color: #64748b; }

.analytics-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); margin-bottom: 22px; }
.analytics-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.analytics-card-title { font-size: 1.05rem; font-weight: 700; color: #0f172a; margin: 0; display: flex; align-items: center; gap: 8px; }
.analytics-card-subtitle { font-size: 0.82em; color: #64748b; }

.analytics-prog-bar-container { background: #f1f5f9; border-radius: 6px; height: 10px; overflow: hidden; width: 100%; border: 1px solid #e2e8f0; }
.analytics-prog-bar-fill { height: 100%; border-radius: 6px; transition: width 0.4s ease; }

.analytics-tag { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 4px; font-size: 0.8em; font-weight: 600; text-decoration: none; }
.analytics-tag-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.analytics-tag-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.analytics-tag-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.analytics-tag-neutral { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.analytics-tag-primary { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.chart-inspect-banner { background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; font-size: 0.85em; color: #334155; display: flex; justify-content: space-between; align-items: center; min-height: 20px; }
.chart-point:hover { r: 8px; cursor: pointer; }

/* Collapsible Analytics Cards */
details.analytics-card.analytics-collapsible-card {
    transition: all 0.2s ease;
}
details.analytics-card.analytics-collapsible-card summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    list-style: none;
    user-select: none;
    outline: none;
}
details.analytics-card.analytics-collapsible-card summary::-webkit-details-marker {
    display: none;
}
details.analytics-card.analytics-collapsible-card summary::after {
    content: '▾';
    font-size: 1.2em;
    font-weight: 700;
    color: #64748b;
    margin-left: 12px;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
details.analytics-card.analytics-collapsible-card:not([open]) summary {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}
details.analytics-card.analytics-collapsible-card:not([open]) summary::after {
    transform: rotate(-90deg);
}
.analytics-card-body {
    margin-top: 14px;
}

/* Modal Dialog Styles */
@media (prefers-reduced-motion: no-preference) {
    .modal-overlay {
        animation: modalOverlayFade 150ms ease-out;
    }
    .modal-dialog,
    .login-card,
    .locked-card {
        animation: modalDialogPop 160ms cubic-bezier(0.16, 1, 0.3, 1);
    }
}

@keyframes modalOverlayFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalDialogPop {
    from {
        opacity: 0;
        transform: scale(0.97) translateY(4px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    box-sizing: border-box;
}

.modal-dialog {
    background: #ffffff;
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border: 1px solid #cbd5e1;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

.snippet-card {
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: all 0.15s ease;
}

.snippet-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.1);
}

/* --- AI & OCR Verification Disclaimers --- */
.ai-disclaimer-caption {
    font-size: 0.74rem;
    color: #64748b;
    line-height: 1.35;
    margin-top: 8px;
    margin-bottom: 0;
}

/* --- AI Loading Spinner & Indicators --- */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #93c5fd;
    border-top-color: #1e40af;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.ai-loading-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: #1e40af;
    padding: 4px 0;
}

/* --- Intensity View Toggle Buttons --- */
.intensity-view-toggle {
    padding: 4px 10px;
    border: none;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    color: #475569;
    transition: all 0.15s ease;
}

.intensity-view-toggle.active {
    background: #10b981;
    color: #ffffff;
    font-weight: 700;
}

/* --- Mobile Responsive Optimizations --- */
@media (max-width: 768px) {
    .export-dropdown-content {
        position: fixed !important;
        top: calc(var(--sticky-nav-offset, 76px) + 4px);
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) translateY(-5px);
        width: min(360px, calc(100vw - 20px)) !important;
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100vh - 90px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4) !important;
        border-radius: 12px !important;
        z-index: 2500 !important;
    }

    .export-dropdown.active .export-dropdown-content {
        transform: translateX(-50%) translateY(0);
    }

    #bulkConfigPopover {
        position: fixed !important;
        bottom: 84px !important;
        top: auto !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        width: min(360px, calc(100vw - 20px)) !important;
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100vh - 110px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4) !important;
        border-radius: 12px !important;
        z-index: 2500 !important;
    }

    .top-nav {
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        gap: 6px !important;
        padding: 7px 10px !important;
        min-height: auto !important;
    }

    /* ROW 1: Coach Brand / Dashboard Link */
    .top-nav .coach-nav-brand {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        width: 100% !important;
        flex: none !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
        min-width: 0 !important;
        overflow: visible !important;
    }

    .top-nav .coach-nav-brand a.back-link:not(.animate-from-dashboard) {
        flex-shrink: 0 !important;
        height: 28px !important;
        min-height: 28px !important;
        padding: 2px 8px !important;
        font-size: 0.78rem !important;
    }

    .top-nav .coach-nav-brand .nav-brand-title {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: 0.88rem !important;
        min-width: 0 !important;
    }

    .top-nav .coach-nav-brand .nav-brand-sep {
        flex-shrink: 0 !important;
    }

    /* ROW 1: Coach Brand - Layout when Back Link is present (Dashboard Left, Brand + Workspace Switcher Center, Page Title Right) */
    .top-nav .coach-nav-brand.has-back-link {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        flex: none !important;
        gap: 6px !important;
        flex-wrap: nowrap !important;
        min-width: 0 !important;
        overflow: visible !important;
        height: 32px !important;
    }

    .top-nav .coach-nav-brand.has-back-link .coach-brand-left {
        flex: 0 0 auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .top-nav .coach-nav-brand.has-back-link a.back-link:not(.animate-from-dashboard) {
        flex-shrink: 0 !important;
        height: 30px !important;
        min-height: 30px !important;
        padding: 2px 8px !important;
        font-size: 0.78rem !important;
        white-space: nowrap !important;
        line-height: 1 !important;
    }

    .top-nav .coach-nav-brand.has-back-link .coach-brand-center {
        flex: 0 0 auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        padding: 0 2px !important;
    }

    .top-nav .coach-nav-brand.has-back-link .nav-brand-name {
        font-weight: 800 !important;
        font-size: clamp(0.95rem, 3.2vw, 1.15rem) !important;
        white-space: nowrap !important;
        color: #ffffff !important;
        letter-spacing: 0.5px !important;
        flex-shrink: 0 !important;
    }

    .top-nav .coach-nav-brand.has-back-link .coach-tenant-switchers {
        display: inline-flex !important;
        align-items: center !important;
        flex: 0 1 auto !important;
        min-width: 0 !important;
    }

    .top-nav .coach-nav-brand.has-back-link .coach-tenant-switchers .nav-workspace-sep {
        display: none !important;
    }

    .top-nav .coach-nav-brand.has-back-link .coach-tenant-switchers .nav-workspace-pill {
        height: 28px !important;
        padding: 2px 7px !important;
        font-size: 0.74rem !important;
        gap: 5px !important;
        min-width: 0 !important;
    }

    .top-nav .coach-nav-brand.has-back-link .coach-brand-right {
        flex: 1 1 0px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .top-nav .coach-nav-brand.has-back-link .nav-brand-title {
        text-align: right !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: clamp(0.76rem, 2.6vw, 0.88rem) !important;
        font-weight: 600 !important;
        color: #e2e8f0 !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .top-nav .coach-nav-brand.has-back-link .nav-brand-sep,
    .top-nav .coach-nav-brand.has-back-link .coach-brand-sep,
    .top-nav .coach-nav-brand.has-back-link .nav-readonly-badge {
        display: none !important;
    }

    .top-nav .coach-nav-brand:not(.has-back-link):has(.coach-tenant-switchers) .nav-subtitle {
        display: none !important;
    }

    /* ROW 2: Coach Action Buttons */
    .top-nav .coach-nav-actions {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: flex-start !important;
        width: 100% !important;
        flex: none !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
        margin: 0 !important;
        padding: 0 0 2px 0 !important;
        box-sizing: border-box !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }

    .top-nav .coach-nav-actions::-webkit-scrollbar {
        display: none !important;
    }

    .top-nav .coach-nav-actions .btn,
    .top-nav .coach-nav-actions .btn-primary,
    .top-nav .coach-nav-actions .btn-ghost,
    .top-nav .coach-nav-actions .btn-outline,
    .top-nav .coach-nav-actions button:not(.split-btn-dropdown),
    .top-nav .coach-nav-actions a:not(.split-btn-dropdown) {
        height: 32px !important;
        min-height: 32px !important;
        padding: 4px 10px !important;
        font-size: clamp(0.72rem, 2.6vw, 0.82rem) !important;
        font-weight: 600 !important;
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        line-height: 1 !important;
    }

    .top-nav .coach-nav-actions .split-btn-group {
        height: 32px !important;
        min-height: 32px !important;
        display: inline-flex !important;
        align-items: stretch !important;
        flex-shrink: 0 !important;
    }

    .top-nav .coach-nav-actions .split-btn-main {
        width: auto !important;
        height: 32px !important;
        min-height: 32px !important;
        font-size: clamp(0.72rem, 2.6vw, 0.82rem) !important;
        padding: 4px 10px !important;
    }

    .top-nav .coach-nav-actions .split-btn-dropdown {
        height: 32px !important;
        min-height: 32px !important;
        padding: 4px 8px !important;
        font-size: 0.75rem !important;
    }

    .top-nav .coach-nav-actions .export-dropdown {
        flex-shrink: 0 !important;
    }

    .top-nav .coach-nav-actions .export-dropdown-btn {
        height: 32px !important;
        min-height: 32px !important;
        font-size: clamp(0.72rem, 2.6vw, 0.82rem) !important;
        padding: 4px 10px !important;
    }

    .top-nav .coach-nav-actions .save-dropdown {
        flex-shrink: 0 !important;
        margin-left: 0 !important;
    }

    .save-dropdown-content {
        position: fixed !important;
        margin-top: 0 !important;
        min-width: 180px !important;
        max-width: calc(100vw - 20px) !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35) !important;
        border-radius: 8px !important;
        border: 1px solid #cbd5e1 !important;
        padding: 6px !important;
        background-color: #ffffff !important;
        z-index: 2500 !important;
    }

    .top-nav .coach-nav-actions #saveStatus,
    .top-nav .coach-nav-actions #settingsNavStatus,
    .top-nav .coach-nav-actions #cleanNavStatus,
    .top-nav .coach-nav-actions #logNavStatus {
        width: auto !important;
        max-width: 120px !important;
        font-size: 0.72rem !important;
        margin-right: 4px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        flex-shrink: 0 !important;
    }

    .top-nav .coach-nav-actions #saveStatus:empty,
    .top-nav .coach-nav-actions #settingsNavStatus:empty,
    .top-nav .coach-nav-actions #cleanNavStatus:empty,
    .top-nav .coach-nav-actions #logNavStatus:empty {
        display: none !important;
    }

    .dashboard-nav-actions {
        justify-content: flex-start !important;
        width: 100% !important;
    }

    .nav-btn-desktop {
        display: none !important;
    }
    .nav-btn-mobile {
        display: inline !important;
    }

    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

.nav-btn-mobile {
    display: none;
}
.nav-btn-desktop {
    display: inline;
}

@media (max-width: 640px) {
    .dashboard-nav-actions {
        justify-content: flex-start;
        width: 100%;
    }
    .nav-btn-full {
        display: none;
    }
    .nav-btn-desktop {
        display: none;
    }
    .nav-btn-mobile {
        display: inline;
    }
    .top-nav .coach-nav-brand.has-back-link:has(.coach-tenant-switchers) .coach-brand-center .nav-brand-name span {
        display: none !important;
    }
    .top-nav .coach-nav-brand.has-back-link .coach-tenant-switchers .nav-workspace-pill:has(.nav-workspace-suborg-name) .nav-single-org-name,
    .top-nav .coach-nav-brand.has-back-link .coach-tenant-switchers .nav-workspace-pill:has(.nav-workspace-suborg-name) .nav-workspace-chevron {
        display: none !important;
    }
}

@media (max-width: 420px) {
    .nav-subtitle {
        display: none !important;
    }
    .top-nav .coach-nav-brand .nav-brand-sep {
        display: none !important;
    }
}

/* ==========================================================================
   Public Portal Navbar Responsive 2-Row Maximum Auto-Adjusting Layout
   Ensures the nav bar is never more than two rows on workout & upload pages.
   ========================================================================== */

.top-nav.public-portal-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    box-sizing: border-box;
    min-height: 56px;
}

.top-nav.public-portal-nav #navProgramSwitcherMenu {
    right: 0 !important;
    left: auto !important;
    max-width: calc(100vw - 24px) !important;
}

.top-nav.public-portal-nav .public-nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
}

.top-nav.public-portal-nav .public-nav-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    white-space: nowrap;
}

.top-nav.public-portal-nav .public-nav-switcher-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.top-nav.public-portal-nav .public-nav-status:empty {
    display: none !important;
}

.top-nav.public-portal-nav .public-nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.top-nav.public-portal-nav .public-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    text-decoration: none;
    box-sizing: border-box;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

/* Tablet & Mobile: Strictly Enforce 2 Rows (Row 1: Brand & Switcher, Row 2: Action Buttons) */
@media (max-width: 768px) {
    .top-nav.public-portal-nav {
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        gap: 6px !important;
        padding: 7px 10px !important;
        min-height: auto !important;
    }

    /* ROW 1: Brand & Switcher */
    .top-nav.public-portal-nav .public-nav-brand {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        flex: none !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
    }

    .top-nav.public-portal-nav .public-nav-title-group {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow: hidden !important;
        white-space: nowrap !important;
    }

    .top-nav.public-portal-nav .nav-brand-title {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: 0.88rem !important;
    }

    .top-nav.public-portal-nav .public-nav-switcher-group {
        flex-shrink: 0 !important;
    }

    .top-nav.public-portal-nav .public-nav-status {
        display: none !important;
    }

    /* ROW 2: Auto-Adjusting Action Buttons */
    .top-nav.public-portal-nav .public-nav-actions {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        flex: none !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    .top-nav.public-portal-nav .public-nav-actions .public-nav-btn {
        flex: 1 1 0px !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 5px 4px !important;
        font-size: clamp(0.7rem, 2.7vw, 0.82rem) !important;
        font-weight: 700 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        letter-spacing: -0.2px !important;
        line-height: 1.25 !important;
        gap: 3px !important;
    }

    .top-nav.public-portal-nav .public-nav-actions .public-nav-btn span {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
}

/* Mobile Page Title Collapse (<= 540px) so Co-Branded Logos + Program Switcher fit on Row 1 */
@media (max-width: 540px) {
    .top-nav.public-portal-nav .nav-brand-title,
    .top-nav.public-portal-nav .nav-brand-sep {
        display: none !important;
    }
}

/* Compact Mobile (<= 400px) */
@media (max-width: 400px) {
    .top-nav.public-portal-nav {
        padding: 5px 6px !important;
        gap: 4px !important;
    }

    .top-nav.public-portal-nav .public-nav-actions {
        gap: 4px !important;
    }

    .top-nav.public-portal-nav .public-nav-actions .public-nav-btn {
        padding: 4px 2px !important;
        font-size: clamp(0.66rem, 2.8vw, 0.76rem) !important;
        letter-spacing: -0.3px !important;
    }
}

/* Small Screens (<= 340px) */
@media (max-width: 340px) {
    .top-nav.public-portal-nav .nav-brand-title,
    .top-nav.public-portal-nav .nav-brand-sep {
        display: none !important;
    }

    .top-nav.public-portal-nav .public-nav-actions .public-nav-btn {
        padding: 3px 1px !important;
        font-size: 0.65rem !important;
    }
}

/* --- Progress Report Inline Widget Placeholders --- */
.report-widget-placeholder {
    background: #f4f4f5;
    border: 1.5px dashed #cbd5e1;
    border-radius: 8px;
    padding: 14px 18px;
    margin: 16px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #475569;
    font-size: 0.9rem;
    user-select: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.report-widget-placeholder .widget-icon {
    font-size: 1.15rem;
    line-height: 1;
}
.report-widget-placeholder .widget-name {
    color: #0f172a;
    font-weight: 700;
}
.report-widget-placeholder .widget-note {
    color: #64748b;
    font-style: italic;
    font-size: 0.85rem;
}


