/* ============================================================
   QMS Cloud — Global Stylesheet
   ============================================================ */

:root {
    --navy:       #1565c0;
    --navy-dark:  #0d47a1;
    --navy-light: #1976d2;
    --accent:     #1976d2;
    --success:    #2e7d32;
    --warning:    #e65100;
    --danger:     #c62828;
    --info:       #0277bd;
    --sidebar-w:  260px;
    --topbar-h:   56px;
}

/* ── Reset / Base ── */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: #f0f2f5;
    color: #2d3748;
    min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--navy);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 1000;
    transition: transform .25s ease;
}
.sidebar-brand {
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
}
.sidebar-brand small {
    display: block;
    font-size: 10px;
    font-weight: 400;
    opacity: .7;
    text-transform: uppercase;
    letter-spacing: .8px;
}
.sidebar-company {
    padding: 8px 20px 10px;
    background: rgba(0,0,0,.2);
    color: rgba(255,255,255,.85);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .4px;
}
.sidebar-section {
    padding: 18px 20px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,.45);
}
.sidebar-nav { list-style: none; margin: 0; padding: 0 0 8px; }
.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: rgba(255,255,255,.82);
    font-size: 13.5px;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: rgba(255,255,255,.1);
    color: #fff;
    text-decoration: none;
    border-left-color: #90caf9;
}
.sidebar-nav li a .icon {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: .85;
}
.sidebar-footer {
    margin-top: auto;
    padding: 12px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
    color: rgba(255,255,255,.5);
    font-size: 11px;
}
.clause-tag {
    display: block;
    font-size: 10px;
    opacity: .6;
    margin-top: 1px;
    font-weight: 400;
    letter-spacing: .2px;
}

/* ── Top bar ── */
.topbar {
    position: fixed;
    top: 0; left: var(--sidebar-w); right: 0;
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 2px solid #dde3ea;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    z-index: 900;
}
.topbar-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--navy);
    flex: 1;
}
.topbar-user {
    font-size: 13px;
    color: #555;
}
.topbar-user strong { color: #212121; }

/* ── Main content ── */
.main-content {
    margin-left: var(--sidebar-w);
    padding-top: var(--topbar-h);
    min-height: 100vh;
}
.content-wrap {
    padding: 24px;
}

/* ── Cards ── */
.card {
    background: #fff;
    border: 1px solid #dde3ea;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(21,101,192,.07);
}
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid #dde3ea;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--navy);
    background: #f8fafd;
    border-radius: 8px 8px 0 0;
}
.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid #dde3ea;
    background: #f8fafd;
    border-radius: 0 0 8px 8px;
}

