/* =======================================================================
   KALKULATOR SIX SIGMA CPK & DPMO — PLATINUM ENTERPRISE STYLESHEET
   Industrial QC & Six Sigma DMAIC Theme (Dark Mode Compliant)
   ======================================================================= */

:root {
    --qc-primary: #0284c7;
    --qc-primary-dark: #0369a1;
    --qc-primary-light: #e0f2fe;
    --qc-accent: #0ea5e9;
    --qc-heading: var(--text-primary, #0f172a);
    --qc-text: var(--text-primary, #1e293b);
    --qc-text-muted: var(--text-muted, #64748b);
    --qc-bg-card: var(--bg-card, #ffffff);
    --qc-bg-card-sub: var(--bg-secondary, #f8fafc);
    --qc-border: var(--border-subtle, #e2e8f0);
    --qc-border-focus: #38bdf8;
    --qc-success: #10b981;
    --qc-success-bg: rgba(16, 185, 129, 0.1);
    --qc-warning: #f59e0b;
    --qc-warning-bg: rgba(245, 158, 11, 0.1);
    --qc-danger: #ef4444;
    --qc-danger-bg: rgba(239, 68, 68, 0.1);
    --qc-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --qc-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
    --qc-primary: #38bdf8;
    --qc-primary-dark: #0284c7;
    --qc-primary-light: rgba(56, 189, 248, 0.15);
    --qc-accent: #7dd3fc;
    --qc-heading: #f8fafc;
    --qc-text: #e2e8f0;
    --qc-text-muted: #94a3b8;
    --qc-bg-card: var(--bg-card, #1e293b);
    --qc-bg-card-sub: var(--bg-secondary, #0f172a);
    --qc-border: var(--border-subtle, #334155);
    --qc-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --qc-shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.5);
}

/* ── Container & Hero ── */
.container-tool-page {
    max-width: 1240px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.tool-header-hero {
    position: relative;
    padding: 2.5rem 2rem;
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.08) 0%, rgba(14, 165, 233, 0.03) 100%);
    border: 1px solid var(--qc-border);
    border-radius: 16px;
    margin-bottom: 1.75rem;
    overflow: hidden;
}

.tool-calc-watermark {
    position: absolute;
    top: -15px;
    right: -10px;
    opacity: 0.06;
    pointer-events: none;
    color: var(--qc-heading);
}

.hero-title {
    font-size: 2rem;
    font-weight: 800;
    color: var(--qc-heading);
    letter-spacing: -0.02em;
    margin: 0 0 0.75rem;
    line-height: 1.25;
}

.hero-subtitle {
    font-size: 1rem;
    color: var(--qc-text-muted);
    line-height: 1.6;
    max-width: 820px;
    margin: 0 0 1.25rem;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.trust-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--qc-bg-card);
    color: var(--qc-text);
    border: 1px solid var(--qc-border);
}

.trust-badge--accent {
    background: var(--qc-primary-light);
    color: var(--qc-primary);
    border-color: rgba(2, 132, 199, 0.25);
}

.trust-badge--gold {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
    border-color: rgba(245, 158, 11, 0.3);
}

/* ── 2-Column Desktop Grid (58% / 42%) ── */
.calc-workspace {
    display: grid;
    grid-template-columns: 58% 42%;
    gap: 1.5rem;
    align-items: start;
    margin-top: 1.5rem;
}

@media (max-width: 960px) {
    .calc-workspace {
        grid-template-columns: 1fr;
    }
}

.panel-card {
    background: var(--qc-bg-card);
    border: 1px solid var(--qc-border);
    border-radius: 16px;
    padding: 1.75rem;
    box-shadow: var(--qc-shadow);
}

/* ── Quick Scenario Strip ── */
.preset-strip {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
}

.preset-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--qc-text-muted);
    margin-bottom: 0.6rem;
}

.preset-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.preset-pill {
    background: var(--qc-bg-card);
    border: 1px solid var(--qc-border);
    color: var(--qc-text);
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.preset-pill:hover {
    border-color: var(--qc-primary);
    color: var(--qc-primary);
}

.preset-pill.active {
    background: var(--qc-primary);
    color: #ffffff;
    border-color: var(--qc-primary);
    box-shadow: 0 2px 4px rgba(2, 132, 199, 0.25);
}

/* ── Workspace Bar ── */
.workspace-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--qc-bg-card-sub);
    border: 1px dashed var(--qc-border);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 1.25rem;
    font-size: 0.8rem;
}

.workspace-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--qc-text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--qc-success);
    display: inline-block;
}

.workspace-actions {
    display: flex;
    gap: 0.4rem;
}

.ws-btn {
    background: var(--qc-bg-card);
    border: 1px solid var(--qc-border);
    color: var(--qc-text);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ws-btn:hover {
    background: var(--qc-border);
}

.ws-btn-primary {
    background: var(--qc-primary-light);
    border-color: var(--qc-primary);
    color: var(--qc-primary);
}

/* ── Mode Switcher ── */
.mode-switcher-wrap {
    margin-bottom: 1.5rem;
}

.mode-switcher {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    background: var(--qc-bg-card-sub);
    padding: 0.35rem;
    border-radius: 12px;
    border: 1px solid var(--qc-border);
}

.seg-btn {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-radius: 9px;
    background: transparent;
    border: none;
    color: var(--qc-text-muted);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
}

.seg-btn.active {
    background: var(--qc-bg-card);
    color: var(--qc-heading);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.seg-icon {
    font-size: 1.35rem;
}

.seg-title {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
}

.seg-desc {
    display: block;
    font-size: 0.72rem;
    color: var(--qc-text-muted);
    margin-top: 2px;
}

/* ── Forms & Fields ── */
.section-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.sec-badge {
    background: var(--qc-primary);
    color: #ffffff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
}

.sec-title {
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--qc-heading);
    margin: 0;
}

.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}

.grid-3col {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.75rem;
}

@media (max-width: 600px) {
    .grid-2col, .grid-3col {
        grid-template-columns: 1fr;
    }
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.field-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--qc-heading);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.field-tip {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--qc-text-muted);
}

