/* ============================================
   Powmetrix Professional UI
   Design System v2.0
   ============================================ */

/* ========== 1. Design Tokens ========== */
:root {
    /* Color Palette */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;

    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warning: #ea580c;
    --muted-color: #5f6b76;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
}

/* ========== 2. Pico CSS Overrides ========== */
:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size: 0.9375rem;
    --line-height: 1.6;
    --border-radius: var(--radius-md);
}

body {
    background: var(--gray-50);
    font-size: var(--font-size);
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Inter', sans-serif;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

h2 {
    font-size: 1.375rem;
    font-weight: 600;
    line-height: 1.3;
}

h3 {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.4;
}

small {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

/* ========== 3. Navigation ========== */
.site-nav {
    background: var(--gray-900);
    padding: 0.75rem 1rem;
    margin-bottom: 0;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-nav ul {
    margin: 0;
}

.site-nav .brand {
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    color: var(--gray-300);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    position: relative;
}

.nav-link:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
    color: white;
    background: rgba(37, 99, 235, 0.2);
    border-bottom: 2px solid var(--primary);
}

.nav-auth {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.nav-org {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.org-name {
    color: var(--gray-300);
    font-size: 0.875rem;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.role-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

.role-badge.role-admin   { background: #7c3aed; color: white; }
.role-badge.role-analyst { background: var(--primary); color: white; }
.role-badge.role-viewer  { background: var(--gray-500); color: white; }

.nav-logout {
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    background: transparent;
    border: 1px solid var(--gray-500);
    color: var(--gray-300);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}

.nav-logout:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--gray-300);
    color: white;
}

/* ========== 4. Page Title ========== */
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0 0 var(--spacing-lg) 0;
    padding: 0;
    line-height: 1.3;
}

.page-hint {
    color: var(--gray-600);
    font-size: 0.9rem;
    margin: calc(-1 * var(--spacing-sm)) 0 var(--spacing-lg) 0;
}

/* ========== 5. Layout Components ========== */
.panel {
    background: white;
    padding: var(--spacing-xl);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-lg);
    margin-top: var(--spacing-lg);
}

.blends-layout {
    display: flex;
    gap: var(--spacing-xl);
    align-items: flex-start;
}

.blends-layout .panel {
    flex: 0 0 360px;
    position: sticky;
    top: calc(60px + var(--spacing-lg));
}

.blends-layout > div:last-child {
    flex: 1;
    min-width: 0;
}

/* Blend Page Tabs */
.blend-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: var(--spacing-xl);
}

.blend-tab {
    flex: 1;
    padding: 0.875rem 1.25rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--gray-600);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    text-align: center;
    margin-bottom: -2px;
    border-radius: 0;
}

.blend-tab:hover {
    color: var(--gray-800);
    background: var(--gray-50);
    transform: none;
}

.blend-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

.blend-tab-panel {
    display: none;
}

.blend-tab-panel.active {
    display: block;
}

