/* KMK fixes (Nov 2026, Batch 5–7). Loaded last by every layout header. */

/* H16 / UI-14 — no sideways page scroll at desktop width.
   The main area is a flex child next to the sidebar: let it shrink. */
.app-layout { min-width: 0; }
.app-layout .main-content,
.app-layout main,
.app-layout .content { min-width: 0; max-width: 100%; overflow-x: clip; }
.public-main, .customer-main, main { min-width: 0; }
/* Wide tables scroll inside their own box instead of pushing the page. */
.table-container, .table-responsive, .kmk-table-scroll {
    width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.page-header, .table-header { flex-wrap: wrap; gap: .75rem; }
.page-header > *, .table-header > * { min-width: 0; }

/* Dates, reference numbers and money stay on one line in tables. */
.table td:first-child,
.table td.nowrap, .table th.nowrap,
.table td time { white-space: nowrap; }

/* H15 / UI-13 — status badges never wrap and use the same compact shape. */
.badge,
.status-badge,
.kmk-badge-nowrap,
.table td span[style*="background"],
td > span[style*="border-radius"] {
    white-space: nowrap !important;
    display: inline-block;
    line-height: 1.35;
}
.table td span[style*="border-radius:999px"],
.table td span[style*="border-radius: 999px"] { border-radius: 5px !important; }

/* Action button groups wrap instead of overflowing. */
.table td .btn + .btn, .table td form + .btn, .table td .btn + form { margin-left: .25rem; }
.table td form { display: inline-block; margin: 0; }

/* Broken / missing 3D model message (model-viewer-status.js). */
model-viewer { position: relative; }
.kmk-model-error { border-radius: inherit; }

/* Required-field marker and visible field errors. */
.required { color: #dc2626; font-weight: 700; }
.kmk-field-error-msg { display: block; color: #dc2626; font-size: .8rem; margin-top: .25rem; }
.kmk-field-invalid { border-color: #dc2626 !important; background: #fef2f2 !important; }

/* Home page: "View details" is a quiet text link, not a second button. */
.product-info .product-link {
    display: inline-block; margin-top: .35rem; color: var(--primary-700, #1565c0);
    font-weight: 600; font-size: .9rem; text-decoration: none;
}
.product-info .product-link:hover, .product-info .product-link:focus-visible { text-decoration: underline; }

/* ===== UI consistency pass (Nov 12) ===== */

/* Page header: the title is always shown; actions sit on the right. */
.main-content .page-header.kmk-page-header {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
    gap: .75rem 1rem; margin: 0 0 1rem; padding: 0 0 .75rem;
    background: none; box-shadow: none; border: 0; border-bottom: 1px solid var(--gray-200, #e5e7eb); border-radius: 0;
}
.main-content .page-header.kmk-page-header h1 {
    margin: 0; font-size: 1.45rem; line-height: 1.25; color: var(--gray-900, #0f172a);
    display: flex; align-items: center; flex-wrap: wrap; gap: .5rem;
}
.main-content .page-header.kmk-page-header p { margin: .2rem 0 0; color: #64748b; font-size: .9rem; }
.main-content .page-header.kmk-page-header h1 span[style*="background"] { font-size: .8rem !important; font-weight: 600; border-radius: 5px !important; white-space: nowrap; }
.main-content .page-header.kmk-page-header .kmk-page-actions { margin: 0 0 0 auto; }

/* Badges: one look everywhere (these classes had no colours before). */
.badge {
    display: inline-block; padding: 4px 10px; border-radius: 5px; font-size: .75rem; font-weight: 600;
    line-height: 1.35; white-space: nowrap; color: #fff; background: #64748b;
}
.badge.badge-success { background: #15803d; }
.badge.badge-danger { background: #dc2626; }
.badge.badge-warning { background: #b45309; }
.badge.badge-info, .badge.badge-primary { background: #1565c0; }
.badge.badge-secondary { background: #64748b; }

/* Buttons inside tables: same height, same size, never wrap. */
.table td .btn, .table td a.btn, .table td button.btn,
.table td .btn-sm, .table td .btn-small {
    display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box;
    height: 32px; min-height: 32px; padding: 0 .8rem; margin: 0; font-size: .8rem; line-height: 1;
    white-space: nowrap; border-radius: 7px; vertical-align: middle;
}
.table td .btn + .btn, .table td form + .btn, .table td .btn + form, .table td form + form { margin-left: .35rem; }
.table td form { display: inline-flex; align-items: center; margin: 0; vertical-align: middle; }
/* "Edit" looks the same on every list (Users used a white outline). */
.table td a.btn.btn-secondary[href*="_edit.php"] { background: var(--primary-600, #1976d2) !important; border-color: var(--primary-600, #1976d2) !important; color: #fff !important; }
.table td a.btn.btn-secondary[href*="_edit.php"]:hover { background: var(--primary-700, #1565c0) !important; }
.table th { white-space: nowrap; }
.btn { white-space: nowrap; }

/* One-line cells, and an Actions column that stays in view when the table scrolls sideways. */
.table td.kmk-nowrap, .kmk-c-table td.kmk-nowrap, table td.kmk-nowrap { white-space: nowrap; }
table.kmk-has-actions tbody tr { background: #fff; }
table.kmk-has-actions th:last-child,
table.kmk-has-actions td:last-child {
    position: sticky; right: 0; z-index: 1; background: inherit; white-space: nowrap;
    box-shadow: -8px 0 8px -8px rgba(15, 23, 42, .18);
}
table.kmk-has-actions thead th:last-child { background: var(--gray-50, #f8fafc); }

/* Form controls share one font; filter bars line up. */
textarea, select, input, button { font-family: inherit; }
.search-form .btn, form[data-validate="off"] .btn, .report-filters .btn { height: 38px; padding-top: 0; padding-bottom: 0; display: inline-flex; align-items: center; line-height: 1; }

/* Chat: Edit / Delete are easier to tap. */
.chat-action-btn { font-size: .8rem !important; padding: .25rem .35rem !important; min-height: 28px; }

/* 3D & AR cards: the two buttons match. */
.ar-actions .btn { white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; min-height: 40px; }

/* Toasts with several sentences stay readable. */
.toast { max-width: min(92vw, 520px); align-items: flex-start; }

/* Show the page title (an older rule hid it) and let the sticky Actions column work. */
.main-content .page-header.kmk-page-header h1 { display: flex !important; font-size: 1.45rem !important; }
.main-content .page-header.kmk-page-header > h2 { display: block !important; }
.main-content .page-header.kmk-page-header p { display: block !important; }
.main-content .page-header.kmk-page-header {
    margin: 0 0 1rem !important; padding: 0 0 .75rem !important;
    border-bottom: 1px solid var(--gray-200, #e5e7eb) !important;
}
table.kmk-has-actions { overflow: visible; }
.table-container { border-radius: var(--radius-lg, 12px); }

/* Header buttons: one size on every page. */
.main-content .page-header.kmk-page-header .kmk-page-actions .btn,
.kmk-page-actions .btn {
    display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box;
    height: 40px; min-height: 40px; padding: 0 1.1rem; font-size: .9rem; line-height: 1; white-space: nowrap;
}
/* Name / product columns keep a readable width instead of wrapping into four lines. */
table.kmk-has-actions td:nth-child(2) { min-width: 150px; }

/* Status labels: same shape and size on every page (colours come from kmk_status_colors() in PHP). */
.table td span[style*="background"][style*="color:#fff"],
.table td span[style*="background"][style*="color: #fff"],
.table td span[style*="background"][style*="color:white"],
.table td .badge, .status-badge,
.main-content p > span[style*="background"][style*="color:#fff"],
.main-content .page-header h1 span[style*="background"] {
    display: inline-block !important; padding: 4px 10px !important; border-radius: 5px !important;
    font-size: .75rem !important; font-weight: 600 !important; line-height: 1.35 !important;
    letter-spacing: 0 !important; text-transform: none !important; white-space: nowrap !important; color: #fff !important;
}


/* ===== Nov 12, round 4 ===== */
/* Number fields: no up/down arrows. Values are typed in. */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* Product image card: the "Primary" label is white text on green, clearly different from the yellow "Set Primary" button. */
.image-item .badge-primary {
    display: inline-block; background: #15803d !important; color: #ffffff !important;
    padding: 3px 8px; border-radius: 5px; font-size: .75rem; font-weight: 700; white-space: nowrap;
}

/* 3D models: progress message while a model file downloads (model-viewer-status.js). */
.kmk-model-loading {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: .5rem; padding: 1rem; text-align: center; background: rgba(248, 250, 252, .92); color: #334155;
    font-size: .9rem; font-weight: 600; z-index: 1; pointer-events: none;
}
.kmk-model-loading .kmk-model-bar { width: min(220px, 70%); height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.kmk-model-loading .kmk-model-bar i { display: block; height: 100%; width: 0; background: #1565c0; transition: width .2s; }

/* ===== Milestone progress (panel revision, Nov 20) ===== */
.kmk-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Full tracker on one order / quotation */
.kmk-tracker {
    background: #fff; border: 1px solid var(--gray-200, #e5e7eb); border-radius: 14px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .06); padding: 1rem 1.25rem 1.1rem; margin: 0 0 1.5rem;
}
.kmk-tracker-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .25rem 1rem; margin-bottom: .9rem; }
.kmk-tracker-head h2 { margin: 0; font-size: 1rem; color: var(--gray-900, #0f172a); }
.kmk-tracker-summary { font-size: .85rem; color: #475569; font-weight: 600; }
.kmk-tracker-stopped .kmk-tracker-summary { color: #b91c1c; }
.kmk-tracker-done .kmk-tracker-summary { color: #15803d; }
.kmk-tracker-meter { overflow-x: auto; padding: 1.1rem .25rem .25rem; }
.kmk-tracker-steps {
    --kmk-dot: 28px; position: relative; display: flex; list-style: none; margin: 0; padding: 0; min-width: 560px;
}
/* grey track behind the dots, green fill up to the current step */
.kmk-tracker-steps::before, .kmk-tracker-steps::after {
    content: ""; position: absolute; top: calc(var(--kmk-dot) / 2 - 2px); height: 4px; border-radius: 4px;
    left: calc(100% / (2 * var(--kmk-n, 6))); right: calc(100% / (2 * var(--kmk-n, 6)));
}
.kmk-tracker-steps::before { background: #e2e8f0; }
.kmk-tracker-steps::after { background: #22c55e; right: auto; width: calc((100% - 100% / var(--kmk-n, 6)) * var(--kmk-progress-num, 0)); }
.kmk-tracker-step { position: relative; flex: 1 1 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .3rem; z-index: 1; }
.kmk-tracker-dot {
    width: var(--kmk-dot); height: var(--kmk-dot); border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700; border: 2px solid #cbd5e1; background: #fff; color: #94a3b8;
}
.kmk-tracker-label { font-size: .8rem; font-weight: 600; color: #94a3b8; line-height: 1.2; padding: 0 .2rem; }
.kmk-tracker-date { font-size: .72rem; color: #64748b; }
.kmk-tracker-step.is-done .kmk-tracker-dot { background: #22c55e; border-color: #22c55e; color: #fff; }
.kmk-tracker-step.is-done .kmk-tracker-label { color: #334155; }
.kmk-tracker-step.is-current .kmk-tracker-dot { background: #22c55e; border-color: #22c55e; color: #fff; box-shadow: 0 0 0 5px rgba(34, 197, 94, .2); }
.kmk-tracker-step.is-current .kmk-tracker-label { color: #0f172a; }
.kmk-tracker-step.is-stopped .kmk-tracker-dot { background: #dc2626; border-color: #dc2626; color: #fff; font-size: 1rem; box-shadow: 0 0 0 5px rgba(220, 38, 38, .15); }
.kmk-tracker-step.is-stopped .kmk-tracker-label { color: #b91c1c; }
.kmk-tracker-caret {
    position: absolute; top: -1rem; width: 9px; height: 9px; border-right: 2px solid #475569; border-bottom: 2px solid #475569; transform: rotate(45deg);
}

/* Clickable milestone steps in a list's filter bar (beside Status and Clear) */
.kmk-flow-host { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; }
.kmk-flow { flex: 1 1 520px; min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: .5rem .75rem;
    background: #fff; border: 1px solid var(--gray-200, #e5e7eb); border-radius: 12px; padding: .55rem .75rem; box-shadow: 0 2px 8px rgba(15, 23, 42, .04); }
.kmk-flow-steps { display: flex; list-style: none; margin: 0; padding: 0; flex: 1 1 auto; min-width: 0; }
.kmk-flow-step { position: relative; flex: 1 1 0; min-width: 72px; }
.kmk-flow-step + .kmk-flow-step::before {   /* connector line */
    content: ""; position: absolute; top: 12px; right: calc(50% + 14px); width: calc(100% - 28px); height: 3px; border-radius: 3px; background: #e2e8f0;
}
.kmk-flow-step a { display: flex; flex-direction: column; align-items: center; gap: .2rem; text-decoration: none; color: #64748b; padding: 0 .15rem; border-radius: 8px; }
.kmk-flow-step a:hover .kmk-flow-label, .kmk-flow-step a:focus-visible .kmk-flow-label { color: var(--primary-700, #1565c0); text-decoration: underline; }
.kmk-flow-dot { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700;
    border: 2px solid #cbd5e1; background: #fff; color: #94a3b8; position: relative; z-index: 1; }
.kmk-flow-step.has-items .kmk-flow-dot { border-color: #22c55e; color: #15803d; }
.kmk-flow-step.is-active .kmk-flow-dot { background: #22c55e; border-color: #22c55e; color: #fff; box-shadow: 0 0 0 4px rgba(34, 197, 94, .2); }
.kmk-flow-label { font-size: .72rem; font-weight: 600; line-height: 1.15; text-align: center; white-space: nowrap; }
.kmk-flow-step.is-active .kmk-flow-label { color: #0f172a; }
.kmk-flow-count { font-size: .68rem; font-weight: 700; color: #475569; background: #f1f5f9; border-radius: 999px; padding: 0 .45rem; line-height: 1.5; }
.kmk-flow-step.is-active .kmk-flow-count { background: #dcfce7; color: #15803d; }
.kmk-flow-stop { display: inline-flex; align-items: center; gap: .35rem; text-decoration: none; font-size: .75rem; font-weight: 600; color: #b91c1c;
    border: 1px solid #fecaca; background: #fff5f5; border-radius: 999px; padding: .2rem .65rem; white-space: nowrap; }
.kmk-flow-stop .kmk-flow-x { font-size: .95rem; line-height: 1; }
.kmk-flow-stop .kmk-flow-count { background: #fee2e2; color: #b91c1c; }
.kmk-flow-stop.is-active { background: #dc2626; border-color: #dc2626; color: #fff; }
.kmk-flow-stop.is-active .kmk-flow-count { background: rgba(255, 255, 255, .25); color: #fff; }
@media (max-width: 700px) {
    .kmk-flow { flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .kmk-flow-steps { min-width: 460px; }
}

/* Per-row progress on list pages (Nov 20, rev 2) */
.kmk-pick { flex: 1 1 520px; min-width: 0; }
.kmk-pick-hint { margin: 0; padding: .7rem 1rem; border: 1px dashed #cbd5e1; border-radius: 12px; color: #64748b; font-size: .875rem; background: #fff; }
.kmk-pick .kmk-tracker { margin: 0; padding: .6rem 1rem .7rem; }
.kmk-pick .kmk-tracker h2 { font-size: .95rem; }
tr[data-kmk-row] { cursor: pointer; }
tr[data-kmk-row]:hover td { background: #f8fafc; }
tr[data-kmk-row]:focus-visible { outline: 2px solid var(--primary-600, #1e88e5); outline-offset: -2px; }
tr.kmk-row-picked td { background: #ecfdf5 !important; box-shadow: inset 0 0 0 0 transparent; }
tr.kmk-row-picked td:first-child { box-shadow: inset 3px 0 0 #22c55e; }