/* ── KPI / Stat cards ── */
.stat-card {
    background: #fff;
    border-radius: 8px;
    border-left: 4px solid var(--navy);
    padding: 18px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.07);
}
.stat-card.green  { border-left-color: var(--success); }
.stat-card.orange { border-left-color: #ef6c00; }
.stat-card.red    { border-left-color: var(--danger); }
.stat-card.blue   { border-left-color: var(--info); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--navy); }
.stat-card .stat-label { font-size: 12px; color: #757575; text-transform: uppercase; letter-spacing: .5px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
.qms-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.qms-table thead th {
    background: var(--navy);
    color: #fff;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}
.qms-table tbody tr:nth-child(even) { background: #f7f9fc; }
.qms-table tbody tr:hover { background: #e3f0fb; }
.qms-table tbody td { padding: 9px 14px; border-bottom: 1px solid #e8ecf1; vertical-align: middle; }
.qms-table tfoot td { padding: 9px 14px; font-weight: 600; background: #f0f2f5; }

/* ── Badges / Status ── */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: capitalize;
}
.badge-open      { background: #e3f2fd; color: #0d47a1; }
.badge-closed    { background: #e8f5e9; color: #1b5e20; }
.badge-pending   { background: #fff8e1; color: #e65100; }
.badge-overdue   { background: #ffebee; color: #b71c1c; }
.badge-draft     { background: #f5f5f5; color: #555; }
.badge-active    { background: #e8f5e9; color: #2e7d32; }
.badge-critical  { background: #ffebee; color: #c62828; }
.badge-major     { background: #fff3e0; color: #bf360c; }
.badge-minor     { background: #e1f5fe; color: #01579b; }
.badge-obs       { background: #f3e5f5; color: #4a148c; }
.badge-plan      { background: #e3f2fd; color: #0d47a1; }
.badge-do        { background: #f3e5f5; color: #6a1b9a; }
.badge-check     { background: #fff8e1; color: #f57f17; }
.badge-act       { background: #e8f5e9; color: #1b5e20; }
.badge-ccp       { background: #ffebee; color: #b71c1c; font-weight: 700; }
.badge-oprp      { background: #fff3e0; color: #e65100; }
.badge-high      { background: #ffebee; color: #c62828; }
.badge-medium    { background: #fff3e0; color: #e65100; }
.badge-low       { background: #e8f5e9; color: #2e7d32; }

/* ── Buttons ── */
.btn-navy {
    background: var(--navy);
    color: #fff;
    border: none;
    padding: 8px 18px;
    border-radius: 5px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.btn-navy:hover { background: var(--navy-light); color: #fff; text-decoration: none; }
.btn-outline-navy {
    background: transparent;
    color: var(--navy);
    border: 1.5px solid var(--navy);
    padding: 7px 16px;
    border-radius: 5px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
}
.btn-outline-navy:hover { background: var(--navy); color: #fff; text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Forms ── */
.form-label { font-weight: 600; font-size: 13px; margin-bottom: 4px; color: #333; }
.form-control, .form-select {
    border: 1.5px solid #c8d0db;
    border-radius: 5px;
    padding: 7px 11px;
    font-size: 13.5px;
    width: 100%;
    transition: border-color .2s, box-shadow .2s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(21,101,192,.14);
    outline: none;
}
.form-section {
    background: #f7f9fc;
    border: 1px solid #dde3ea;
    border-radius: 7px;
    padding: 16px 20px;
    margin-bottom: 20px;
}
.form-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--navy);
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--navy);
}

/* ── PDCA Timeline ── */
.pdca-steps {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 16px 0;
}
.pdca-step {
    background: #fff;
    border-radius: 8px;
    padding: 14px 16px;
    border-top: 4px solid #ccc;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.pdca-step.plan  { border-top-color: #1565c0; }
.pdca-step.do    { border-top-color: #6a1b9a; }
.pdca-step.check { border-top-color: #f57f17; }
.pdca-step.act   { border-top-color: #2e7d32; }
.pdca-step .pdca-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
    margin-bottom: 4px;
}
.pdca-step .pdca-title { font-weight: 600; font-size: 13.5px; color: #212121; }
.pdca-step .pdca-body  { font-size: 12.5px; color: #555; margin-top: 6px; }

/* ── Risk matrix ── */
.risk-matrix { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; max-width: 320px; }
.risk-cell {
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
}
.risk-low    { background: #c8e6c9; color: #1b5e20; }
.risk-medium { background: #fff9c4; color: #827717; }
.risk-high   { background: #ffccbc; color: #bf360c; }
.risk-critical { background: #ffcdd2; color: #b71c1c; }

/* ── Alerts / Flash ── */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13.5px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.alert-success { background: #e8f5e9; color: #1b5e20; border-left: 4px solid #43a047; }
.alert-danger  { background: #ffebee; color: #b71c1c; border-left: 4px solid #e53935; }
.alert-warning { background: #fff8e1; color: #e65100; border-left: 4px solid #fb8c00; }
.alert-info    { background: #e3f2fd; color: #0d47a1; border-left: 4px solid #1e88e5; }

/* ── Tabs (module sub-tabs) ── */
.module-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
}
.module-tab {
    padding: 10px 18px;
    font-size: 13.5px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all .2s;
    text-decoration: none;
}
.module-tab:hover { color: var(--navy); text-decoration: none; }
.module-tab.active { color: var(--navy); border-bottom-color: var(--navy); }

/* ── Attachments ── */
.attachment-list { list-style: none; margin: 0; padding: 0; }
.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 5px;
    background: #f0f4f9;
    margin-bottom: 6px;
    font-size: 13px;
}
.attachment-item a { flex: 1; color: var(--accent); }
.attachment-upload {
    border: 2px dashed #b0bec5;
    border-radius: 7px;
    padding: 24px;
    text-align: center;
    color: #78909c;
    transition: border-color .2s;
    cursor: pointer;
}
.attachment-upload:hover { border-color: var(--navy); color: var(--navy); }

/* ── Pagination ── */
.pagination { display: flex; gap: 4px; align-items: center; }
.page-btn {
    padding: 5px 12px;
    border-radius: 5px;
    border: 1.5px solid #ccc;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    color: #333;
    transition: all .2s;
}
.page-btn:hover, .page-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ── Progress bars ── */
.progress-bar-wrap {
    background: #e0e0e0;
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 10px;
    background: var(--navy);
    transition: width .4s ease;
}
.progress-bar-fill.green  { background: var(--success); }
.progress-bar-fill.orange { background: #ef6c00; }
.progress-bar-fill.red    { background: var(--danger); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar { left: 0; }
    .pdca-steps { grid-template-columns: 1fr 1fr; }
}

/* ── Print ── */
/* ── Printing ──────────────────────────────────────────────────────────────
   Every section prints through these rules, so a page needs no print styles
   of its own. Anything that is on screen only — buttons, filter bars, paging
   — carries .print-hide or is covered below. The .print-only header appears
   on paper and nowhere else.                                                */

.print-only { display: none; }

@media print {
    @page { size: A4; margin: 14mm 11mm 15mm; }

    /* chrome that must not reach the paper */
    .sidebar, .topbar, .print-hide,
    button, .btn, .btn-sm, .btn-navy, .btn-primary, .btn-danger,
    .btn-outline, .btn-outline-navy, .btn-secondary,
    .pagination, .flash, .alert-dismiss, #flash-container,
    form[method="get"], input[type="submit"], .modal-overlay {
        display: none !important;
    }

    html, body {
        background: #fff !important;
        font-size: 10.5pt;
        color: #000;
    }
    .main-content  { margin-left: 0 !important; padding: 0 !important; }
    .content-wrap  { max-width: none !important; padding: 0 !important; margin: 0 !important; }

    .print-only { display: block; }

    .print-header {
        border-bottom: 2px solid #1a3a5c;
        padding-bottom: 6px;
        margin-bottom: 12px;
    }
    .print-header .ph-brand {
        font-size: 15pt; font-weight: 700; color: #1a3a5c; line-height: 1.2;
    }
    .print-header .ph-sub   { font-size: 8.5pt; color: #444; }
    .print-header .ph-title { font-size: 12pt; font-weight: 700; margin-top: 6px; }
    .print-header .ph-meta  { font-size: 8pt; color: #555; margin-top: 2px; }

    /* cards flatten to plain blocks */
    .card {
        box-shadow: none !important;
        border: 1px solid #bbb !important;
        break-inside: avoid; page-break-inside: avoid;
        margin-bottom: 10px !important;
    }
    .card-header {
        background: #eef2f8 !important; color: #1a3a5c !important;
        font-weight: 700; border-bottom: 1px solid #bbb !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    /* tables: header repeats on every page, rows are not split */
    table, .qms-table { width: 100% !important; border-collapse: collapse !important; }
    thead { display: table-header-group; }
    tfoot { display: table-footer-group; }
    tr    { break-inside: avoid; page-break-inside: avoid; }
    .qms-table th, .qms-table td {
        border: 1px solid #999 !important;
        padding: 3px 5px !important;
        font-size: 8.5pt !important;
    }
    .qms-table th {
        background: #1a3a5c !important; color: #fff !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
    .table-wrap { overflow: visible !important; }

    /* keep the colour-coded badges legible in mono as well as colour */
    .badge, [class*="risk-level-"], [class*="opp-level-"] {
        border: 1px solid #666 !important;
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }

    /* stat tiles sit in a row rather than wrapping oddly */
    .stat-card { border: 1px solid #bbb !important; box-shadow: none !important; }

    a { color: #000 !important; text-decoration: none !important; }
    details { display: block !important; }
    details > summary { display: none !important; }   /* print the content, not the toggle */
}