.form-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--qc-border);
    background: var(--qc-bg-card-sub);
    color: var(--qc-heading);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--qc-primary);
    background: var(--qc-bg-card);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.field-hint {
    font-size: 0.72rem;
    color: var(--qc-text-muted);
    line-height: 1.35;
}

/* ── Collapsible Raw Data Box ── */
.raw-data-details {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
}

.raw-data-summary {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--qc-primary);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.raw-data-box {
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px dashed var(--qc-border);
}

/* ── Right Column: Sticky Results Panel ── */
.tool-sticky-result {
    position: sticky;
    top: 80px;
}

.result-sticky-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--qc-border);
}

.result-live-indicator {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--qc-primary);
    letter-spacing: 0.05em;
}

.live-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--qc-primary);
    animation: livePulseAnim 1.8s infinite;
}

@keyframes livePulseAnim {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(2, 132, 199, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(2, 132, 199, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(2, 132, 199, 0); }
}

.result-timestamp {
    font-size: 0.72rem;
    color: var(--qc-text-muted);
}

/* ── Hero Score Card ── */
.hero-score-card {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.08) 0%, rgba(14, 165, 233, 0.02) 100%);
    border: 1px solid var(--qc-border);
    border-radius: 14px;
    padding: 1.35rem;
    text-align: center;
    margin-bottom: 1.25rem;
}

.hero-score-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--qc-text-muted);
    margin-bottom: 0.35rem;
}

.hero-score-val {
    font-family: var(--font-mono);
    font-size: 2.75rem;
    font-weight: 800;
    color: var(--qc-heading);
    line-height: 1.1;
    margin-bottom: 0.5rem;
}

.hero-score-badge {
    display: inline-block;
    padding: 0.35rem 0.85rem;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 700;
    background: var(--qc-success-bg);
    color: var(--qc-success);
    border: 1px solid rgba(16, 185, 129, 0.3);
    margin-bottom: 0.5rem;
}

.hero-score-desc {
    font-size: 0.8rem;
    color: var(--qc-text-muted);
    line-height: 1.4;
}

/* ── Distribution Chart Card ── */
.curve-chart-card {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 12px;
    padding: 0.85rem;
    margin-bottom: 1.25rem;
}

.curve-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--qc-heading);
    margin-bottom: 0.5rem;
}

/* ── 2x2 Metric Cells ── */
.metrics-2x2-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.metric-cell {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 10px;
    padding: 0.75rem 0.85rem;
}

.metric-cell-label {
    display: block;
    font-size: 0.72rem;
    color: var(--qc-text-muted);
    margin-bottom: 0.25rem;
}

.metric-cell-val {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--qc-heading);
}

.metric-cell-sub {
    display: block;
    font-size: 0.68rem;
    color: var(--qc-text-muted);
    margin-top: 2px;
}

/* ── Audit Table ── */
.audit-details {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 1.25rem;
}

.audit-summary {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--qc-text-muted);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
}

