/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-light);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
}

.btn-danger {
    background: var(--color-red);
    color: #fff;
}

.btn-pill {
    height: 38px;
    padding: 0 var(--space-5);
    border-radius: var(--radius-pill);
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Card */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
}

.card-header h2 {
    font-size: inherit;
    font-weight: inherit;
}

.card-body {
    padding: var(--space-5);
}

.section-gap {
    margin-bottom: var(--space-5);
}

/* Stat strip - one card, multiple stat tiles (label + value + delta) */
.stat-strip {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-5) var(--space-6);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: var(--space-5) var(--space-6);
    margin-bottom: var(--space-6);
}

.stat-tile .stat-head {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
}

.stat-tile .stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
}

.stat-tile .stat-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.stat-tile .stat-delta-row {
    margin-top: var(--space-2);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.delta-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px var(--space-2) 1px 6px;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 700;
}

.delta-badge svg {
    width: 12px;
    height: 12px;
}

.delta-good { background: var(--color-green-bg); color: var(--color-green); }
.delta-bad { background: var(--color-red-bg); color: var(--color-red); }

.stat-tile .stat-delta-period {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Badge / status */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: var(--font-size-xs);
    font-weight: 600;
}

.badge-green { background: var(--color-green-bg); color: var(--color-green); }
.badge-yellow { background: var(--color-yellow-bg); color: var(--color-yellow); }
.badge-orange { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-red { background: var(--color-red-bg); color: var(--color-red); }
.badge-gray { background: var(--color-gray-bg); color: var(--color-gray); }

/* Table toolbar - search + filters above a data table */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.pill-input {
    flex: 1;
    min-width: 220px;
    max-width: 360px;
}

.pill-input input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font: inherit;
    color: var(--color-text);
    min-width: 0;
}

.pill-input input::placeholder {
    color: var(--color-text-muted);
}

.pill-select {
    appearance: none;
    -webkit-appearance: none;
    height: 38px;
    padding: 0 34px 0 var(--space-4);
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background-color: var(--color-bg);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6b6e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.table-toolbar-count {
    margin-left: auto;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* Table */
.data-table {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.data-table-scroll {
    overflow-x: auto;
}

.data-table table {
    width: 100%;
    font-size: var(--font-size-sm);
}

.data-table th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--color-border);
}

.data-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--color-bg);
}

.data-table .cell-primary {
    font-weight: 600;
}

.data-table .cell-muted {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.data-table .row-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: var(--color-text-muted);
}

.data-table .row-link svg {
    width: 16px;
    height: 16px;
}

