:root {
    --bg: #eef3f7;
    --bg-soft: #f7fafc;
    --panel: #ffffff;
    --panel-subtle: #fbfdff;
    --text: #17212b;
    --muted: #637083;
    --muted-2: #8a96a7;
    --line: #dce4ec;
    --line-strong: #c7d2de;
    --primary: #176b87;
    --primary-dark: #0d455c;
    --primary-soft: #e8f6fb;
    --blue: #176bff;
    --blue-soft: #eaf2ff;
    --nav: #0f2230;
    --nav-2: #163447;
    --ok: #12805c;
    --ok-soft: #e7f7ef;
    --danger: #c0392b;
    --danger-soft: #fdecea;
    --warn: #b7791f;
    --warn-soft: #fff4dc;
    --shadow: 0 18px 45px rgba(20, 38, 55, 0.09);
    --shadow-soft: 0 8px 24px rgba(20, 38, 55, 0.06);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
    color: var(--text);
    line-height: 1.5;
    background:
        linear-gradient(180deg, rgba(23, 107, 135, 0.08), rgba(238, 243, 247, 0) 320px),
        var(--bg);
}

a {
    color: inherit;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 268px;
    padding: 22px 16px;
    color: #fff;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0)),
        linear-gradient(160deg, var(--nav), var(--nav-2));
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 12px 0 34px rgba(15, 34, 48, 0.12);
}

.brand {
    display: grid;
    gap: 5px;
    padding: 4px 10px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong {
    font-size: 21px;
    line-height: 1.2;
}

.brand span {
    max-width: 190px;
    color: #b7c8d4;
    font-size: 13px;
}

nav {
    display: grid;
    gap: 7px;
    margin-top: 22px;
}

nav a {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: #d7e6ec;
    text-decoration: none;
    font-size: 14px;
    font-weight: 800;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

nav a:hover,
nav a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.1);
}

nav a.active {
    box-shadow: inset 3px 0 0 #6bd3ff;
}

