/* =========================================================
   Fleet Management — app-specific layer on top of the
   enterprise theme (style.css). Keep only overrides that
   are unique to this app.
   ========================================================= */

/* --- Page title row ------------------------------------------------ */
.page-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.page-title-row h1 {
    font-size: 17px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.page-title-row h1 .lucide { color: var(--accent); }
.page-title-row .spacer { flex: 1; }

/* --- Toolbar (search + actions) ----------------------------------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }

/* --- Dashboard stat cards ----------------------------------------- */
/* Equal-width cards that fill the row regardless of count; wrap on
   narrow screens with equal fill per line. */
.stats-row {
    grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
}
.stat-card {
    min-height: 82px;
    padding: 16px 18px;
}
.stat-card .stat-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    flex: 1;
}
.stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    font-size: 18px;
    flex-shrink: 0;
}
.stat-card .stat-icon .lucide { width: 18px; height: 18px; }
.stat-card .stat-value { font-size: 21px; }
.stat-card .stat-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Chart cards --------------------------------------------------- */
/* Uniform card + canvas height so every card in a row matches.
   Note: style.css sets .card-body { flex: 1 } (basis 0%), which would
   grow the body and defeat a fixed height — so we pin flex-basis too. */
.chart-card, .map-card { display: flex; flex-direction: column; }
.chart-card .card-body { padding: 14px 16px; position: relative; height: 300px; min-height: 0; flex: 0 0 300px; }
.chart-card canvas { width: 100% !important; height: 100% !important; max-height: none; display: block; }

/* Compact 4-up chart row: hide chart legends below medium widths so the
   cards stay equal instead of wrapping/overflowing. */
@media (max-width: 1200px) {
    .dashboard-col-3 { grid-column: span 6; }
}
@media (max-width: 768px) {
    .dashboard-col-3,
    .dashboard-col-4,
    .dashboard-col-5,
    .dashboard-col-6,
    .dashboard-col-7 { grid-column: 1 / -1; }
    .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
    .stats-row { grid-template-columns: 1fr; }
}

.dashboard-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.dashboard-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}
.dashboard-grid-2 .span-2 { grid-column: 1 / -1; }

/* --- Map ----------------------------------------------------------- */
.map-card .card-body { padding: 0; height: 300px; min-height: 0; flex: 0 0 300px; }
#map {
    height: 100%;
    width: 100%;
    border-radius: 0 0 var(--radius) var(--radius);
    background: #E7EAEE;
}

/* --- Table card ---------------------------------------------------- */
.table-card .card-body { padding: 0; }
.table-card .data-table { min-width: 720px; }
.table-card .table-actions { display: flex; gap: 6px; }
.table-card .table-empty { text-align: center; padding: 42px 14px; color: var(--muted); font-size: 13px; }
.table-card .table-empty .lucide { display: block; min-width: 28px; margin: 0 auto 10px; opacity: .4; }

/* --- Row action buttons (colored per action) ------------------------ */
.table-actions .btn-icon-sm {
    width: 28px; height: 28px; border-radius: 8px; font-size: 13px;
    transition: all .15s; box-shadow: inset 0 0 0 1px rgba(255,255,255,.4);
}
.table-actions .btn-icon-sm .lucide { width: 14px; height: 14px; }
.table-actions .btn-icon-sm:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.15); }
.table-actions .btn-icon-sm:active { transform: translateY(0); }

