/* =====================================================================================
   ATS additions to the shared design system (crm.css). Only ATS-specific pieces live
   here; everything uses the --crm-* tokens so light and dark mode both work.
   ===================================================================================== */

/* ---------- Small utilities ---------- */
.min-w-0 { min-width: 0; }
.fw-600 { font-weight: 600; }
.toolbar .search-box.flex-grow-1 { max-width: none; }
img.avatar { object-fit: cover; background: var(--crm-surface-2); }
.logo-thumb { width: 36px; height: 36px; border-radius: var(--crm-radius-sm); object-fit: contain; background: var(--crm-surface-2); border: 1px solid var(--crm-border); flex-shrink: 0; }
.cell-clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-pre { white-space: pre-line; }
.toolbar [data-list-filters] { display: contents; }
.table-crm tbody tr[data-href] { cursor: pointer; }
.page-actions form { display: inline-flex; }

/* A dynamic-fields card with no fields configured is hidden entirely. */
.card-crm:has([data-dynamic-empty]) { display: none; }

/* ---------- Stage / status helpers ---------- */
.stage-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-right: .35rem; vertical-align: middle; }
.funnel-row { display: grid; grid-template-columns: minmax(110px, 160px) 1fr 44px; gap: .75rem; align-items: center; padding: .4rem 0; font-size: .82rem; }
.funnel-track { height: 8px; border-radius: 999px; background: var(--crm-neutral-soft); overflow: hidden; }
.funnel-fill { display: block; height: 100%; border-radius: inherit; background: var(--crm-primary); min-width: 2px; }
.funnel-row .num { text-align: right; font-weight: 700; color: var(--crm-text); }

/* ---------- Score ring (candidate / application) ---------- */
.score-ring { --v: 0; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
    background: radial-gradient(closest-side, var(--crm-surface) 78%, transparent 80% 100%), conic-gradient(var(--crm-primary) calc(var(--v) * 1%), var(--crm-neutral-soft) 0); }
.score-ring span { font-weight: 750; font-size: .85rem; color: var(--crm-text); }