.data-table tr:hover .row-link {
    background: var(--color-border);
    color: var(--color-text);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.pagination .page-btns {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.pill-sm {
    height: 32px;
    padding: 0 var(--space-3);
    font-size: var(--font-size-xs);
}

.pill:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pill:disabled:hover {
    background: var(--color-bg);
}

.page-num {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-pill);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}

.page-num.active {
    background: var(--color-primary);
    color: #fff;
}

/* Alert list */
.alert-list {
    display: flex;
    flex-direction: column;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-item:hover {
    background: var(--color-bg);
    cursor: pointer;
}

.alert-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-red { background: var(--status-critical); }
.dot-orange { background: var(--status-serious); }
.dot-yellow { background: var(--status-warning); }

.alert-item .alert-text {
    flex: 1;
}

.alert-item .alert-vehicle {
    font-weight: 600;
}

/* Chart card */
.chart-legend {
    display: flex;
    align-items: center;
    gap: var(--space-5);
}

.chart-legend .legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.chart-legend .legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.chart-legend .legend-value {
    font-weight: 700;
    color: var(--color-text);
}

.chart-svg .grid-line {
    stroke: var(--chart-grid);
    stroke-width: 1;
}

.chart-svg {
    width: 100%;
    height: auto;
}

.chart-svg .axis-label {
    fill: var(--color-text-muted);
    font-size: 11px;
}

.chart-svg .series-line {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-svg .series-area {
    opacity: 0.1;
}

.chart-svg .series-dot {
    stroke: var(--color-surface);
    stroke-width: 2;
}

/* Sortable table headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.data-table th.sortable:hover {
    color: var(--color-text);
}

.data-table th.sortable .sort-icon {
    width: 12px;
    height: 12px;
    margin-left: 4px;
    opacity: 0.35;
    vertical-align: -2px;
}

.data-table th.sortable.sort-asc .sort-icon,
.data-table th.sortable.sort-desc .sort-icon {
    opacity: 1;
}

.data-table th.sortable.sort-desc .sort-icon {
    transform: rotate(180deg);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: 100;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-sm {
    max-width: 420px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-size: var(--font-size-lg);
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.modal-close:hover {
    background: var(--color-bg);
}

.modal-close svg {
    width: 18px;
    height: 18px;
}

.modal-body {
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
}

.modal-footer .footer-start {
    margin-right: auto;
}

/* Forms */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.form-control {
    width: 100%;
    height: 38px;
    padding: 0 var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    background: var(--color-surface);
}

.form-control:focus-visible {
    border-color: var(--color-primary);
}

.form-error {
    margin-top: var(--space-2);
    font-size: var(--font-size-xs);
    color: var(--color-red);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

/* Read-only detail rows (view modal) */
.detail-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-row .detail-label {
    color: var(--color-text-muted);
}

.detail-row .detail-value {
    font-weight: 600;
    text-align: right;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: var(--space-5);
    right: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 200;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--color-text);
    color: #fff;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: var(--font-size-sm);
    animation: toast-in 0.18s ease;
}

.toast svg {
    width: 16px;
    height: 16px;
    color: var(--status-good);
    flex-shrink: 0;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Office cards */
.office-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-4);
}

.office-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    cursor: pointer;
}

.office-card:hover {
    border-color: var(--color-primary-light);
}

.office-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.office-card-title {
    font-size: var(--font-size-md);
    font-weight: 700;
}

.office-card-code {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.office-card-meta {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.office-card-meta .meta-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.office-card-meta svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--color-text-faint);
}

.office-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}

.office-stat .value {
    font-size: 20px;
    font-weight: 700;
}

.office-stat.stat-warn .value {
    color: var(--color-red);
}

.office-stat .label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Vehicle mini-list (used in the office view modal) */
.mini-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.mini-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
}

.mini-list a:last-child {
    border-bottom: none;
}

.mini-list a:hover {
    background: var(--color-bg);
}

/* Vehicle profile header */
.vehicle-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-3);
}

.back-link:hover {
    color: var(--color-text);
}

.back-link svg {
    width: 14px;
    height: 14px;
}

.vehicle-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.vehicle-header .vehicle-model {
    font-size: var(--font-size-md);
    color: var(--color-text-muted);
    margin-top: 2px;
}

.vehicle-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-6);
    margin-top: var(--space-4);
}

.vehicle-facts .fact-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.vehicle-facts .fact-value {
    font-size: var(--font-size-md);
    font-weight: 700;
    margin-top: 2px;
}

/* Tabs */
.tabs-bar {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-5);
}

.tab-btn {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab-btn:hover {
    color: var(--color-text);
}

.tab-btn.active {
    color: var(--color-primary-dark);
    border-bottom-color: var(--color-primary);
}


/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-7) var(--space-5);
    color: var(--color-text-muted);
    text-align: center;
    gap: var(--space-2);
}

/* Global search (Ctrl/Cmd+K palette), injected by search.js on every page */
.search-overlay {
    align-items: flex-start;
    padding-top: 12vh;
}

.search-palette {
    max-width: 560px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.search-palette-input {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.search-palette-input svg {
    width: 18px;
    height: 18px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.search-palette-input input {
    flex: 1;
    border: none;
    outline: none;
    font-size: var(--font-size-md);
    background: transparent;
    color: var(--color-text);
}

.search-palette-input .kbd {
    font-size: 11px;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 1px 6px;
    flex-shrink: 0;
}

.search-palette-results {
    overflow-y: auto;
    padding: var(--space-2);
}

.search-result-group {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-faint);
    padding: var(--space-3) var(--space-3) var(--space-1);
}

.search-result-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.search-result-row svg {
    width: 18px;
    height: 18px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.search-result-row.active,
.search-result-row:hover {
    background: var(--color-bg);
}

.search-result-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
}

.search-result-meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.search-empty {
    padding: var(--space-5);
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}
