:root {
    --ink: #172033;
    --muted: #6c778b;
    --line: #dce3ee;
    --panel: #ffffff;
    --surface: #f4f7fb;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --accent: #2563eb;
    --danger-soft: #f8d7da;
    --warning-soft: #fff3cd;
}

html, body { min-height: 100%; }
html { overflow-x: hidden; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--surface);
    font-family: "Segoe UI", Arial, sans-serif;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr);
}

.app-sidebar {
    background: #0b2433;
    color: #e7f6f4;
    padding: 24px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.sidebar-toggle,
.sidebar-close,
.sidebar-backdrop { display: none; }

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    text-decoration: none;
    margin-bottom: 28px;
}
.brand:hover { color: #fff; }
.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--primary);
    font-size: 24px;
    font-weight: 800;
}
.brand-mark img {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: contain;
    background: #fff;
}
.brand small {
    display: block;
    color: #a8c7c4;
    font-size: 12px;
    margin-top: 2px;
}

.app-nav { display: grid; gap: 6px; }
.app-nav a {
    color: #d8e8e6;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: 600;
}
.app-nav a:hover {
    background: rgba(255, 255, 255, .09);
    color: #fff;
}
.nav-section {
    color: #87aaa6;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    margin: 16px 12px 4px;
}

.app-main {
    min-width: 0;
    width: 100%;
}
.topbar {
    min-height: 86px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .92);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar-heading {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 14px;
}
.topbar-heading > div { min-width: 0; }
.topbar h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 750;
    overflow-wrap: anywhere;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.user-chip {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 12px;
    background: #fff;
    color: var(--muted);
    font-weight: 600;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.profile-avatar {
    width: 38px;
    height: 38px;
    display: inline-grid;
    place-items: center;
    border: 1px solid #cbd8ce;
    border-radius: 50%;
    background: #eef8f0;
    color: #163d2c;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(22, 61, 44, .22);
}
.profile-avatar:hover, .profile-avatar:focus { background: #e2f2e6; outline: 2px solid rgba(35, 105, 72, .15); }
.profile-avatar-small { width: 34px; height: 34px; font-size: 13px; box-shadow: none; }
.profile-notification-badge {
    position: absolute;
    top: -5px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 2px 5px;
    border: 2px solid #fff;
    border-radius: 10px;
    background: #dc3545;
    color: #fff;
    font-size: 10px;
}
.account-menu { width: min(350px, calc(100vw - 24px)); overflow: hidden; }
.account-menu-header { display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.account-menu-header div { display: flex; flex-direction: column; min-width: 0; }
.account-menu-header strong { overflow: hidden; text-overflow: ellipsis; }
.account-menu-header small { color: var(--muted); }
.account-menu-title { padding: 10px 14px 5px; color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.notification-list { max-height: 260px; overflow-y: auto; padding: 4px 8px 10px; }
.notification-list:empty { display: none; }
.account-menu-footer { border-top: 1px solid var(--line); padding: 6px; }
.account-menu-footer a { display: block; padding: 8px 10px; border-radius: 7px; color: #b42318; text-decoration: none; font-weight: 650; }
.account-menu-footer a:hover { background: #fff1f0; }
.account-menu-footer .account-menu-link { color: var(--ink); }
.account-menu-footer .account-menu-link:hover { background: var(--surface); }

.content-area {
    width: 100%;
    max-width: 1600px;
    margin-inline: auto;
    padding: 28px;
}
.logo-upload-panel {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}
.logo-preview {
    display: grid;
    place-items: center;
    flex: 0 0 92px;
    width: 92px;
    height: 92px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--primary);
    font-size: 40px;
    font-weight: 800;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.page-heading h2,
.page-heading h3 {
    margin: 0;
    font-size: 24px;
    font-weight: 760;
}
.eyebrow {
    display: block;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 4px;
}

.card, .data-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(23, 32, 51, .06);
    background: var(--panel);
}
.data-panel { padding: 14px; }
.card-header {
    border-top-left-radius: 8px !important;
    border-top-right-radius: 8px !important;
}

.btn-primary,
.btn-purple {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-primary:hover,
.btn-purple:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.bg-purple, .table-purple {
    background: #0b2433 !important;
    color: #fff;
}

.table {
    --bs-table-striped-bg: #f8fafc;
    margin-bottom: 0;
}
.table thead th {
    background: #eef4f7;
    color: #254256;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--line);
}
.table-purple th {
    background: #0b2433 !important;
    color: #fff !important;
}
.table-responsive {
    width: 100%;
    font-size: 14px;
    -webkit-overflow-scrolling: touch;
}
.table-responsive > .table { min-width: 720px; }
.table td,
.table th { vertical-align: middle; }
.table td { overflow-wrap: anywhere; }

/* Shared data grid: compact rows and contained scrolling on every list page. */
.app-table-panel { padding: 0; overflow: hidden; }
.app-table-scroll {
    max-height: 610px;
    overflow: auto;
    scrollbar-gutter: stable;
}
.app-data-table {
    min-width: 1100px !important;
    width: max-content;
    table-layout: auto;
    font-size: 12px;
}
.app-data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}
.app-data-table thead th {
    height: 42px;
    padding: 8px 12px;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
    font-size: 12px;
    font-weight: 700;
    color: #172033;
    background: #eef0ff;
    border-right: 1px solid #d8dced;
}
.app-data-table tbody td {
    height: 42px;
    padding: 7px 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    overflow-wrap: normal;
    border-bottom: 1px solid #e3e7ee;
}
.app-data-table tbody tr:nth-child(even) > * { background: #fbfcfe; }
.app-data-table tbody tr:hover > * { background: #f4f7ff; }
.app-data-table tbody td { max-width: 260px; }
.app-data-table .btn-sm {
    min-height: 30px;
    height: 30px;
    padding-top: 3px;
    padding-bottom: 3px;
    font-size: 12px;
}
.app-data-table.dashboard-report-table {
    min-width: 2820px !important;
    width: 2820px;
    table-layout: fixed;
}
.machine-data-table { min-width: 1450px !important; }
.dashboard-report-table th:nth-child(1), .dashboard-report-table td:nth-child(1) { width: 105px; }
.dashboard-report-table th:nth-child(2), .dashboard-report-table td:nth-child(2) { width: 145px; }
.dashboard-report-table th:nth-child(3), .dashboard-report-table td:nth-child(3) { width: 125px; }
.dashboard-report-table th:nth-child(4), .dashboard-report-table td:nth-child(4) { width: 175px; }
.dashboard-report-table th:nth-child(5), .dashboard-report-table td:nth-child(5) { width: 145px; }
.dashboard-report-table th:nth-child(6), .dashboard-report-table td:nth-child(6) { width: 105px; }
.dashboard-report-table th:nth-child(7), .dashboard-report-table td:nth-child(7) { width: 110px; }
.dashboard-report-table th:nth-child(8), .dashboard-report-table td:nth-child(8) { width: 130px; }
.dashboard-report-table th:nth-child(9), .dashboard-report-table td:nth-child(9) { width: 180px; }
.dashboard-report-table th:nth-child(10), .dashboard-report-table td:nth-child(10) { width: 140px; }
.dashboard-report-table th:nth-child(11), .dashboard-report-table td:nth-child(11) { width: 145px; }
.dashboard-report-table th:nth-child(12), .dashboard-report-table td:nth-child(12) { width: 145px; }
.dashboard-report-table th:nth-child(13), .dashboard-report-table td:nth-child(13) { width: 190px; }
.dashboard-report-table th:nth-child(14), .dashboard-report-table td:nth-child(14) { width: 240px; }
.dashboard-report-table th:nth-child(15), .dashboard-report-table td:nth-child(15) { width: 75px; }
.dashboard-report-table th:nth-child(16), .dashboard-report-table td:nth-child(16) { width: 95px; }
.dashboard-report-table th:nth-child(17), .dashboard-report-table td:nth-child(17) { width: 230px; overflow: visible; }
.dashboard-report-table th:nth-child(18), .dashboard-report-table td:nth-child(18) { width: 205px; overflow: visible; }
.dashboard-report-table th:nth-child(19), .dashboard-report-table td:nth-child(19) { width: 190px; overflow: visible; }
.dashboard-report-table .badge { font-size: 10px; }
.dashboard-status-form,
.dashboard-actions { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.dashboard-hide-form { margin: 0; }
.dashboard-status-form .form-select { width: 128px; }
.dashboard-status-form .form-select,
.dashboard-status-form .btn,
.dashboard-actions .btn { min-height: 30px; height: 30px; padding-top: 3px; padding-bottom: 3px; font-size: 12px; }

canvas {
    max-width: 100%;
    max-height: 360px;
}

img,
svg { max-width: 100%; }

.form-control,
.form-select,
.btn { min-height: 38px; }
.required-indicator {
    margin-left: 4px;
    color: #dc2626;
    font-weight: 800;
}
.field-validation-error {
    display: block;
    margin-top: 4px;
    font-size: 12px;
}
.machine-registration-form .is-invalid {
    border-color: #dc2626;
    background-color: #fffafa;
}

.login-wrapper {
    min-height: calc(100vh - 160px);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card { width: 100%; max-width: 420px; }

.priority-high { background: #dc2626; }
.priority-medium { background: #facc15; color: #1f2937; }
.priority-low { background: #16a34a; }
.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 700;
    background: #e2e8f0;
    color: #334155;
}
.status-updated,
.status-assigned { background: #dcfce7; color: #166534; }
.status-deleted,
.status-removed { background: #fee2e2; color: #991b1b; }

.table-striped > tbody > tr.machine-row-warning > * { background-color: var(--warning-soft); }
.table-striped > tbody > tr.machine-row-expired > * { background-color: var(--danger-soft); }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(82vw, 300px);
        height: 100dvh;
        padding: 22px 18px;
        box-shadow: 18px 0 45px rgba(2, 12, 20, .28);
        transform: translateX(-105%);
        transition: transform .22s ease;
    }
    .sidebar-open .app-sidebar { transform: translateX(0); }
    .sidebar-close {
        display: grid;
        place-items: center;
        position: absolute;
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
        padding: 0;
        border: 0;
        border-radius: 8px;
        background: rgba(255, 255, 255, .1);
        color: #fff;
        font-size: 28px;
        line-height: 1;
    }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 20;
        width: 100%;
        height: 100%;
        border: 0;
        background: rgba(3, 14, 23, .52);
    }
    .sidebar-open .sidebar-backdrop { display: block; }
    .sidebar-open { overflow: hidden; }
    .brand { padding-right: 38px; }
    .sidebar-toggle {
        display: inline-flex;
        flex: 0 0 auto;
        width: 42px;
        height: 42px;
        padding: 10px;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #fff;
    }
    .sidebar-toggle span {
        display: block;
        width: 100%;
        height: 2px;
        border-radius: 2px;
        background: var(--ink);
    }
    .topbar {
        min-height: 72px;
        padding: 13px 18px;
    }
    .topbar-actions .user-chip { display: none; }
    .content-area { padding: 18px; }
    .login-wrapper { min-height: calc(100dvh - 116px); }
}

@media (max-width: 575.98px) {
    .logo-upload-panel { align-items: stretch; flex-direction: column; }
    .topbar {
        gap: 10px;
        padding: 10px 12px;
    }
    .topbar h1 { font-size: 17px; }
    .topbar .eyebrow {
        max-width: 180px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .topbar-actions { flex: 0 0 auto; }
    .topbar-actions .btn {
        min-height: 38px;
        padding-inline: 10px;
    }
    .content-area { padding: 14px 12px 24px; }
    .page-heading {
        align-items: stretch;
        flex-direction: column;
        margin-bottom: 14px;
    }
    .page-heading h2,
    .page-heading h3 { font-size: 21px; }
    .page-heading > .btn { width: 100%; }
    .card-body.p-4 { padding: 18px !important; }
    .data-panel {
        margin-inline: -12px;
        padding: 8px 0;
        border-radius: 0;
        border-inline: 0;
    }
    .table-responsive { padding-bottom: 4px; }
    .table-responsive > .table { min-width: 680px; }
    .table th,
    .table td {
        padding: .65rem .7rem;
        white-space: nowrap;
    }
    .table td { max-width: 240px; }
    .table td form.d-flex {
        min-width: 210px;
        flex-wrap: nowrap;
    }
    form > .btn[type="submit"]:not(.btn-sm),
    .card-body > form > .btn:last-child { width: 100%; }
    .login-card { max-width: none; }
    .login-wrapper { align-items: flex-start; padding-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar { transition: none; }
}
