/* =========================================================
   Christ the King Registry — Stylesheet
   Mobile-friendly version
   ========================================================= */

:root {
    --ck-navy: #0f2a4a;
    --ck-navy-2: #1a4179;
    --ck-gold: #c9a227;
    --ck-bg: #f4f6f9;
    --ck-border: #e2e8f0;
    --ck-muted: #64748b;
    --ck-sidebar-w: 250px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--ck-bg);
    color: #1e293b;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.ck-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--ck-sidebar-w);
    background: var(--ck-navy);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 1040;
    transition: transform .25s ease;
}

.ck-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: #fff;
    flex-shrink: 0;
}
.ck-brand-badge {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    background: var(--ck-gold);
    color: var(--ck-navy);
    border-radius: 50%;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}
.ck-brand strong { display: block; font-size: .9rem; line-height: 1.2; }
.ck-brand small { font-size: .72rem; color: #94a3b8; line-height: 1.2; }

.ck-nav { flex: 1; padding: .5rem 0; }
.ck-nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .7rem 1rem;
    color: #cbd5e1;
    text-decoration: none;
    font-size: .9rem;
    margin: 2px .5rem;
    border-radius: .4rem;
    transition: background .15s, color .15s;
}
.ck-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.ck-nav a.active { background: var(--ck-navy-2); color: #fff; font-weight: 500; }
.ck-nav a i { width: 20px; text-align: center; flex-shrink: 0; }
.ck-nav a .badge { margin-left: auto; }

.ck-nav-sep {
    border-top: 1px solid rgba(255,255,255,.08);
    margin: .75rem .5rem;
}

.ck-user {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.ck-user-name { color: #fff; font-weight: 500; font-size: .9rem; }
.ck-user-role { font-size: .75rem; color: #94a3b8; }

/* =========================================================
   MAIN LAYOUT
   ========================================================= */
.ck-main {
    margin-left: var(--ck-sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left .25s ease;
}

.ck-topbar {
    background: #fff;
    padding: .85rem 1.25rem;
    border-bottom: 1px solid var(--ck-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.ck-topbar h1 {
    font-size: 1.1rem;
    margin: 0;
    font-weight: 600;
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ck-burger {
    background: none;
    border: 0;
    font-size: 1.5rem;
    padding: 0;
    cursor: pointer;
    color: var(--ck-navy);
    line-height: 1;
    display: none;
}
.ck-content { padding: 1.25rem; flex: 1; }

/* =========================================================
   CARDS, STATS
   ========================================================= */
.card {
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    border-radius: .65rem;
}

.stat-card {
    background: #fff;
    padding: 1rem 1.15rem;
    border-radius: .65rem;
    border-left: 4px solid var(--ck-navy);
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.stat-card.gold  { border-left-color: var(--ck-gold); }
.stat-card.green { border-left-color: #10b981; }
.stat-card.red   { border-left-color: #ef4444; }
.stat-card .lbl { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ck-muted); }
.stat-card .val { font-size: 1.5rem; font-weight: 700; color: var(--ck-navy); margin-top: .15rem; line-height: 1.1; }

/* =========================================================
   TABLES
   ========================================================= */
.table { margin-bottom: 0; }
.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ck-muted);
    border-bottom: 2px solid var(--ck-border);
    white-space: nowrap;
    padding: .75rem .65rem;
}
.table td {
    vertical-align: middle;
    padding: .75rem .65rem;
    border-color: #f1f5f9;
}
.clickable-row { cursor: pointer; transition: background .1s; }
.clickable-row:hover { background: #f8fafc; }
.file-ico { font-size: 1.15rem; margin-right: .4rem; }
.fname { font-weight: 500; word-break: break-word; }
.tag {
    background: #eef2ff;
    color: #4338ca;
    padding: .15rem .5rem;
    border-radius: .3rem;
    font-size: .72rem;
    white-space: nowrap;
}

.btn-group-sm > .btn { padding: .25rem .5rem; font-size: .8rem; }

/* Inline form inside a .btn-group */
.form-in-group { display: contents; }

/* =========================================================
   EMPTY STATES
   ========================================================= */
.empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--ck-muted);
}
.empty i { font-size: 2.5rem; opacity: .35; display: block; margin-bottom: .5rem; }
.empty.big { padding: 3rem 1rem; }
.empty.big i { font-size: 3.5rem; }

/* =========================================================
   DROPZONE
   ========================================================= */
.dropzone {
    border: 2px dashed #cbd5e1;
    background: #fff;
    border-radius: .75rem;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all .15s;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--ck-navy-2);
    background: #eef4ff;
}
.dropzone i.bi-cloud-arrow-up {
    font-size: 2.5rem;
    color: var(--ck-navy);
    display: block;
    margin-bottom: .5rem;
}
.dz-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
    text-align: left;
}
.dz-list li {
    background: #f8fafc;
    padding: .35rem .65rem;
    border-radius: .35rem;
    margin-top: .25rem;
    font-size: .85rem;
    word-break: break-all;
}

/* =========================================================
   PREVIEW MODAL
   ========================================================= */
.pv-body {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1rem;
}
.pv-preview {
    background: #0f172a;
    color: #94a3b8;
    border-radius: .5rem;
    overflow: auto;
    display: grid;
    place-items: center;
    padding: 1rem;
    min-height: 60vh;
}
.pv-preview iframe { width: 100%; height: 70vh; border: 0; background: #fff; border-radius: .35rem; }
.pv-preview img { max-width: 100%; max-height: 70vh; border-radius: .35rem; }
.pv-preview pre { color: #e2e8f0; text-align: left; font-size: .85rem; width: 100%; max-height: 70vh; overflow: auto; }
.pv-preview .pv-icon-big { font-size: 5rem; opacity: .5; }
.pv-meta {
    background: #f8fafc;
    border-radius: .5rem;
    padding: 1rem;
    font-size: .88rem;
    max-height: 70vh;
    overflow-y: auto;
}
.pv-meta dl { margin: 0; }
.pv-meta dt {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ck-muted);
    margin-top: .75rem;
}
.pv-meta dd { margin: 0; word-break: break-word; }
.pv-meta .actions {
    display: flex;
    gap: .35rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.pv-meta .actions .btn { font-size: .82rem; }

.docx-preview-wrap {
    background: #e5e7eb;
    padding: 1.5rem .5rem;
    overflow: auto;
    max-height: 72vh;
    border-radius: .5rem;
    width: 100%;
}
.docx-preview-wrap .docx-wrapper { background: transparent; padding: 0; }
.docx-preview-wrap .docx-wrapper > section.docx {
    background: #fff;
    margin: 1rem auto;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    border-radius: .25rem;
    padding: 2rem;
    max-width: 800px;
}

.xlsx-preview-wrap {
    background: #fff;
    padding: 1rem;
    border-radius: .5rem;
    overflow: auto;
    max-height: 72vh;
    width: 100%;
}
.xlsx-preview-wrap table { border-collapse: collapse; font-size: .85rem; margin-bottom: 1.5rem; }
.xlsx-preview-wrap table td,
.xlsx-preview-wrap table th {
    border: 1px solid #e2e8f0;
    padding: .3rem .6rem;
    white-space: nowrap;
}
.xlsx-sheet-title {
    font-weight: 600;
    color: var(--ck-navy);
    margin: .5rem 0;
    padding-bottom: .25rem;
    border-bottom: 2px solid var(--ck-gold);
    display: inline-block;
}

/* =========================================================
   NOTIFICATIONS
   ========================================================= */
.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: .65rem;
    padding: .15rem .35rem;
}
.notif-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    animation: ck-pulse 1.4s infinite;
    pointer-events: none;
}
@keyframes ck-pulse {
    0%   { transform: scale(.85); opacity: .9; }
    70%  { transform: scale(1.35); opacity: 0; }
    100% { transform: scale(1.35); opacity: 0; }
}
.notif-menu { padding: 0; box-shadow: 0 12px 32px rgba(0,0,0,.12); }
.notif-item {
    padding: .6rem .9rem;
    border-bottom: 1px solid #f1f5f9;
    white-space: normal;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: #f8fafc; }
.notif-item-urgent { background: #fff7ed; }
.notif-item-urgent:hover { background: #ffedd5; }
.notif-item-icon { font-size: 1.05rem; padding-top: .1rem; }

.notif-row {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border-bottom: 1px solid #f1f5f9;
}
.notif-row:last-child { border-bottom: none; }
.notif-row:hover { background: #f8fafc; }
.notif-row.notif-urgent { background: #fff7ed; border-left: 4px solid #ef4444; }
.notif-row.notif-read { opacity: .65; background: #fff; border-left-color: #e2e8f0; }
.notif-icon { font-size: 1.35rem; padding-top: .15rem; flex-shrink: 0; }
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: .95rem; }
.notif-time { font-size: .75rem; }
.notif-message { font-size: .9rem; color: #334155; white-space: pre-wrap; word-break: break-word; }

/* =========================================================
   BACKDROP (mobile menu)
   ========================================================= */
.ck-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 1030;
    opacity: 0;
    transition: opacity .25s;
}
.ck-backdrop.show { display: block; opacity: 1; }

/* =========================================================
   STICKY table head (bulk preview)
   ========================================================= */
.sticky-top { z-index: 5; }

/* =========================================================
   RESPONSIVE — Tablet (≤ 991.98px)
   ========================================================= */
@media (max-width: 991.98px) {

    /* Sidebar becomes an off-canvas drawer */
    .ck-sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,.15);
    }
    .ck-sidebar.open { transform: translateX(0); }

    /* Main takes full width */
    .ck-main { margin-left: 0; }

    /* Show the burger */
    .ck-burger { display: block; }

    .ck-content { padding: 1rem; }

    /* Preview modal stacks vertically */
    .pv-body {
        grid-template-columns: 1fr;
        gap: .75rem;
    }
    .pv-preview { min-height: 45vh; }
    .pv-preview iframe { height: 55vh; }
    .pv-preview img { max-height: 55vh; }
    .pv-preview pre { max-height: 55vh; }
    .pv-meta { max-height: none; }
}

/* =========================================================
   RESPONSIVE — Phone (≤ 767.98px)
   ========================================================= */
@media (max-width: 767.98px) {

    .ck-topbar { padding: .7rem 1rem; }
    .ck-topbar h1 { font-size: 1rem; }

    .ck-content { padding: .85rem; }

    /* Stat cards — 2 per row */
    .stat-card { padding: .85rem; }
    .stat-card .val { font-size: 1.25rem; }

    /* Full-screen preview modal */
    .modal-xl,
    .modal-lg { --bs-modal-width: 100%; }
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }
    .modal-content {
        border: 0;
        border-radius: 0;
        min-height: 100vh;
    }
    .pv-preview { min-height: 40vh; }
    .pv-preview iframe { height: 50vh; }
    .pv-preview img { max-height: 50vh; }

    /* ---------- TABLE → CARD LAYOUT ---------- */
    .table-mobile thead { display: none; }
    .table-mobile tbody tr {
        display: block;
        background: #fff;
        border-radius: .65rem;
        box-shadow: 0 1px 4px rgba(0,0,0,.06);
        margin-bottom: .75rem;
        padding: .85rem .95rem;
        border: 0;
    }
    .table-mobile tbody tr.clickable-row:hover { background: #f8fafc; }
    .table-mobile tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: .75rem;
        padding: .35rem 0;
        border: 0;
        font-size: .88rem;
        text-align: left !important;
    }
    .table-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--ck-muted);
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .04em;
        flex-shrink: 0;
    }
    .table-mobile tbody td[data-label=""]::before { content: none; }
    .table-mobile tbody td:not([data-label])::before { content: none; }

    /* File name cell — show without label at top */
    .table-mobile tbody td.cell-file {
        padding-bottom: .6rem;
        border-bottom: 1px solid #f1f5f9;
        margin-bottom: .35rem;
    }
    .table-mobile tbody td.cell-file::before { display: none; }

    /* Action buttons row — no label, left-aligned */
    .table-mobile tbody td.cell-actions {
        justify-content: flex-start;
        padding-top: .75rem;
        border-top: 1px solid #f1f5f9;
        margin-top: .35rem;
    }
    .table-mobile tbody td.cell-actions::before { display: none; }
    .table-mobile tbody td.cell-actions .btn-group { flex-wrap: wrap; gap: .25rem; }
    .table-mobile tbody td.cell-actions .btn { padding: .4rem .6rem; font-size: .85rem; }

    /* Pagination */
    .pagination { flex-wrap: wrap; justify-content: center; }
    .page-link { padding: .35rem .65rem; font-size: .85rem; }

    /* Filter forms — no force column */
    .card form .row > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }

    /* Filter card — tighten spacing */
    .card > form.p-3 { padding: .85rem !important; }

    /* Buttons inside card headers stack */
    .d-flex.justify-content-between.align-items-center.mb-2 { flex-direction: column; align-items: stretch !important; gap: .5rem; }

    /* Docx / Xlsx preview — less padding */
    .docx-preview-wrap { padding: 1rem .25rem; }
    .docx-preview-wrap .docx-wrapper > section.docx { padding: 1rem; }
    .xlsx-preview-wrap { padding: .5rem; }

    /* Notifications */
    .notif-row { padding: .85rem; gap: .75rem; }
    .notif-title { font-size: .9rem; }
}

/* =========================================================
   RESPONSIVE — Small phone (≤ 575.98px)
   ========================================================= */
@media (max-width: 575.98px) {

    .ck-content { padding: .65rem; }

    .stat-card { padding: .7rem .85rem; }
    .stat-card .lbl { font-size: .65rem; }
    .stat-card .val { font-size: 1.1rem; }

    .ck-brand { padding: 1rem .85rem; }
    .ck-brand strong { font-size: .85rem; }

    /* Action buttons stack in 2 columns */
    .table-mobile tbody td.cell-actions .btn-group {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        width: 100%;
    }
    .table-mobile tbody td.cell-actions .btn-group > * {
        width: 100%;
    }

    /* Modal — total full screen */
    .modal-dialog { margin: 0; }
    .modal-content { border-radius: 0; }

    /* Filter form small buttons go full width */
    .card form .btn-sm { width: 100%; }

    /* Back to top */
    .back-top { right: 1rem; bottom: 1rem; width: 42px; height: 42px; font-size: 1rem; }
}

/* =========================================================
   Accessibility — allow selection inside form fields
   ========================================================= */
input, textarea, select {
    -webkit-user-select: text;
    user-select: text;
}

/* Prevent iOS zoom on focus (font-size must be ≥ 16px) */
@media (max-width: 767.98px) {
    .form-control, .form-select { font-size: 16px; }
    input[type="date"].form-control { font-size: 16px; }
}