.audit-table {
    width: 100%;
    margin-top: 0.65rem;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.audit-table td {
    padding: 0.4rem 0.2rem;
    border-bottom: 1px solid var(--qc-border);
}

.audit-table td:last-child {
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 600;
}

/* ── 7-in-1 Universal Action Suite ── */
.action-suite {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.btn-primary-lg {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.25rem;
    background: var(--qc-primary);
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);
}

.btn-primary-lg:hover {
    background: var(--qc-primary-dark);
    transform: translateY(-1px);
}

.action-secondary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.btn-sec {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.6rem 0.75rem;
    background: var(--qc-bg-card-sub);
    color: var(--qc-text);
    border: 1px solid var(--qc-border);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-sec:hover {
    background: var(--qc-border);
}

.btn-sec--wa {
    color: #059669;
}

.utility-links-bar {
    display: flex;
    justify-content: space-between;
    margin-top: 0.35rem;
}

.util-link-btn {
    background: transparent;
    border: none;
    color: var(--qc-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0.2rem;
}

.util-link-btn:hover {
    color: var(--qc-primary);
}

/* ── Modals & Overlays ── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.open {
    display: flex;
}

.modal-dialog {
    background: var(--qc-bg-card);
    border: 1px solid var(--qc-border);
    border-radius: 16px;
    width: 100%;
    max-width: 780px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--qc-shadow-lg);
    overflow: hidden;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--qc-border);
}

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.modal-foot {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--qc-border);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ── A4 Sheet Styles ── */
.a4-paper {
    background: #ffffff;
    color: #0f172a;
    padding: 2.25rem 2.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

/* ── Knowledge Tabs & Tables ── */
.knowledge-section {
    margin-top: 2.5rem;
    background: var(--qc-bg-card);
    border: 1px solid var(--qc-border);
    border-radius: 16px;
    padding: 1.5rem;
}

.tabs-header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    border-bottom: 2px solid var(--qc-border);
    padding-bottom: 0.75rem;
    margin-bottom: 1.25rem;
}

.tab-trigger {
    background: transparent;
    border: none;
    color: var(--qc-text-muted);
    font-size: 0.88rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab-trigger.active {
    background: var(--qc-primary-light);
    color: var(--qc-primary);
}

.ref-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.ref-table th, .ref-table td {
    padding: 0.75rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--qc-border);
}

.ref-table th {
    background: var(--qc-bg-card-sub);
    color: var(--qc-heading);
    font-weight: 700;
}

.pill-val {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    background: var(--qc-primary-light);
    color: var(--qc-primary);
    font-weight: 700;
    font-family: var(--font-mono);
}

.formula-cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 768px) {
    .formula-cards-grid { grid-template-columns: 1fr; }
}

.formula-card {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 12px;
    padding: 1.15rem;
}

.formula-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--qc-heading);
    margin: 0 0 0.4rem;
}

.formula-desc {
    font-size: 0.8rem;
    color: var(--qc-text-muted);
    margin: 0 0 0.65rem;
}

.formula-latex {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    background: var(--qc-bg-card);
    border: 1px dashed var(--qc-border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    color: var(--qc-primary);
}

.standards-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.standard-item {
    background: var(--qc-bg-card-sub);
    border: 1px solid var(--qc-border);
    border-radius: 12px;
    padding: 1.15rem;
    display: flex;
    gap: 1rem;
}

.standard-badge {
    background: var(--qc-primary-light);
    color: var(--qc-primary);
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.4rem 0.65rem;
    border-radius: 8px;
    height: fit-content;
    white-space: nowrap;
}

.standard-content p {
    font-size: 0.82rem;
    color: var(--qc-text-muted);
    margin: 0.25rem 0 0;
    line-height: 1.45;
}

/* ── Bottom Meta & Embed ── */
.tool-bottom-rating {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 2rem 0 1rem;
}

.tool-bottom-meta {
    text-align: center;
    font-size: 0.8rem;
    color: var(--qc-text-muted);
    margin: 1rem 0;
}

.tool-bottom-embed {
    display: flex;
    justify-content: center;
    margin-top: 1.5rem;
}

.btn-embed-bottom {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: 9999px;
    border: 1px solid var(--qc-border);
    background: var(--qc-bg-card);
    color: var(--qc-text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-embed-bottom:hover {
    border-color: var(--qc-primary);
    color: var(--qc-primary);
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100000;
}

.dwik-toast {
    background: #0f172a;
    color: #f8fafc;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastSlideUp 0.3s ease;
}

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