:root {
    --bg: #f5f6f7;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --text: #15171a;
    --muted: #6b7280;
    --muted-strong: #4b5563;
    --line: #e1e5ea;
    --line-strong: #cfd6df;
    --primary: #145c52;
    --primary-hover: #0f493f;
    --primary-soft: #e7f1ef;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --success-bg: #eaf7ee;
    --success-text: #14733f;
    --warning-bg: #fff5d7;
    --warning-text: #73510a;
    --error-bg: #fff1f0;
    --error-text: #a11f17;
    --shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    color-scheme: light;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.topbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    padding: 0 34px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-size: 18px;
    font-weight: 650;
    text-decoration: none;
    letter-spacing: 0;
}

.brand::before {
    content: "";
    width: 10px;
    height: 28px;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: inset 0 -10px 0 rgba(255, 255, 255, 0.18);
}

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

nav a,
nav button {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    border: 0;
    border-radius: 6px;
    padding: 7px 11px;
    background: transparent;
    color: var(--muted-strong);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
}

nav a:hover,
nav button:hover {
    background: var(--surface-soft);
    color: var(--text);
}

.shell {
    width: min(1160px, calc(100% - 36px));
    margin: 26px auto 42px;
}

.panel,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    margin: 88px auto 0;
    padding: 30px;
}

.auth-mark {
    width: fit-content;
    margin-bottom: 20px;
    border: 1px solid #c9ddd8;
    border-radius: 999px;
    padding: 5px 10px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
}

h1 {
    margin: 0 0 7px;
    font-size: 28px;
    font-weight: 650;
    line-height: 1.15;
    letter-spacing: 0;
}

.muted {
    color: var(--muted);
    margin: 0 0 18px;
}

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

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

.summary-pill {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 11px;
    background: var(--surface-soft);
    color: var(--muted-strong);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

form {
    margin: 0;
}

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

input,
select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    background: #ffffff;
    font: inherit;
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

input::placeholder {
    color: #9aa3af;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(20, 92, 82, 0.12);
}

button {
    min-height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    padding: 8px 13px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

button:hover {
    background: var(--surface-soft);
    border-color: #b9c2ce;
}

button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

button.primary:hover {
    border-color: var(--primary-hover);
    background: var(--primary-hover);
}

button.secondary {
    border-color: var(--line-strong);
    background: #ffffff;
    color: var(--primary);
}

button.secondary:hover {
    border-color: #aeb8c4;
    background: var(--surface-soft);
}

button.compact {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
}

button.danger {
    border-color: #f0b8b2;
    background: var(--danger-soft);
    color: var(--danger);
}

button.danger:hover {
    border-color: #e38f86;
    background: #ffe6e3;
}

.icon-button {
    width: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: 999px;
    color: var(--muted-strong);
    font-size: 22px;
    line-height: 1;
}

.auth-card form,
.user-form {
    display: grid;
    gap: 14px;
}

.filters {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 12px;
    align-items: end;
    padding: 14px;
    margin-bottom: 12px;
    background: #fbfcfd;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.status-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.status-filter a {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 12px;
    background: #ffffff;
    color: var(--muted-strong);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.status-filter a:hover {
    border-color: var(--line-strong);
    background: var(--surface-soft);
    color: var(--text);
}

.status-filter a.active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.user-form {
    grid-template-columns: 1fr 1fr 1fr 166px 116px auto;
    align-items: end;
    gap: 12px;
    padding: 14px;
    margin-bottom: 18px;
    background: #fbfcfd;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
}

.check input {
    width: auto;
    min-height: auto;
}

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

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

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

tbody tr:hover {
    background: #fbfcfd;
}

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

th {
    color: var(--muted-strong);
    background: #f7f8fa;
    font-size: 12px;
    font-weight: 600;
    text-transform: none;
}

td strong {
    font-weight: 600;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
}

.badge.used {
    color: var(--success-text);
    background: var(--success-bg);
}

.badge.unused {
    color: var(--warning-text);
    background: var(--warning-bg);
}

.badge.expired {
    color: var(--muted-strong);
    background: #eef1f4;
}

.actions {
    width: 1%;
    white-space: nowrap;
}

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

.actions button {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
}

.actions .icon-danger {
    width: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-color: #f0b8b2;
    border-radius: 6px;
    padding: 0;
    background: #ffffff;
    color: var(--danger);
    font-size: 18px;
    line-height: 1;
}

.actions .icon-danger:hover {
    border-color: #e38f86;
    background: var(--danger-soft);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.pagination a,
.pagination span {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    background: #ffffff;
    color: var(--muted-strong);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.pagination a:hover {
    border-color: var(--line-strong);
    background: var(--surface-soft);
    color: var(--text);
}

.pagination span {
    color: #a0a8b3;
}

.pagination .active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.pagination-pages {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.modal {
    width: min(420px, calc(100% - 28px));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0;
    background: #ffffff;
    color: var(--text);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.modal::backdrop {
    background: rgba(17, 24, 39, 0.38);
}

.modal form {
    display: grid;
    gap: 0;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 18px 18px 4px;
}

.modal-head h2 {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 650;
}

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

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px 18px;
    border-top: 1px solid var(--line);
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 28px;
}

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

.alert.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.alert.error {
    background: var(--error-bg);
    color: var(--error-text);
}

@media (max-width: 900px) {
    .topbar,
    nav {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar {
        padding: 16px;
    }

    .filters,
    .user-form {
        grid-template-columns: 1fr;
    }

    .section-head {
        flex-direction: column;
    }

    .head-actions {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .pagination {
        align-items: stretch;
        flex-direction: column;
    }

    th,
    td {
        min-width: 130px;
    }
}