.workspace {
    margin-left: 268px;
    padding: 30px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-header h1 {
    margin: 0;
    font-size: clamp(26px, 3vw, 36px);
    line-height: 1.1;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.run-monitoring {
    display: flex;
    align-items: end;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(220, 228, 236, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.run-monitoring label {
    min-width: 98px;
}

.run-monitoring input {
    height: 42px;
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.login-shell {
    width: min(440px, 100%);
}

.login-panel {
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.login-brand {
    display: grid;
    gap: 6px;
    margin-bottom: 22px;
}

.login-brand strong {
    color: var(--primary-dark);
    font-size: 24px;
}

.login-brand span {
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-form button {
    width: 100%;
    min-height: 44px;
}

.section-title {
    margin-bottom: 18px;
}

.section-title h2,
.section-title p {
    margin: 0;
}

.section-title h2 {
    font-size: 22px;
}

.section-title p {
    max-width: 780px;
    margin-top: 5px;
    color: var(--muted);
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    width: fit-content;
    max-width: 100%;
    margin: 0 0 18px;
    padding: 5px;
    background: #e4ebf1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.tabs a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 900;
}

.tabs a:hover,
.tabs a.active {
    color: var(--primary-dark);
    background: #fff;
    box-shadow: 0 5px 14px rgba(20, 38, 55, 0.08);
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stats article,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stats article {
    position: relative;
    min-height: 112px;
    padding: 18px;
    overflow: hidden;
}

.stats article::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(180deg, var(--primary), #52b788);
}

.stats span {
    display: block;
    margin-bottom: 3px;
    color: var(--primary-dark);
    font-size: 32px;
    font-weight: 900;
    line-height: 1;
}

.stats small {
    color: var(--muted);
    font-weight: 800;
}

.grid {
    display: grid;
    gap: 18px;
    margin-bottom: 18px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

h2 {
    margin: 0 0 16px;
    font-size: 20px;
    line-height: 1.25;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.panel-heading h2,
.panel-heading h3 {
    margin: 0;
}

.panel-heading button {
    width: auto;
    min-width: 136px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.device-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.model-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.wide {
    grid-column: 1 / -1;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.check input {
    width: auto;
}

input,
select,
textarea,
button {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    font: inherit;
}

input,
select,
textarea {
    color: var(--text);
    background: #fff;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 0;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(23, 107, 135, 0.14);
}

button,
.primary {
    cursor: pointer;
    color: #fff;
    background: linear-gradient(180deg, #1b7896, var(--primary-dark));
    border-color: var(--primary);
    font-weight: 900;
    transition: transform 0.12s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

button:hover,
.primary:hover {
    background: linear-gradient(180deg, #176b87, #09394d);
    box-shadow: 0 8px 18px rgba(13, 69, 92, 0.16);
}

button:active {
    transform: translateY(1px);
}

.primary {
    min-width: 170px;
}

.ghost {
    color: var(--primary-dark);
    background: #fff;
    border-color: var(--line-strong);
}

.ghost:hover {
    color: var(--primary-dark);
    background: var(--bg-soft);
    box-shadow: none;
}

.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    color: var(--primary-dark);
    background: #fff;
    border-color: var(--line);
    line-height: 1;
}

.icon:hover {
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-color: #b8dce8;
    box-shadow: none;
}

.edit-icon {
    font-size: 16px;
}

.check-icon {
    color: var(--ok);
    font-size: 18px;
}

.file-icon {
    color: var(--primary-dark);
    font-size: 16px;
}

.check-action {
    display: inline-grid;
    grid-template-columns: 1fr;
    grid-template-rows: 16px 12px;
    justify-items: center;
    align-items: center;
    gap: 0;
    width: 46px;
    min-width: 46px;
    height: 40px;
    min-height: 40px;
    padding: 4px 0;
    border-color: #c6ded5;
    background: #fff;
}

.check-action span {
    line-height: 1;
}

.check-action small {
    min-width: 0;
    color: var(--muted);
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
}

.danger-text {
    color: var(--danger);
}

.download-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 10px;
    color: var(--primary-dark);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 900;
}

.download-link:hover {
    background: var(--primary-soft);
    border-color: #b8dce8;
}

.uid-toggle {
    min-width: 70px;
    color: var(--primary-dark);
    background: #fff;
    border-color: var(--line-strong);
}

.uid-toggle:hover {
    background: var(--blue-soft);
    border-color: #b7cdfd;
    box-shadow: none;
}

.uid-toggle.active {
    color: #fff;
    background: var(--blue);
    border-color: var(--blue);
}

.uid-toggle.active:hover {
    background: #0d55d9;
}

.flash {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
    font-weight: 800;
}

.flash.error {
    border-color: #fecaca;
    background: #fff5f5;
    color: #991b1b;
}

.mini-list {
    display: grid;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.mini-list.no-divider {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.mini-list h3 {
    margin: 0;
    font-size: 15px;
}

.mini-list article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    background: var(--panel-subtle);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.mini-list strong,
.mini-list small {
    display: block;
}

.mini-list small {
    color: var(--muted);
}

.model-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

table {
    width: 100%;
    min-width: 1100px;
    border-collapse: separate;
    border-spacing: 0;
}

th,
td {
    padding: 12px 11px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: 0;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    color: var(--muted);
    background: #f3f7fa;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

tbody tr {
    transition: background 0.14s ease;
}

tbody tr:hover {
    background: #f8fbfd;
}

th:nth-child(10),
td:nth-child(10) {
    width: 72px;
    min-width: 72px;
    max-width: 72px;
    text-align: center;
}

th:nth-child(11),
td:nth-child(11) {
    width: 62px;
    min-width: 62px;
    max-width: 62px;
    text-align: center;
}

th:nth-child(12),
td:nth-child(12) {
    width: 92px;
    min-width: 92px;
    max-width: 92px;
}

th:nth-child(13),
td:nth-child(13) {
    position: sticky;
    right: 0;
    width: 184px;
    min-width: 184px;
    max-width: 184px;
    background: #fff;
    box-shadow: -8px 0 16px rgba(20, 38, 55, 0.06);
}

th:nth-child(13) {
    z-index: 2;
    background: #f3f7fa;
}

.data-table th {
    cursor: pointer;
    user-select: none;
}

.data-table th.sort-asc::after {
    content: " ^";
}

.data-table th.sort-desc::after {
    content: " v";
}

.datatable-toolbar,
.datatable-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}

.datatable-toolbar label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.datatable-toolbar select {
    width: 88px;
}

.datatable-toolbar input[type="search"] {
    width: min(340px, 44vw);
}

.datatable-footer {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.datatable-pages {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.datatable-pages button {
    width: auto;
    min-width: 34px;
    min-height: 34px;
    padding: 6px 9px;
    color: var(--primary-dark);
    background: #fff;
    border-color: var(--line);
}

.datatable-pages button:hover {
    background: var(--primary-soft);
    box-shadow: none;
}

.datatable-pages button.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.datatable-pages button:disabled {
    cursor: default;
    opacity: 0.5;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 78px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
}

.badge.ok {
    color: var(--ok);
    background: var(--ok-soft);
}

.badge.danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.badge.muted {
    color: var(--muted);
    background: #eef2f5;
}

.metric-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    min-height: 28px;
    padding: 4px 8px;
    border: 1px solid rgba(20, 38, 55, 0.12);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 900;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.metric-empty {
    color: var(--muted);
}

.gpu-summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
}

.gpu-summary strong {
    font-size: 13px;
}

.gpu-summary small {
    color: var(--muted);
}

.gpu-summary-button {
    width: auto;
    min-width: 44px;
    min-height: 32px;
    padding: 6px 10px;
    color: var(--primary-dark);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.gpu-summary-button:hover {
    background: var(--blue-soft);
    border-color: #b7cdfd;
    box-shadow: none;
}

.modal-body {
    padding: 20px;
}

.gpu-modal {
    width: min(820px, calc(100vw - 32px));
}

.server-file-modal {
    width: min(980px, calc(100vw - 32px));
}

.server-file {
    display: grid;
    gap: 18px;
}

.server-file section {
    padding: 14px;
    background: var(--panel-subtle);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.server-file h3 {
    margin: 0 0 12px;
    color: var(--primary-dark);
    font-size: 14px;
}

.server-file dl {
    display: grid;
    grid-template-columns: minmax(120px, 190px) 1fr;
    gap: 8px 14px;
    margin: 0;
}

.server-file dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.server-file dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
}

.file-table {
    overflow-x: auto;
}

.file-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.file-table th,
.file-table td {
    padding: 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.gpu-list {
    display: grid;
    gap: 12px;
}

.gpu-item {
    padding: 14px;
    background: var(--panel-subtle);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.gpu-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.gpu-item-head strong {
    white-space: nowrap;
}

.gpu-item-head span {
    color: var(--muted);
    text-align: right;
}

.gpu-item-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding-top: 12px;
}

.gpu-item-grid > div {
    display: grid;
    align-content: start;
    gap: 6px;
}

.gpu-item-grid small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.gpu-item-grid em {
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.actions form,
.actions button {
    min-width: 70px;
}

.actions .icon,
.actions .check-action {
    min-width: 42px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.row-actions button {
    width: auto;
}

.detail td,
.empty {
    color: var(--muted);
    background: var(--panel-subtle);
}

.empty {
    margin: 0;
    padding: 12px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
}

.alerts {
    display: grid;
    gap: 12px;
}

.alert {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-left: 4px solid var(--muted);
    border-radius: var(--radius);
}

.alert.open {
    border-left-color: var(--danger);
}

.alert p {
    margin: 8px 0;
}

.alert small {
    display: block;
    color: var(--muted);
}

.compact .alert {
    display: block;
}

.health-row {
    display: grid;
    grid-template-columns: 16px 48px 1fr;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.health-row:last-child {
    border-bottom: 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.ok {
    background: var(--ok);
}

.dot.danger {
    background: var(--danger);
}

.dot.muted {
    background: var(--muted);
}

.settings-panel {
    max-width: 980px;
}

.modal {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 30px 90px rgba(15, 34, 48, 0.35);
}

.modal-wide {
    width: min(1120px, calc(100vw - 32px));
}

.modal::backdrop {
    background: rgba(15, 34, 48, 0.55);
    backdrop-filter: blur(2px);
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
}

.modal-header h2 {
    margin: 0;
}

.modal form {
    padding: 20px;
}

.modal form.modal-delete {
    display: flex;
    justify-content: flex-start;
    padding: 16px 20px;
    background: #fff8f7;
    border-top: 1px solid var(--line);
}

.modal-delete button {
    width: auto;
    min-width: 150px;
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

.modal-delete button:hover {
    background: #9f2d23;
}

.modal-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 6px;
}

.modal-actions button {
    width: auto;
    min-width: 130px;
}

@media (max-width: 1180px) {
    .sidebar {
        position: static;
        width: auto;
    }

    .workspace {
        margin-left: 0;
        padding: 20px;
    }

    nav {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .stats,
    .model-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .device-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .sidebar {
        padding: 18px 14px;
    }

    nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .workspace {
        padding: 16px;
    }

    .page-header,
    .panel-heading,
    .datatable-toolbar,
    .datatable-footer,
    .modal-actions,
    .alert {
        display: grid;
    }

    .run-monitoring {
        display: grid;
    }

    .grid.two,
    .stats,
    .form-grid,
    .device-form,
    .model-form,
    .model-list,
    .gpu-item-grid {
        grid-template-columns: 1fr;
    }

    .panel {
        padding: 16px;
    }

    .panel-heading button,
    .modal-actions button,
    .datatable-toolbar input[type="search"] {
        width: 100%;
    }

    .datatable-toolbar label {
        align-items: stretch;
    }

    .gpu-item-head {
        display: grid;
    }

    .gpu-item-head span {
        text-align: left;
    }
}
