:root {
    --bg: #f7f5f2;
    --panel: #fffdfa;
    --ink: #2f3437;
    --muted: #6f767a;
    --line: #e8dfd7;
    --mint: #9bcfbd;
    --mint-dark: #4f927f;
    --peach: #f2b8a2;
    --rose: #d9828b;
    --blue: #6f98b5;
    --shadow: 0 18px 45px rgba(73, 61, 48, .08);
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #fff9f1;
    border-right: 1px solid var(--line);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.brand,
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--mint), var(--peach));
    color: #fff;
    font-weight: 800;
}

.brand small,
.login-brand p {
    display: block;
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.nav {
    display: grid;
    gap: 8px;
}

.nav a,
.logout-link {
    padding: 11px 12px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 650;
}

.nav a:hover,
.nav a.active {
    background: #eef7f3;
    color: var(--mint-dark);
}

.logout-link {
    margin-top: auto;
    color: var(--rose);
}

.main {
    padding: 32px;
}

.topbar,
.panel-header,
.actions-row,
.form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar {
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--mint-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size: 30px;
}

h2 {
    font-size: 19px;
}

.user-pill,
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 8px;
    padding: 5px 10px;
    background: #eef7f3;
    color: var(--mint-dark);
    font-size: 13px;
    font-weight: 750;
}

.badge.success {
    background: #e9f6ed;
    color: #397a56;
}

.badge.warning {
    background: #fff4df;
    color: #8b6328;
}

.badge.danger {
    background: #fff0f1;
    color: #a84450;
}

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

.badge.compact {
    min-height: 22px;
    margin-left: 8px;
    padding: 3px 7px;
    font-size: 11px;
}

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

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

.stat-card {
    padding: 22px;
    display: grid;
    gap: 10px;
}

.stat-card span,
.panel p {
    color: var(--muted);
}

.stat-card strong {
    font-size: 34px;
}

.stat-card a {
    color: var(--blue);
    font-weight: 750;
}

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

.panel.narrow {
    max-width: 860px;
}

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

.panel p {
    margin: 6px 0 0;
}

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    padding: 0 16px;
    font-weight: 800;
    cursor: pointer;
}

.button.primary {
    background: var(--mint-dark);
    color: white;
}

.button.secondary {
    background: #f0ebe4;
    color: var(--ink);
}

.button.ghost {
    background: #fffdfa;
    border: 1px solid var(--line);
    color: var(--mint-dark);
}

.button.small {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
}

.button.full {
    width: 100%;
}

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

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

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

td small {
    color: var(--muted);
}

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

.filters-bar {
    display: flex;
    align-items: end;
    gap: 10px;
    margin-bottom: 18px;
    padding: 10px;
    background: #fbf7f1;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.filters-bar label {
    flex: 0 0 180px;
    gap: 5px;
}

.filters-bar .filter-search {
    flex: 1 1 280px;
}

.filters-bar input,
.filters-bar select {
    min-height: 38px;
    padding: 8px 10px;
}

.filter-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
}

.filter-actions .button {
    min-height: 38px;
}

.promo-table {
    min-width: 1120px;
}

.promo-table th,
.promo-table td {
    padding: 15px 12px;
}

.promo-table th:last-child,
.promo-table td:last-child {
    width: 250px;
}

.code-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border-radius: 8px;
    padding: 5px 9px;
    background: #eef7f3;
    color: var(--mint-dark);
    letter-spacing: .02em;
}

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

.usage-meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    min-width: 150px;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
}

.progress-track {
    width: 100%;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #efe9e2;
}

.progress-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--mint-dark);
}

.progress-fill.high {
    background: var(--rose);
}

.row-actions {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbf7f1;
}

.row-actions form {
    margin: 0;
}

.row-actions .button {
    white-space: nowrap;
}

.detail-panel {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 2fr;
    gap: 18px;
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffaf0;
}

.detail-panel h3 {
    margin: 10px 0 4px;
    font-size: 24px;
}

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

.detail-panel dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 4px;
}

.detail-panel dd {
    margin: 0;
    font-weight: 700;
}

.form {
    display: grid;
    gap: 16px;
}

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

.span-2 {
    grid-column: span 2;
}

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

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    padding: 11px 12px;
}

textarea {
    resize: vertical;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    align-self: end;
    min-height: 42px;
}

.check-row input {
    width: auto;
}

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

.alert.error {
    background: #fff0f1;
    color: #a84450;
}

.alert.success {
    background: #eaf7f0;
    color: #397a56;
}

.alert.warning {
    background: #fff4df;
    color: #8b6328;
}

.error-list {
    margin: 10px 0 0;
    padding-left: 18px;
}

.block {
    display: block;
    margin-top: 6px;
}

.diagnostic-panel {
    background: #fffaf0;
}

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

.diagnostic-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fffdfa;
}

.diagnostic-grid dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 6px;
}

.diagnostic-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-weight: 750;
}

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

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

.login-brand {
    margin-bottom: 24px;
}

.login-brand h1 {
    font-size: 25px;
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        padding: 18px;
    }

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

    .main {
        padding: 20px;
    }

    .stats-grid,
    .grid-form,
    .diagnostic-grid,
    .detail-panel,
    .detail-panel dl {
        grid-template-columns: 1fr;
    }

    .filters-bar {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .filters-bar label,
    .filters-bar .filter-search {
        flex: 1 1 220px;
    }

    .filter-actions {
        flex: 1 1 100%;
    }

    .span-2 {
        grid-column: span 1;
    }

    .topbar,
    .panel-header,
    .actions-row,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }
}

/* Promo code page overrides: keep filters and row actions compact on desktop. */
.panel form.filters-bar {
    display: flex;
    flex-direction: row;
    align-items: end;
    gap: 10px;
}

.panel form.filters-bar label {
    width: auto;
    min-width: 0;
}

.panel form.filters-bar label:not(.filter-search) {
    flex: 0 0 180px;
}

.panel form.filters-bar .filter-search {
    flex: 1 1 320px;
}

.panel form.filters-bar .filter-actions {
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
}

.promo-table .row-actions {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
}

.promo-table .row-actions form,
.promo-table .row-actions button,
.promo-table .row-actions a {
    margin: 0;
}

@media (max-width: 900px) {
    .panel form.filters-bar {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .panel form.filters-bar label:not(.filter-search),
    .panel form.filters-bar .filter-search {
        flex: 1 1 220px;
    }

    .panel form.filters-bar .filter-actions {
        flex: 1 1 100%;
    }
}
