:root {
    --bg: #f5f7f8;
    --surface: #ffffff;
    --line: #dfe5e8;
    --text: #172026;
    --muted: #66737b;
    --primary: #176b5b;
    --primary-dark: #0f4f43;
    --accent: #b64f2d;
    --ok: #0d684d;
    --error: #9d2d2d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 28px;
    padding: 14px 28px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
}

.brand {
    color: var(--text);
    font-size: 18px;
}

.topbar nav,
.user-menu {
    display: flex;
    align-items: center;
    gap: 18px;
}

.user-menu {
    color: var(--muted);
    font-size: 14px;
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px;
}

.hero,
.section {
    margin-bottom: 28px;
}

.hero {
    padding: 34px 0 18px;
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 10px;
    font-size: 34px;
    line-height: 1.12;
}

h2 {
    margin-bottom: 16px;
    font-size: 23px;
}

h3 {
    margin-bottom: 6px;
    font-size: 20px;
}

.eyebrow {
    margin-bottom: 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

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

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stats article,
.panel,
.item-card,
.equipment-card,
.login-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.stats article {
    padding: 20px;
}

.stats span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.stats strong {
    display: block;
    margin-top: 8px;
    font-size: 32px;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.compact-head {
    align-items: center;
    margin-bottom: 14px;
}

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

.data-table-wrap {
    padding: 14px;
}

.table-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.table-toolbar label {
    width: min(360px, 100%);
}

.data-table-wrap .dt-container {
    color: var(--text);
}

.data-table-wrap .dt-layout-row {
    align-items: center;
    gap: 14px;
    margin: 0 0 12px;
}

.data-table-wrap .dt-layout-row:last-child {
    margin: 12px 0 0;
}

.data-table-wrap .dt-search,
.data-table-wrap .dt-length,
.data-table-wrap .dt-info {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.data-table-wrap .dt-input {
    min-height: 38px;
    margin-left: 8px;
    border: 1px solid #cad3d7;
    border-radius: 7px;
    padding: 8px 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

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

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--primary);
    border-radius: 7px;
    background: var(--primary);
    color: white;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.icon-button {
    width: 40px;
    padding: 0;
}

.button.secondary,
button.secondary {
    background: white;
    color: var(--primary);
}

button.danger {
    border-color: var(--error);
    background: white;
    color: var(--error);
}

button:disabled {
    border-color: var(--line);
    background: #eef2f3;
    color: var(--muted);
    cursor: not-allowed;
}

button.is-loading {
    gap: 9px;
}

button.is-loading::before {
    content: "";
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.item-card {
    display: grid;
    min-height: 170px;
    gap: 12px;
    padding: 20px;
}

.item-actions,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.table-actions {
    justify-content: flex-end;
}

.inline-delete-form {
    display: inline-flex;
}

.inline-delete-form .danger {
    border-color: var(--error);
    background: var(--error);
    color: white;
}

.inline-delete-form .danger:disabled {
    border-color: var(--line);
    background: #eef2f3;
    color: var(--muted);
}

.split-actions {
    justify-content: flex-end;
}

.delete-form {
    display: flex;
    justify-content: flex-end;
}

.code {
    display: inline-block;
    margin-bottom: 10px;
    padding: 5px 9px;
    border-radius: 6px;
    background: #e8f2ef;
    color: var(--primary-dark);
    font-weight: 800;
}

.two-col {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 18px;
}

.panel {
    padding: 20px;
}

.form-panel {
    margin-bottom: 18px;
}

.modal {
    width: min(620px, calc(100vw - 36px));
    max-height: calc(100vh - 56px);
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 20px;
    background: var(--surface);
    color: var(--text);
    overflow: auto;
}

.modal::backdrop {
    background: rgba(23, 32, 38, 0.48);
}

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

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.modal-head h2 {
    margin-bottom: 0;
}

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

.form-grid.two-fields {
    grid-template-columns: minmax(160px, 0.35fr) 1fr;
}

.details {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 10px 18px;
    margin: 0;
}

.details dt {
    color: var(--muted);
    font-weight: 800;
}

.details dd {
    margin: 0;
}

.stack {
    display: grid;
    gap: 14px;
}

.stack.compact {
    gap: 10px;
}

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

input,
textarea,
select {
    width: 100%;
    border: 1px solid #cad3d7;
    border-radius: 7px;
    padding: 10px 11px;
    color: var(--text);
    font: inherit;
}

textarea {
    resize: vertical;
}

.equipment-list {
    display: grid;
    gap: 16px;
}

.equipment-card {
    display: grid;
    grid-template-columns: 260px 1fr;
    overflow: hidden;
}

.equipment-media {
    display: grid;
    min-height: 230px;
    place-items: center;
    background: #e8ecef;
    color: var(--muted);
    font-weight: 800;
}

.equipment-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-gallery {
    display: grid;
    width: 100%;
    height: 100%;
    min-height: 230px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
}

.photo-gallery img {
    height: 110px;
    min-height: 0;
    border-radius: 4px;
}

.equipment-body {
    display: grid;
    gap: 12px;
    padding: 18px;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.inline-form input {
    max-width: 360px;
}

.report {
    border-left: 4px solid var(--primary);
    background: #f0f6f4;
    padding: 14px;
}

.report-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.report-head h4 {
    margin-bottom: 0;
}

.markdown-report {
    display: grid;
    gap: 10px;
}

.markdown-report h3,
.markdown-report h4,
.markdown-report h5,
.markdown-report p,
.markdown-report ul {
    margin: 0;
}

.markdown-report h3 {
    margin-top: 4px;
    font-size: 18px;
}

.markdown-report h4 {
    margin-top: 4px;
    font-size: 16px;
}

.markdown-report h5 {
    color: var(--text);
    font-size: 14px;
}

.markdown-report ul {
    padding-left: 22px;
}

.markdown-report li + li {
    margin-top: 5px;
}

.markdown-report pre {
    margin: 0;
    white-space: pre-wrap;
    font-family: inherit;
}

.alert {
    margin-bottom: 16px;
    border-radius: 7px;
    padding: 12px 14px;
    font-weight: 700;
}

.alert.success {
    background: #e8f5ef;
    color: var(--ok);
}

.alert.error {
    background: #f9e8e8;
    color: var(--error);
}

.login-page {
    min-height: 100vh;
    background:
        linear-gradient(rgba(23, 32, 38, 0.62), rgba(23, 32, 38, 0.62)),
        url("https://images.unsplash.com/photo-1556911220-e15b29be8c8f?auto=format&fit=crop&w=1800&q=80") center/cover;
}

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

.login-panel {
    width: min(420px, 100%);
    padding: 28px;
}

@media (max-width: 820px) {
    .topbar {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .page {
        padding: 18px;
    }

    .stats,
    .two-col,
    .equipment-card,
    .form-grid,
    .form-grid.two-fields {
        grid-template-columns: 1fr;
    }

    .details {
        grid-template-columns: 1fr;
    }
}