/* ---------- Document tiles (candidate files) ---------- */
.doc-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; font-size: 1.1rem; background: var(--crm-primary-soft); color: var(--crm-primary-text); }
.doc-icon[data-ext="pdf"] { background: var(--crm-danger-soft); color: var(--crm-danger-text); }
.doc-icon[data-ext="doc"], .doc-icon[data-ext="docx"] { background: var(--crm-info-soft); color: var(--crm-info-text); }
.doc-icon[data-ext="png"], .doc-icon[data-ext="jpg"], .doc-icon[data-ext="jpeg"] { background: var(--crm-success-soft); color: var(--crm-success-text); }
.doc-tile { display: flex; align-items: center; gap: .75rem; padding: .7rem .8rem; border: 1px solid var(--crm-border); border-radius: var(--crm-radius); background: var(--crm-surface); color: var(--crm-text); width: 100%; text-align: left; }
.doc-tile:hover { border-color: rgba(var(--crm-primary-rgb), .45); background: var(--crm-surface-hover); color: var(--crm-text); }
.doc-tile .name { font-weight: 600; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.doc-tile .meta { font-size: .74rem; color: var(--crm-muted); display: block; }

/* ---------- Q & A (screening answers) ---------- */
.qa-item { padding: .8rem 0; border-bottom: 1px solid var(--crm-border); }
.qa-item:last-child { border-bottom: 0; }
.qa-item .q { font-size: .78rem; font-weight: 600; color: var(--crm-muted); margin-bottom: .2rem; }
.qa-item .a { white-space: pre-line; }

/* ---------- In-page file viewer ---------- */
.ats-viewer .modal-dialog { max-width: min(1320px, 96vw); }
.ats-viewer .modal-content { height: calc(100vh - 3.5rem); }
.ats-viewer .modal-dialog.modal-fullscreen { max-width: none; width: 100vw; margin: 0; }
.ats-viewer .modal-dialog.modal-fullscreen .modal-content { height: 100vh; border-radius: 0; }
.ats-viewer .modal-header { gap: .6rem; flex-wrap: nowrap; }
.ats-viewer .modal-title { font-size: 1rem; margin: 0; }
.ats-viewer .modal-body { display: flex; min-height: 0; overflow: hidden; background: var(--crm-bg); padding: 0; }
.fv-rail { width: 280px; flex-shrink: 0; overflow-y: auto; padding: .5rem .75rem 1rem; background: var(--crm-surface); border-right: 1px solid var(--crm-border); }
.fv-single .fv-rail { display: none; }
.fv-rail-group { padding: .9rem .5rem .35rem; font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--crm-subtle); }
.fv-item { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .6rem; margin-bottom: 2px; text-align: left; color: var(--crm-text-2); background: none; border: 1px solid transparent; border-radius: var(--crm-radius); }
.fv-item:hover { background: var(--crm-surface-hover); }
.fv-item.is-active { background: var(--crm-primary-soft); border-color: rgba(var(--crm-primary-rgb), .3); color: var(--crm-primary-text); }
.fv-item .doc-icon { width: 34px; height: 34px; font-size: 1rem; }
.fv-item-name { display: block; overflow: hidden; font-size: .82rem; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.fv-item-meta { display: block; font-size: .72rem; color: var(--crm-muted); }
.fv-stage { position: relative; display: flex; flex: 1; min-width: 0; }
.fv-frame { flex: 1; width: 100%; height: 100%; border: 0; background: #fff; }
.fv-state { margin: auto; max-width: 540px; padding: 2rem 1.5rem; text-align: center; }
.fv-state h3 { font-size: 1.05rem; margin-bottom: .4rem; }
.fv-state p { color: var(--crm-muted); }
.fv-state-icon { display: inline-grid; place-items: center; width: 64px; height: 64px; margin-bottom: 1rem; border-radius: 18px; font-size: 1.75rem; color: var(--crm-primary); background: var(--crm-primary-soft); }
.fv-state[data-tone="warn"] .fv-state-icon { color: var(--crm-warning); background: var(--crm-warning-soft); }
.fv-state-detail { margin-top: 1rem; padding: .75rem 1rem; font-size: .8rem; text-align: left; color: var(--crm-text-2); background: var(--crm-surface); border: 1px dashed var(--crm-border-strong); border-radius: var(--crm-radius); }
.fv-image-wrap { display: grid; flex: 1; place-items: center; overflow: auto; padding: 1.5rem; }
.fv-image { max-width: 100%; height: auto; background: #fff; box-shadow: var(--crm-shadow-lg); }
.fv-text { flex: 1; margin: 0; overflow: auto; padding: 1.5rem 2rem; font-size: .85rem; white-space: pre-wrap; background: var(--crm-surface); color: var(--crm-text); }
.fv-paper-wrap { flex: 1; overflow: auto; padding: 1.5rem; }
.fv-paper { max-width: 820px; margin: 0 auto; padding: 2.5rem 3rem; line-height: 1.7; white-space: pre-line; background: var(--crm-surface); border-radius: var(--crm-radius-sm); box-shadow: var(--crm-shadow); }
@media (max-width: 991.98px) {
    .ats-viewer .modal-content { height: 100%; }
    .ats-viewer .modal-body { flex-direction: column; }
    .fv-rail { display: flex; gap: .5rem; width: auto; overflow-x: auto; overflow-y: hidden; padding: .5rem; border-right: 0; border-bottom: 1px solid var(--crm-border); }
    .fv-rail-group { display: none; }
    .fv-item { flex: 0 0 220px; width: auto; margin: 0; }
    #fvFullscreen { display: none; }
    .fv-paper { padding: 1.5rem; }
}

/* ---------- Detail pages ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.detail-grid > aside { position: sticky; top: calc(var(--crm-topbar-h) + 1rem); display: grid; gap: 1rem; }
@media (max-width: 1199.98px) { .detail-grid { grid-template-columns: 1fr; } .detail-grid > aside { position: static; } }
.info-grid .info-item .value:empty::after { content: "—"; color: var(--crm-subtle); }
.app-card { border: 1px solid var(--crm-border); border-radius: var(--crm-radius); padding: .9rem 1rem; background: var(--crm-surface); }
.app-card + .app-card { margin-top: .75rem; }
.app-card .head { display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.app-card .title { font-weight: 650; }

/* ---------- Upload preview (logos / photos) ---------- */
.upload-preview { display: flex; align-items: center; gap: 1rem; }
.upload-preview img { width: 72px; height: 72px; border-radius: var(--crm-radius); object-fit: contain; border: 1px solid var(--crm-border); background: var(--crm-surface-2); }

/* ---------- Public careers / apply pages ---------- */
.public-shell { min-height: 100vh; background: var(--crm-bg); }
.public-top { display: flex; align-items: center; gap: .6rem; padding: .9rem clamp(1rem, 4vw, 2rem); background: var(--crm-surface); border-bottom: 1px solid var(--crm-border); }
.public-top .brand-name { font-weight: 750; color: var(--crm-text); }
.public-main { max-width: 1080px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }
.public-foot { text-align: center; padding: 1.5rem; font-size: .78rem; color: var(--crm-muted); }

/* ---------- Job wizard (Create / Application form / Screening / Publish) ---------- */
.wizard-steps { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; padding: .35rem; background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius-lg); margin-bottom: 1rem; }
.wizard-steps::-webkit-scrollbar { display: none; }
.wizard-step { display: flex; align-items: center; gap: .55rem; padding: .55rem .8rem; border-radius: var(--crm-radius); color: var(--crm-muted); font-weight: 600; font-size: .82rem; white-space: nowrap; flex: 1 0 auto; }
.wizard-step .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; background: var(--crm-neutral-soft); color: var(--crm-neutral-text); }
.wizard-step.done { color: var(--crm-success-text); }
.wizard-step.done .n { background: var(--crm-success-soft); color: var(--crm-success-text); }
.wizard-step.current { background: var(--crm-primary-soft); color: var(--crm-primary-text); }
.wizard-step.current .n { background: var(--crm-primary); color: #fff; }
a.wizard-step:hover { color: var(--crm-text); background: var(--crm-surface-hover); }

/* ---------- Permission matrix ---------- */
.permission-matrix th.module { min-width: 200px; }
.permission-matrix td.perm, .permission-matrix th.perm { text-align: center; width: 90px; }

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .page-actions, .toolbar, .pager, .sticky-actions, .toast-stack { display: none !important; }
    .main { margin: 0 !important; }
}

/* ---------- Bridge for older page-level styles (job wizard, public apply) ----------
   Their stylesheets use the previous token names; point them at the kit tokens so they
   follow the same palette and dark mode. */
:root, [data-theme="dark"] {
    --card-bg: var(--crm-surface);
    --card-header-bg: var(--crm-surface-2);
    --border-color: var(--crm-border);
    --border-light: var(--crm-neutral-soft);
    --divider-color: var(--crm-border);
    --primary: var(--crm-primary);
    --primary-soft-bg: var(--crm-primary-soft);
    --primary-shadow: var(--crm-focus);
    --text-primary: var(--crm-text);
    --text-secondary: var(--crm-muted);
    --heading-color: var(--crm-text);
    --placeholder-color: var(--crm-subtle);
    --table-header-bg: var(--crm-surface-2);
    --success-color: var(--crm-success);
    --success-soft-bg: var(--crm-success-soft);
    --danger-color: var(--crm-danger);
    --danger-soft-bg: var(--crm-danger-soft);
    --info-color: var(--crm-info);
    --info-soft-bg: var(--crm-info-soft);
    --input-bg: var(--crm-surface);
    --input-border: var(--crm-border-strong);
    --input-focus: var(--crm-primary);
    --shadow-sm: var(--crm-shadow-sm);
    --shadow-md: var(--crm-shadow);
    --transition-fast: .15s ease;
}
.job-description { line-height: 1.7; }
.job-description img { max-width: 100%; height: auto; }
.job-description table { width: 100%; }
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--crm-subtle); pointer-events: none; }
.rich-editor h3 { font-size: 1.05rem; margin: .75rem 0 .35rem; }
.form-section:has([data-dynamic-empty]) { display: none; }