/* Material rows */
.composition-row {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.composition-row select {
    flex: 3;
    margin-bottom: 0;
}

.composition-row input[type="number"] {
    flex: 1;
    max-width: 90px;
    margin-bottom: 0;
}

.composition-row .btn-danger-sm {
    flex: 0 0 auto;
    width: auto;       /* Override Pico CSS global button { width: 100% } */
    min-width: 2rem;
    padding: 0.375rem 0.5rem;
}

/* Inverse formulation row labels */
.inverse-row-label {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 3rem;
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.875rem;
}

.form-hint {
    color: var(--gray-600);
    font-size: 0.875rem;
    margin-bottom: var(--spacing-md);
}

/* Sum indicator */
.composition-sum {
    padding: var(--spacing-sm) 0;
    font-weight: 600;
}

.comp-sum-ok {
    color: var(--success);
}

.comp-sum-bad {
    color: var(--danger);
}

/* Composition chips (in result fragment) */
.composition-summary {
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    border-left: 4px solid var(--primary);
    background: var(--gray-50);
    border-radius: var(--radius-sm);
}

.composition-summary h4 {
    margin: 0 0 var(--spacing-xs) 0;
    font-size: 0.75rem;
    color: var(--gray-600);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.composition-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.composition-chip {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 12px;
    font-size: 0.8125rem;
    background: white;
    color: var(--gray-700);
}

/* Composition metrics display */
.composition-metrics {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--gray-200);
}

.metric-row:last-child {
    border-bottom: none;
}

.metric-label {
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.9375rem;
}

.metric-value {
    font-weight: 600;
    color: var(--gray-900);
    font-size: 1rem;
    text-align: right;
}

.form-row {
    display: flex;
    gap: var(--spacing-md);
    align-items: flex-end;
}

.form-row > * {
    flex: 1;
}

.form-row button {
    margin: 0;
}

/* ========== 6. Forms ========== */
form label {
    display: block;
    margin-bottom: var(--spacing-md);
    font-weight: 500;
    color: var(--gray-700);
}

form input[type="text"],
form input[type="number"],
form select {
    width: 100%;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

form input:focus,
form select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

input[type="hidden"] {
    display: none;
}

/* ========== 7. Buttons ========== */
button,
.btn-primary {
    width: auto;           /* Override Pico CSS global button { width: 100% } */
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-size: 0.9375rem;
}

button:hover,
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

button:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

.btn-outline {
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

.btn-danger-sm {
    background: var(--danger);
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.btn-danger-sm:hover {
    background: var(--danger-hover);
}

.secondary {
    background: var(--gray-600);
}

.secondary:hover {
    background: var(--gray-700);
}

.secondary.outline {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.secondary.outline:hover {
    background: var(--gray-100);
}

button.small {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

/* ========== 8. Result Cards ========== */
.result-card {
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

.result-card__header {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.result-card__header h3 {
    margin: 0;
    color: var(--gray-900);
    font-size: 1rem;
    font-weight: 600;
}

.result-card__body {
    padding: var(--spacing-lg);
}

.result-card--wide {
    grid-column: 1 / -1;
}

.gauge-value {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: -20px;
}

.confidence-display {
    text-align: center;
    padding: 2rem;
}

.confidence-display__icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.confidence-display__risk {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0.5rem 0;
}

.confidence-display__percent {
    font-size: 1.25rem;
    color: var(--primary);
    margin: 0.5rem 0;
}

.confidence-display__percent strong {
    font-weight: 700;
}

/* ========== 9. Material Summary ========== */
.material-summary {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.material-summary h4 {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--gray-700);
    font-size: 0.9375rem;
    font-weight: 600;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--spacing-md);
}

.summary-item {
    text-align: center;
}

.summary-item__label {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.summary-item__value {
    display: block;
    font-size: 1rem;
    color: var(--gray-900);
    font-weight: 600;
    font-feature-settings: 'tnum';
}

/* ========== 10. Data Tables ========== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table thead {
    background: var(--gray-100);
}

.data-table th {
    text-align: left;
    padding: 0.875rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-300);
}

.data-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-800);
}

.data-table tbody tr:hover {
    background: var(--gray-50);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table td.num,
.data-table th.num {
    text-align: right;
    font-feature-settings: 'tnum';
}

.data-table td strong {
    color: var(--gray-900);
    font-weight: 600;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========== 11. Page Toolbar ========== */
.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-lg);
    gap: var(--spacing-lg);
}

.page-toolbar__title h2 {
    margin: 0;
}

.page-toolbar__title p {
    margin: 0.5rem 0 0 0;
    color: var(--gray-600);
}

.page-toolbar__actions {
    display: flex;
    gap: var(--spacing-sm);
    flex-shrink: 0;
}

/* ========== 12. Material Links and Badges ========== */
.material-link {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-style: dashed;
    text-decoration-thickness: 1px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.material-link:hover {
    color: var(--primary-hover);
    text-decoration-style: solid;
    text-decoration-thickness: 2px;
}

.category-badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    font-size: 0.8125rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.category-very-cohesive {
    background: #fce8e8;
    color: #922b21;
}

.category-cohesive {
    background: #fdebd0;
    color: #7e5109;
}

.category-semi-cohesive {
    background: #fffacd;
    color: #7d5a00;
}

.category-easy-flowing {
    background: #e8f5e9;
    color: #2e7d32;
}

.category-free-flowing {
    background: #e0f7fa;
    color: #006064;
}

.risk-badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    font-size: 0.8125rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.risk-badge--low      { background: #d4edda; color: #155724; }
.risk-badge--moderate { background: #fff3cd; color: #664d03; }
.risk-badge--high     { background: #ffeacc; color: #8a3800; }
.risk-badge--critical { background: #f8d7da; color: #721c24; }

/* ========== 13. Dialog Overrides ========== */
dialog article {
    max-width: 600px;
}

.dialog-wide article {
    max-width: 900px;
    width: 90vw;
}

dialog article header {
    background: white;
    padding: var(--spacing-lg);
    margin: calc(var(--spacing-lg) * -1);
    margin-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--gray-200);
}

dialog article header h3 {
    margin: 0;
    color: var(--gray-900);
}

dialog article {
    background: white;
}

dialog article form {
    background: none;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 0;
}

dialog article footer {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--gray-200);
}

details {
    margin: var(--spacing-md) 0;
}

details summary {
    cursor: pointer;
    font-weight: 600;
    padding: var(--spacing-sm);
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    color: var(--gray-700);
}

details summary:hover {
    background: var(--gray-200);
}

details[open] summary {
    margin-bottom: var(--spacing-md);
}

/* Detail popup layout — 2-column: chart left, metrics right */
.detail-layout {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1rem;
    align-items: start;
}
.detail-layout h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.875rem;
    color: var(--gray-600);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Compact confidence bar */
.detail-confidence {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-top: 0.75rem;
}
.detail-confidence__emoji { font-size: 1.25rem; }
.detail-confidence__text { font-size: 0.875rem; color: var(--gray-700); }

/* Close button icon in dialog header */
.dialog-close-icon {
    background: none;
    border: none;
    color: var(--gray-600);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.375rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}
.dialog-close-icon:hover {
    color: var(--gray-900);
    background: var(--gray-100);
    transform: none;
}

/* ========== 14. Waiting State ========== */
.results-container {
    min-height: 300px;
}

.waiting {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-500);
    background: white;
    border-radius: var(--radius-md);
    border: 2px dashed var(--gray-300);
}

.waiting h3 {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

/* ========== 15. HTMX Loading ========== */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline;
}

.htmx-request.htmx-indicator {
    display: inline;
}

/* ========== 16. Messages ========== */
.error {
    background: #fee;
    border: 1px solid var(--danger);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    color: var(--danger);
}

.success {
    background: #f0fdf4;
    border: 1px solid var(--success);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    color: var(--success);
}

/* ========== 17. Footer ========== */
.site-footer {
    margin-top: 4rem;
    padding-bottom: 2rem;
}

.footer-text {
    text-align: center;
    color: var(--gray-600);
    font-size: 0.875rem;
}

/* ========== 18. Workspace ========== */
.run-type-badge {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--gray-200);
    color: var(--gray-700);
}
.run-type-badge.run-type-single            { background: #dbeafe; color: #1e40af; }
.run-type-badge.run-type-blend_sweep       { background: #ede9fe; color: #5b21b6; }
.run-type-badge.run-type-blend_composition { background: #fce7f3; color: #9d174d; }
.run-type-badge.run-type-inverse           { background: #d1fae5; color: #065f46; }
.run-type-badge.run-type-dry_coating       { background: #ffedd5; color: #9a3412; }

.btn-save {
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.45rem 0;
    background: var(--gray-800);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-save:hover { background: var(--gray-900); }

.save-confirmation {
    font-size: 0.85rem;
    color: var(--success);
    padding: 0.4rem 0;
}

.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--gray-600);
}

/* ========== 19. Org Management Page ========== */
.org-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .org-layout { grid-template-columns: 1fr; }
}

.org-panel {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.invite-form label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    margin-top: 0.75rem;
    color: var(--gray-700);
}

.invite-form input,
.invite-form select {
    width: 100%;
}

.invite-link {
    display: block;
    word-break: break-all;
    background: var(--gray-100);
    padding: 0.4rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    margin: 0.5rem 0;
}

.btn-copy {
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.row-inactive td { opacity: 0.45; }

.you-badge {
    font-size: 0.7rem;
    background: var(--gray-200);
    color: var(--gray-600);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.action-cell { white-space: nowrap; }

.role-select {
    font-size: 0.8rem;
    padding: 0.2rem 0.4rem;
    width: auto;
    display: inline-block;
    margin: 0;
}

.btn-danger-sm {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-left: 0.4rem;
}

.btn-danger-sm:hover { background: var(--danger); color: white; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }

/* ========== 18. Placeholder Page ========== */
.placeholder-content {
    text-align: center;
    padding: 4rem 2rem;
}

.placeholder-content__icon {
    font-size: 5rem;
    opacity: 0.3;
    margin-bottom: 1rem;
}

.placeholder-content h2 {
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

.placeholder-content p {
    color: var(--gray-500);
}

/* ========== 19. Responsive Breakpoints ========== */

/* Tablet (768px - 1023px) */
@media (max-width: 1023px) {
    .results-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .result-card--wide {
        grid-column: 1 / -1;
    }

    .blends-layout {
        flex-direction: column;
    }

    .blends-layout .panel {
        flex: 1;
        width: 100%;
        position: static;
    }

    .blend-tab {
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }

    .summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
    .page-title {
        font-size: 1.25rem;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .detail-layout {
        grid-template-columns: 1fr;
    }

    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }

    .form-row {
        flex-direction: column;
    }

    .blend-tabs {
        flex-direction: column;
        border-bottom: none;
        gap: var(--spacing-xs);
        margin-bottom: var(--spacing-lg);
    }

    .blend-tab {
        border-bottom: none;
        border-left: 3px solid transparent;
        text-align: left;
        background: var(--gray-50);
        border-radius: var(--radius-sm);
        margin-bottom: 0;
    }

    .blend-tab.active {
        border-left-color: var(--primary);
        background: var(--primary-light);
    }

    .page-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .page-toolbar__actions {
        width: 100%;
        flex-direction: column;
    }

    .page-toolbar__actions button {
        width: 100%;
    }

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Small Mobile (< 480px) */
@media (max-width: 479px) {
    .site-nav {
        padding: 0.5rem;
    }

    .panel {
        padding: var(--spacing-md);
    }

    .result-card__body {
        padding: var(--spacing-md);
    }
}

/* ========== Blend Workspace ========== */

.ws-builder {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.ws-panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-600);
    margin: 0 0 0.75rem 0;
}

/* Material Library */
.ws-library {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.ws-chips-scroll {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 420px;
    overflow-y: auto;
}

.ws-chip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.6rem;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    color: var(--gray-700);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.ws-chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.ws-chip-plus {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    opacity: 0.6;
}

/* Blend Canvas */
.ws-canvas {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.ws-canvas-empty {
    text-align: center;
    color: var(--gray-600);
    font-size: 0.9rem;
    padding: 2rem 1rem;
    border: 2px dashed var(--gray-200);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
}

.canvas-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--gray-100);
}

.canvas-mat-name {
    flex: 1;
    font-size: 0.88rem;
    color: var(--gray-800);
    font-weight: 500;
}

.canvas-weight {
    width: 72px;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    text-align: right;
}

.canvas-weight:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.canvas-pct {
    font-size: 0.8125rem;
    color: var(--gray-600);
    width: 14px;
}

.canvas-remove {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.2rem;
    line-height: 1;
    transition: color 0.15s;
}

.canvas-remove:hover { color: var(--danger); }

.ws-canvas-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
}

.canvas-total {
    font-size: 0.88rem;
    font-weight: 600;
}

.canvas-total.valid   { color: var(--success); }
.canvas-total.invalid { color: var(--gray-600); }

/* Workspace Result Card */
.ws-result-card {
    margin-top: 1.25rem;
    padding: 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
}

.ws-result-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.ws-result-metrics {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.ws-ffc {
    font-size: 1.4rem;
    font-weight: 700;
}

.ws-category {
    font-size: 0.9rem;
    font-weight: 600;
}

.ws-risk {
    font-size: 0.88rem;
}

.ws-confidence {
    font-size: 0.8125rem;
    color: var(--gray-600);
}

/* Save row inside result */
.ws-save-row form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.ws-label-input {
    flex: 1;
    min-width: 160px;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
}

.ws-label-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Saved formulations table */
.ws-run-row:hover { background: var(--gray-50); }
.comp-inline { font-size: 0.82rem; color: var(--gray-600); }

@media (max-width: 768px) {
    .ws-builder {
        grid-template-columns: 1fr;
    }
    .ws-chips-scroll {
        max-height: 200px;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .ws-chip {
        width: auto;
        flex: 0 0 auto;
    }
}


/* ========== 20. Landing Page ========== */

.landing-page {
    background: white;
}

/* Landing Nav */
.landing-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--gray-200);
    padding: 0.75rem 0;
}

.landing-nav__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.landing-nav__brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
}

.landing-nav__actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.landing-nav__link {
    color: var(--gray-700);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9375rem;
    transition: color 0.2s;
}

.landing-nav__link:hover {
    color: var(--primary);
}

/* Hero */
.landing-hero {
    padding: 8rem 0 5rem;
    text-align: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
    color: white;
}

.landing-hero .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.landing-hero__title {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1.15;
    margin: 0 0 1.5rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    color: white;
}

.landing-hero__subtitle {
    font-size: 1.25rem;
    opacity: 0.9;
    max-width: 640px;
    margin: 0 auto 2.5rem;
    line-height: 1.6;
}

.landing-hero__cta {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.landing-hero__cta .btn-outline {
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.landing-hero__cta .btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1.0625rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    text-decoration: none;
    display: inline-block;
}

/* Sections */
.landing-section {
    padding: 5rem 0;
}

.landing-section .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.landing-section--alt {
    background: var(--gray-50);
}

.landing-section__title {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 1rem;
    color: var(--gray-900);
}

.landing-section__subtitle {
    text-align: center;
    max-width: 700px;
    margin: 0 auto 3rem;
    color: var(--gray-600);
    font-size: 1.0625rem;
    line-height: 1.7;
}

/* Cards grid */
.landing-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

.landing-cards--2col {
    grid-template-columns: repeat(2, 1fr);
    max-width: 900px;
    margin: 0 auto;
}

.landing-card {
    background: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}

.landing-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.landing-card__icon {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.landing-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
    color: var(--gray-900);
}

.landing-card p {
    color: var(--gray-600);
    font-size: 0.9375rem;
    line-height: 1.6;
    margin: 0;
}

/* Pipeline (Solution section) */
.landing-pipeline {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1rem;
    max-width: 900px;
    margin: 0 auto;
}

.landing-pipeline__step {
    flex: 1;
    text-align: center;
    padding: 2rem 1.5rem;
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
}

.landing-pipeline__number {
    width: 2.5rem;
    height: 2.5rem;
    line-height: 2.5rem;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: 1.125rem;
    margin: 0 auto 1rem;
}

.landing-pipeline__arrow {
    display: flex;
    align-items: center;
    font-size: 1.5rem;
    color: var(--gray-400);
    padding-top: 3rem;
}

.landing-pipeline__step h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
}

.landing-pipeline__step p {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin: 0;
    line-height: 1.5;
}

/* Parity chart container */
.landing-parity-chart {
    max-width: 640px;
    margin: 0 auto;
}

/* Pricing */
.landing-pricing-card {
    max-width: 480px;
    margin: 0 auto;
    text-align: center;
    padding: 2.5rem;
}

.landing-pricing-card h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}

.landing-pricing-card__price {
    font-size: 1.25rem;
    color: var(--gray-600);
    margin: 0 0 1.5rem;
}

.landing-pricing-card__features {
    list-style: none;
    padding: 0;
    margin: 0 0 2rem;
    text-align: left;
}

.landing-pricing-card__features li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-700);
    font-size: 0.9375rem;
}

.landing-pricing-card__features li::before {
    content: "\2713 ";
    color: var(--success);
    font-weight: 700;
    margin-right: 0.5rem;
}

/* CTA */
.landing-cta {
    padding: 5rem 0;
    text-align: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #2563eb 100%);
    color: white;
}

.landing-cta .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.landing-cta h2 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 1rem;
    color: white;
}

.landing-cta p {
    font-size: 1.125rem;
    opacity: 0.9;
    margin: 0 0 2rem;
}

/* Landing Footer */
.landing-footer {
    padding: 2rem 0;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.875rem;
    border-top: 1px solid var(--gray-200);
}

.landing-footer p {
    margin: 0;
}

/* Landing Responsive */
@media (max-width: 1023px) {
    .landing-hero__title {
        font-size: 2.25rem;
    }
    .landing-pipeline {
        flex-direction: column;
        align-items: center;
    }
    .landing-pipeline__arrow {
        transform: rotate(90deg);
        padding-top: 0;
    }
}

@media (max-width: 767px) {
    .landing-hero {
        padding: 6rem 0 3rem;
    }
    .landing-hero__title {
        font-size: 1.75rem;
    }
    .landing-hero__subtitle {
        font-size: 1rem;
    }
    .landing-cards {
        grid-template-columns: 1fr;
    }
    .landing-cards--2col {
        grid-template-columns: 1fr;
    }
    .landing-section {
        padding: 3rem 0;
    }
}


/* ========== Superadmin Dashboard ========== */

.sa-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.sa-stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.sa-stat-card__value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    font-feature-settings: 'tnum';
    line-height: 1.2;
}

.sa-stat-card__label {
    display: block;
    font-size: 0.8125rem;
    color: var(--gray-600);
    font-weight: 500;
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sa-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.nav-link--superadmin {
    color: #fbbf24 !important;
}

.nav-link--superadmin:hover {
    color: #f59e0b !important;
}

.nav-link--superadmin.active {
    background: rgba(251, 191, 36, 0.15);
    border-bottom-color: #fbbf24;
}

@media (max-width: 900px) {
    .sa-two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 767px) {
    .sa-summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 479px) {
    .sa-summary-grid {
        grid-template-columns: 1fr;
    }
}

.sa-org-row:hover {
    background: var(--gray-50, #f9fafb);
}

.sa-org-detail-row td:empty {
    display: none;
}

.sa-org-detail {
    padding: 1.25rem 1.5rem;
    background: var(--gray-50, #f9fafb);
    border-top: 1px solid var(--gray-200);
}

.sa-org-detail__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.sa-org-detail__stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.sa-mini-stat {
    text-align: center;
}

.sa-mini-stat__value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    font-feature-settings: 'tnum';
}

.sa-mini-stat__label {
    display: block;
    font-size: 0.7rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}


/* ========== 14. Project Workspace ========== */

/* Breadcrumb navigation */
.project-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    margin-bottom: 1.25rem;
}
.project-breadcrumb a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.project-breadcrumb a:hover {
    text-decoration: underline;
}
.project-breadcrumb .breadcrumb-sep {
    color: var(--gray-400);
}
.project-breadcrumb .breadcrumb-current {
    color: var(--gray-600);
    font-weight: 500;
}

/* Create panel (toggle form) */
.project-create-panel {
    margin-bottom: 1.5rem;
}
.project-create-form {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.project-create-form label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 0;
}
.project-create-form label:first-of-type {
    flex: 0 0 260px;
}
.project-create-form label:nth-of-type(2) {
    flex: 1;
    min-width: 180px;
}
.project-create-form input[type="text"] {
    width: 100%;
    margin-top: 0.25rem;
}
.project-create-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Project Grid */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
}

/* Project Card */
.project-card {
    display: block;
    padding: 1.25rem;
    padding-left: calc(1.25rem + 4px);
    background: white;
    border: 1px solid var(--gray-200);
    border-left: 4px solid var(--gray-200);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.project-card:hover {
    border-color: var(--primary);
    border-left-color: var(--primary);
    box-shadow: var(--shadow-md);
}
.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}
.project-card-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
    line-height: 1.3;
}
.project-card-desc {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin: 0.5rem 0 0;
    line-height: 1.4;
}
.project-card-meta {
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--gray-500);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}
.project-card-meta .meta-sep {
    margin: 0 0.3rem;
}
.project-card-delete {
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}
.project-card:hover .project-card-delete {
    opacity: 1;
}

/* Project Header (detail page) */
.project-header-card {
    margin-bottom: 0;
}
.project-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.project-name {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    color: var(--gray-900);
}
.project-creator {
    font-size: 0.82rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
    display: block;
}
.project-description {
    font-size: 0.9rem;
    color: var(--gray-700);
    margin: 0.75rem 0 0;
    line-height: 1.5;
    white-space: pre-wrap;
}
.project-desc-empty {
    color: var(--gray-400);
    font-style: italic;
}
.project-edit-form {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.project-name-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.88rem;
}
.project-name-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.project-desc-textarea {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-family: inherit;
    resize: vertical;
}
.project-desc-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.project-edit-actions {
    display: flex;
    gap: 0.5rem;
}

/* Project Sections */
.project-section {
    margin-top: 1.75rem;
}
.project-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-600);
    margin: 0 0 0.75rem 0;
}

/* Project Materials Chips */
.project-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.project-material-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 999px;
    font-size: 0.84rem;
    color: var(--gray-700);
    font-weight: 500;
}
.chip-remove {
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    margin-left: 0.1rem;
}
.chip-remove:hover {
    color: var(--danger);
}
.project-mats-empty {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin: 0;
}
.project-add-material {
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--gray-200);
}
.add-material-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.material-picker {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    min-width: 200px;
}
.material-picker:focus {
    outline: none;
    border-color: var(--primary);
}

