:root {
    color-scheme: light;
    font-family: "IBM Plex Sans", "Segoe UI", Tahoma, sans-serif;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-muted: #f8fafb;
    --text: #121a24;
    --muted: #5d6978;
    --line: #d7dee6;
    --accent: #1a5fd0;
    --accent-hover: #154ca8;
    --danger: #b42318;
    --danger-hover: #8e1e16;
    --ok-bg: #ecfdf3;
    --ok-line: #9dd7b0;
    --ok-text: #0f6c2f;
    --error-bg: #fef3f2;
    --error-line: #f2a8a3;
    --error-text: #b42318;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(180deg, #f8fafb 0%, var(--bg) 100%);
    color: var(--text);
}

.container {
    width: min(1080px, 94vw);
    margin: 32px auto;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-wide {
    padding: 28px;
}

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

.page-title-row h1 {
    margin: 0;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.page-actions .logout-form {
    margin-top: 0;
    display: block;
}

h1 {
    margin: 0 0 16px;
    font-size: clamp(1.6rem, 3vw, 2.05rem);
    line-height: 1.2;
}

h2 {
    margin: 0;
    font-size: 1.02rem;
    line-height: 1.3;
}

h3 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.3;
}

p {
    margin: 0;
    line-height: 1.45;
}

label {
    font-size: 0.94rem;
    font-weight: 600;
}

input,
select,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid #c8d2de;
    background: #fff;
    color: var(--text);
}

input:focus,
select:focus,
button:focus,
a.button-link:focus,
.back-link:focus,
.icon-button:focus {
    outline: 2px solid rgba(26, 95, 208, 0.28);
    outline-offset: 2px;
}

button,
a.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: fit-content;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

button:hover,
a.button-link:hover {
    background: var(--accent-hover);
}

button.secondary,
a.button-link.secondary {
    background: #4f5e70;
}

button.secondary:hover,
a.button-link.secondary:hover {
    background: #3f4d5e;
}

button.danger,
a.button-link.danger {
    background: var(--danger);
}

button.danger:hover,
a.button-link.danger:hover {
    background: var(--danger-hover);
}

button.ghost,
a.button-link.ghost {
    background: transparent;
    color: var(--muted);
    border-color: #d1d9e2;
}

button.ghost:hover,
a.button-link.ghost:hover {
    background: #f2f5f8;
    color: var(--text);
}

.section {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    padding: 14px;
    margin-bottom: 14px;
}

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

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 2px 0 14px;
}

.back-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.back-link:hover {
    text-decoration: underline;
}

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

.toolbar-between {
    justify-content: space-between;
}

form {
    display: grid;
    gap: 10px;
}

.logout-form {
    margin-top: 14px;
}

.logout-form-top {
    margin-top: 0;
}

.metrics {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    margin-bottom: 14px;
}

.metric {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--surface-muted);
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
}

.metric strong {
    font-size: 1.1rem;
}

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

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 660px;
}

.table th,
.table td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid #e3e9f0;
    vertical-align: middle;
}

.table th {
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 600;
    white-space: nowrap;
}

.table td a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.table td a:hover {
    text-decoration: underline;
}

.table td a.button-link,
.table td a.button-link:hover,
.table td a.button-link:visited {
    color: #fff;
    text-decoration: none;
    font-weight: 500;
}

.table th.actions-col,
.table td.actions-col {
    text-align: right;
}

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

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

.thumb {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid #d7dee8;
    background: #fff;
}

.status {
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-weight: 600;
    margin-bottom: 12px;
}

.status.ok {
    background: var(--ok-bg);
    border: 1px solid var(--ok-line);
    color: var(--ok-text);
}

.status.error {
    background: var(--error-bg);
    border: 1px solid var(--error-line);
    color: var(--error-text);
}

.error {
    color: var(--error-text);
    font-weight: 600;
}

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

.indicator {
    color: var(--muted);
    font-size: 0.88rem;
    white-space: nowrap;
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-flex;
}

.modal {
    width: min(520px, calc(100vw - 24px));
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 0;
    box-shadow: 0 18px 44px rgba(10, 20, 35, 0.22);
    background: var(--surface);
    color: var(--text);
}

.modal::backdrop {
    background: rgba(11, 18, 32, 0.38);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid #e4eaf1;
}

.icon-button {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #d4dce7;
    background: #fff;
    color: var(--muted);
    line-height: 1;
    font-size: 1.1rem;
}

.icon-button:hover {
    background: #f1f4f8;
}

.modal-form {
    padding: 14px 16px 16px;
    gap: 10px;
}

.modal-text {
    padding: 14px 16px 0;
    color: var(--text);
}

.modal-actions {
    margin-top: 4px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 780px) {
    .container {
        width: min(1080px, 96vw);
        margin: 20px auto;
    }

    .page-actions {
        justify-content: flex-start;
    }

    .card,
    .card-wide {
        padding: 18px;
    }

    .section {
        padding: 12px;
    }

    .table {
        min-width: 600px;
    }

    .page-header,
    .section-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .toolbar-between {
        align-items: flex-start;
        flex-direction: column;
    }

    .modal {
        width: calc(100vw - 16px);
    }
}