/* View — accent blue */
.btn-icon-sm.btn-view { color: var(--accent); background: var(--accent-bg); }
.btn-icon-sm.btn-view:hover { background: var(--accent); color: #fff; }
.btn-icon-sm.btn-fleet { color: var(--ok); background: var(--ok-bg); }
.btn-icon-sm.btn-fleet:hover { background: var(--ok); color: #fff; }

/* Edit — amber/warning */
.btn-icon-sm.btn-edit { color: var(--warn); background: var(--warn-bg); }
.btn-icon-sm.btn-edit:hover { background: var(--warn); color: #fff; }

/* Delete — red/danger */
.btn-icon-sm.btn-delete { color: var(--danger); background: var(--danger-bg); }
.btn-icon-sm.btn-delete:hover { background: var(--danger); color: #fff; }

/* --- Read-only "View" modal ----------------------------------------- */
#dataModal .view-details.detail-list { padding: 4px 0 2px; max-height: 60vh; overflow-y: auto; }
#dataModal .view-details .detail-item { padding: 9px 0; }
#dataModal .view-details .detail-label { font-size: 12px; text-transform: none; letter-spacing: 0; }
#dataModal .view-details .detail-value { font-size: 13.5px; }

/* --- Pagination (page-item wrapper) -------------------------------- */
.pagination { flex-wrap: wrap; }
.pagination .page-item { list-style: none; }
.pagination .page-item.disabled .page-link { opacity: .5; pointer-events: none; }
.pagination .page-item .page-link { cursor: pointer; }

/* --- Loader -------------------------------------------------------- */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(245, 246, 248, .72);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
}
.loader-overlay.show { display: flex; }
.loader {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid var(--border-2);
    border-top-color: var(--accent);
    animation: fleet-spin .8s linear infinite;
}
@keyframes fleet-spin { to { transform: rotate(360deg); } }

/* --- Bootstrap modal, themed --------------------------------------- */
.modal-content { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 24px 60px rgba(0,0,0,.28); }
.modal-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.modal-body { padding: 16px; }
.modal-footer { padding: 10px 16px; border-top: 1px solid var(--border); gap: 8px; }
.modal-backdrop.show { opacity: .5; }

.modal .modal-actions { padding: 0 16px 16px; }
.modal-header h3 { display: flex; align-items: center; }
.modal-header h3 .lucide { color: var(--accent); }

/* --- Bootstrap form controls, themed ------------------------------- */
.form-label { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
.form-control, .form-select {
    width: 100%;
    height: 32px;
    padding: 0 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--ink);
    background-color: var(--surface);
    box-shadow: none;
}
.form-select { padding-right: 30px; }
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 107, 235, .12);
}
textarea.form-control { height: auto; min-height: 80px; padding: 8px 11px; }
.mb-3 { margin-bottom: 12px; }
.modal-body .mb-3:last-child { margin-bottom: 0; }

/* --- Bootstrap-style grid + form utilities ------------------------- */
.row { display: flex; flex-wrap: wrap; gap: 0 14px; }
.row > [class*="col-"] { padding: 0; box-sizing: border-box; max-width: 100%; }
.row > .col-md-6 { width: calc(50% - 7px); }
@media (max-width: 640px) {
    .row > .col-md-6 { width: 100%; }
}
.modal-lg { max-width: 720px; }
.text-danger { color: var(--danger); }
.form-text { display: block; font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.alert {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 12.5px;
    line-height: 1.5;
    background: var(--canvas);
}
.alert-info { background: rgba(2, 122, 188, .07); border-color: rgba(2, 122, 188, .22); }
.d-none { display: none !important; }

/* --- Select2 tweaks ------------------------------------------------- */
.select2-container { width: 100% !important; }
.select2-container--bootstrap-5 .select2-selection { min-height: 38px; border-color: var(--border); border-radius: var(--radius-sm); }
.select2-container--bootstrap-5 .select2-selection--single { display: flex; align-items: center; }
.select2-container--bootstrap-5 .select2-selection--multiple { padding: 3px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 0; }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-search--inline { height: auto; margin: 0; padding: 0 2px; flex: 1 1 80px; }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-search--inline .select2-search__field { margin: 0; height: 26px; line-height: 26px; padding: 0 2px; }
.modal .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered .select2-selection__choice {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px 2px 6px; border: 1px solid rgba(47, 150, 235, .35);
    background: rgba(47, 150, 235, .10); color: var(--text);
    border-radius: 999px; font-size: 12px; line-height: 1.4; margin: 1px;
}
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove { border: none; color: var(--muted); }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove:hover { color: var(--danger); background: transparent; }
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__placeholder { color: var(--muted); margin: 0 2px 4px; }
.select2-container--bootstrap-5 .select2-selection:focus,
.select2-container--bootstrap-5.select2-container--focus .select2-selection {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 107, 235, .12);
}
.select2-container .select2-dropdown { border-color: var(--border); border-radius: var(--radius-sm); box-shadow: 0 10px 30px rgba(20, 23, 28, .12); }
.select2-container .select2-search__field:focus { outline: none; }
.form-control.is-invalid, .form-select.is-invalid,
.select2-container.is-invalid .select2-selection,
.select2-container--bootstrap-5.is-invalid .select2-selection {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(229, 62, 62, .12);
}

.invalid-feedback {
    display: block;
    width: 100%;
    margin-top: 4px;
    font-size: 12px;
    color: var(--danger);
}

/* --- Access-features dropdown in the topbar ------------------------ */
.tb-dd-menu .tb-dd-opt.danger { color: var(--danger); }
.tb-dd-menu .tb-dd-opt.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* --- Column picker options ----------------------------------------- */
.col-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
}
.col-opt:hover { background: var(--accent-bg); color: var(--accent-ink); }
.col-opt input { accent-color: var(--accent); }

/* --- Utilities ----------------------------------------------------- */
.hidden { display: none !important; }

/* --- Print --------------------------------------------------------- */
@media print {
    body * { visibility: hidden; }
    #printable-table, #printable-table * { visibility: visible; }
    #printable-table { position: absolute; left: 0; top: 0; width: 100%; }
    .no-print { display: none !important; }
}