/* ---------- Job wizard building blocks ---------- */
.ats-soft-panel, .wizard-tips-card { background: var(--crm-surface-2); border: 1px solid var(--crm-border); border-radius: var(--crm-radius); }
.setting-card { border: 1px solid var(--crm-border); border-radius: var(--crm-radius); padding: 1rem; background: var(--crm-surface); }
.setting-card:hover { border-color: rgba(var(--crm-primary-rgb), .35); }
.setting-icon, .ats-avatar-sm { width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center; background: var(--crm-primary-soft); color: var(--crm-primary-text); flex-shrink: 0; }
.suggestion-badge, .ats-chip-toggle { cursor: pointer; border: 1px solid var(--crm-border-strong); border-radius: 999px; padding: .25rem .7rem; font-size: .76rem; font-weight: 600; background: var(--crm-surface); color: var(--crm-text-2); }
.suggestion-badge:hover, .ats-chip-toggle:hover { border-color: var(--crm-primary); color: var(--crm-primary-text); }
.suggestion-badge.bg-primary { background: var(--crm-primary) !important; border-color: var(--crm-primary); color: #fff !important; }
.wizard-main-card { background: var(--crm-surface); border: 1px solid var(--crm-border); border-radius: var(--crm-radius-lg); padding: 1.25rem; box-shadow: var(--crm-shadow-sm); }

/* <dl class="info-list"> (definition-list form of the kit's info list) */
dl.info-list { display: grid; grid-template-columns: minmax(96px, auto) 1fr; font-size: .84rem; }
dl.info-list > dt, dl.info-list > dd { margin: 0; padding: .55rem 0; border-bottom: 1px dashed var(--crm-border); }
dl.info-list > dt { font-weight: 400; padding-right: 1rem; }
dl.info-list > dt:nth-last-of-type(1), dl.info-list > dd:last-of-type { border-bottom: 0; }

/* Dashboard: six KPI tiles in even rows (2 × 3, or one row on very wide screens). */
@media (min-width: 768px) { .kpi-grid.kpi-six { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1680px) { .kpi-grid.kpi-six { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