/* Run Prediction — reuses .blend-tabs / .blend-tab from Blends page */
/* Override blend-tab to not be equal-width inside project panels */
.project-section .blend-tabs {
    margin-bottom: var(--spacing-lg);
}
.project-section .blend-tab {
    flex: none;
}

.run-form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}
.run-form select,
.run-form input {
    width: auto;
    margin-bottom: 0;
}
.run-material-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    min-width: 240px;
    width: auto;
}
.run-material-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* Override Pico width:100% on selects/inputs inside project forms */
.add-material-form select,
.add-material-form input {
    width: auto;
    margin-bottom: 0;
}

/* Results table tweaks */
.project-results-table {
    border: none;
    box-shadow: none;
}
.project-results-table th,
.project-results-table td {
    padding: 0.625rem 1rem;
}

/* Button helpers */
.btn-sm {
    padding: 0.35rem 0.75rem !important;
    font-size: 0.82rem !important;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .project-grid {
        grid-template-columns: 1fr;
    }
    .project-create-form {
        flex-direction: column;
    }
    .run-form {
        flex-direction: column;
        align-items: stretch;
    }
    .run-material-select {
        min-width: 0;
        width: 100%;
    }
    .add-material-form {
        flex-direction: column;
        align-items: stretch;
    }
    .project-card-delete {
        opacity: 1;
    }
}