/* --- Inventory page ------------------------------------------------ */
.iv-seg {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--canvas);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
}
.iv-seg .iv-seg-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: none;
    background: transparent;
    border-radius: calc(var(--radius-sm) - 1px);
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.iv-seg .iv-seg-btn:hover { color: var(--ink); }
.iv-seg .iv-seg-btn.active { background: #fff; color: var(--accent-ink); box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }
.iv-seg .iv-seg-btn .lucide { width: 14px; height: 14px; }
.iv-seg.sm .iv-seg-btn { font-size: 12px; padding: 4px 10px; }

.iv-select { width: 170px; flex: 0 0 auto; }
@media (max-width: 760px) {
    .iv-select { width: 100%; }
}

.iv-panel .toolbar { margin-bottom: 10px; }
#stockTableWrap, #tranTableWrap { width: 100%; overflow-x: auto; }
.iv-panel .pagination { margin-top: 10px; }

/* Operations table: keep dense columns predictable and actions aligned. */
#opsTable { width: 100%; min-width: 760px; table-layout: fixed; }
#opsTable th, #opsTable td { padding: 6px 8px; white-space: nowrap; }
#opsTable th:nth-child(1), #opsTable td:nth-child(1) { width: 48px; }
#opsTable th:nth-child(2), #opsTable td:nth-child(2) { width: 200px; }
#opsTable th:nth-child(3), #opsTable td:nth-child(3) { width: 148px; }
#opsTable th:nth-child(4), #opsTable td:nth-child(4) { width: 80px; }
#opsTable th:nth-child(5), #opsTable td:nth-child(5) { width: 140px; }
#opsTable th:nth-child(6), #opsTable td:nth-child(6) { width: 104px; }
#opsTable th:nth-child(7), #opsTable td:nth-child(7) { width: 116px; }
#opsTable th:nth-child(8), #opsTable td:nth-child(8) { width: 140px; }
#opsTable th:nth-child(9), #opsTable td:nth-child(9) { width: auto; min-width: 84px; text-align: right; }
#opsTable .ops-operation { display: flex; min-width: 0; flex-direction: column; gap: 2px; }
#opsTable .ops-operation-type { color: var(--accent-ink); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; }
#opsTable .ops-operation-title { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
#opsTable .ops-name { display: inline-block; max-width: 100%; color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
#opsTable .ops-items-link { display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--accent-ink); font-size: 11.5px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; cursor: pointer; opacity: .92; transition: all .15s; }
#opsTable .ops-items-link:hover { border-color: var(--accent); background: var(--accent-bg); opacity: 1; }
#opsTable td:nth-child(2), #opsTable td:nth-child(5) { overflow: hidden; text-overflow: ellipsis; }
#opsTable .status-quick-change { max-width: 132px; }
#opsTable .table-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }
#opsTable .table-actions .btn-icon-sm { flex: 0 0 28px; }

@media (max-width: 1100px) {
    #opsTable { min-width: 0; }
    #opsTable th:nth-child(1), #opsTable td:nth-child(1),
    #opsTable th:nth-child(5), #opsTable td:nth-child(5) { display: none; }
    #opsTable th:nth-child(2), #opsTable td:nth-child(2) { width: 180px; }
    #opsTable th:nth-child(3), #opsTable td:nth-child(3) { width: 148px; }
}

@media (max-width: 760px) {
    #opsTable { min-width: 0; }
    #opsTable th:nth-child(4), #opsTable td:nth-child(4),
    #opsTable th:nth-child(8), #opsTable td:nth-child(8) { display: none; }
    #opsTable th:nth-child(2), #opsTable td:nth-child(2) { width: 170px; }
    #opsTable th:nth-child(3), #opsTable td:nth-child(3) { width: 146px; }
    #opsTable th:nth-child(6), #opsTable td:nth-child(6) { width: 88px; }
    #opsTable th:nth-child(7), #opsTable td:nth-child(7) { width: 110px; }
}

@media (max-width: 760px) {
    .iv-panel .toolbar { flex-wrap: wrap; }
    .iv-panel .toolbar .search-box { width: 100%; }
}

/* --- Login page ---------------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--canvas);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(20, 23, 28, .08);
    padding: 28px 26px 26px;
}
.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}
.login-brand img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.login-brand h1 { font-size: 17px; font-weight: 700; color: var(--ink); }
.login-brand .sub { font-size: 12px; color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-field { display: flex; flex-direction: column; gap: 5px; position: relative; }
.login-field label { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.login-field input {
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    background: var(--surface);
    color: var(--ink);
    width: 100%;
}
.login-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 107, 235, .12); }
.login-field .toggle-pw {
    position: absolute;
    right: 8px;
    bottom: 9px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
}
.login-card .btn-login {
    height: 38px;
    margin-top: 4px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.login-card .btn-login:hover { background: var(--accent-ink); }

/* --- Responsive ---------------------------------------------------- */
@media (max-width: 1100px) {
    .dashboard-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
    .dashboard-grid-2,
    .dashboard-grid-3 { grid-template-columns: 1fr; }
    #map { height: 340px; }
}

/* --- Stock Status chart toggle -------------------------------------- */
.stock-toggle { display: inline-flex; gap: 6px; flex-shrink: 0; }
.stock-toggle .btn { height: 20px; padding: 0 8px; font-size: 11px; line-height: 18px; }
.stock-toggle .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
