:root {
    --bg: #f4efe5;
    --surface: #fffdf9;
    --surface-strong: #ffffff;
    --border: #e8dcc5;
    --text: #1d2330;
    --muted: #687284;
    --accent: #e86f2e;
    --accent-dark: #a44616;
    --success: #11795b;
    --danger: #b83b3b;
    --shadow: 0 18px 45px rgba(74, 54, 28, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(232, 111, 46, 0.18), transparent 28%),
        linear-gradient(180deg, #fcf7ee 0%, #f4efe5 100%);
    color: var(--text);
}

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

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

.sidebar {
    padding: 28px 22px;
    border-right: 1px solid rgba(232, 220, 197, 0.8);
    background: rgba(255, 253, 249, 0.88);
    backdrop-filter: blur(12px);
}

.brand {
    display: block;
    margin-bottom: 28px;
}

.brand-logo {
    width: 100%;
    max-width: 220px;
    max-height: 96px;
    height: auto;
    display: block;
    object-fit: contain;
}

.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, #1d2330 0%, #36425a 100%);
    color: #fff;
    font-weight: 700;
    font-size: 1.3rem;
}

.brand h1,
.topbar h2,
.card h3 {
    margin: 0;
}

.eyebrow {
    margin: 0 0 4px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.75rem;
    color: var(--muted);
}

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

.nav a {
    padding: 14px 16px;
    border-radius: 16px;
    color: #31405c;
    transition: 0.2s ease;
}

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

.nav-logout-button {
    width: 100%;
    text-align: left;
    background: transparent;
    color: #31405c;
    padding: 14px 16px;
    border-radius: 16px;
    border: 0;
    font: inherit;
    font-weight: 400;
    cursor: pointer;
    transition: 0.2s ease;
}

.nav a.active,
.nav a:hover,
.nav-logout-button:hover {
    background: #1d2330;
    color: #fff;
    transform: translateX(2px);
}

.content {
    padding: 26px;
}

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

.topbar-card,
.card,
.stat-card,
.table-shell {
    background: rgba(255, 253, 249, 0.92);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.topbar-card {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 14px 18px;
    border-radius: 18px;
}

.topbar-card p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: var(--success);
    box-shadow: 0 0 0 6px rgba(17, 121, 91, 0.12);
}

.grid {
    display: grid;
    gap: 18px;
}

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

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

.two-col {
    grid-template-columns: 1.25fr 0.75fr;
}

.stat-card,
.card,
.table-shell {
    border-radius: 24px;
    padding: 22px;
}

.stat-label,
.helper,
label,
th {
    color: var(--muted);
}

.stat-value {
    margin-top: 10px;
    font-size: 1.8rem;
    font-weight: 700;
}

.card p,
.helper {
    line-height: 1.6;
}

.flash {
    padding: 14px 18px;
    border-radius: 16px;
    margin-bottom: 18px;
}

.flash-success {
    background: rgba(17, 121, 91, 0.12);
    color: #0f664d;
}

.flash-error {
    background: rgba(184, 59, 59, 0.12);
    color: #8d2525;
}

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

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

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.92rem;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    background: var(--surface-strong);
    color: var(--text);
    font: inherit;
}

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

.tall-textarea {
    min-height: 220px;
}

.button-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

button,
.button-link {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
}

button.primary,
.button-link.primary {
    background: linear-gradient(135deg, var(--accent) 0%, #ff9a52 100%);
    color: #fff;
}

button.secondary,
.button-link.secondary {
    background: #1d2330;
    color: #fff;
}

.cp-action {
    min-width: 110px;
    color: #fff;
}

.cp-approve {
    background: linear-gradient(135deg, #14936b 0%, #28b07b 100%);
}

.cp-cancel {
    background: linear-gradient(135deg, #c94747 0%, #e46666 100%);
}

.cp-view {
    background: #1d2330;
}

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

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

th {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.table-shell table tr:first-child th,
.table-shell table tr:first-child td {
    border-top: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-queued,
.badge-processing {
    background: rgba(232, 111, 46, 0.12);
    color: var(--accent-dark);
}

.badge-success {
    background: rgba(17, 121, 91, 0.12);
    color: var(--success);
}

.badge-partial {
    background: rgba(54, 66, 90, 0.12);
    color: #36425a;
}

.badge-failed {
    background: rgba(184, 59, 59, 0.12);
    color: var(--danger);
}

.mono {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.88rem;
}

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

.history-shell {
    background: rgba(255, 253, 249, 0.95);
    border: 1px solid var(--border);
    border-radius: 28px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.history-head {
    padding: 18px 22px;
    background: linear-gradient(90deg, rgba(232, 111, 46, 0.18), rgba(232, 111, 46, 0.05));
    border-bottom: 1px solid var(--border);
}

.history-head h3 {
    margin: 0;
    font-size: 1.45rem;
}

.history-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 22px;
    align-items: end;
}

.history-search {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
}

.history-search label {
    margin-bottom: 6px;
}

.history-search input,
.history-search select {
    min-width: 180px;
}

.toolbar-button,
.toolbar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    padding: 12px 18px;
    font-weight: 600;
    border: 0;
    cursor: pointer;
    color: #fff;
    background: #4f7ee8;
}

.toolbar-button-soft {
    background: #5f8df0;
}

.toolbar-button-dark {
    background: #1d2330;
}

.toolbar-button-accent {
    background: linear-gradient(135deg, var(--accent) 0%, #ff9a52 100%);
}

.toolbar-icon {
    background: #eef3ff;
    color: #3157a3;
    padding: 10px 14px;
}

.history-table-wrap {
    padding: 0 22px 22px;
    overflow-x: auto;
}

.history-table th {
    background: #eef3fb;
    color: #1d2330;
    font-size: 0.78rem;
}

.history-table td,
.history-table th {
    white-space: nowrap;
}

.history-table td:nth-child(4),
.history-table td:nth-child(9) {
    white-space: normal;
}

.details-payload pre {
    margin: 8px 0 0;
    padding: 12px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--border);
    white-space: pre-wrap;
    word-break: break-word;
}

body.modal-open {
    overflow: hidden;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.46);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    width: min(760px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    border-radius: 28px;
    border: 1px solid var(--border);
    background: rgba(255, 253, 249, 0.98);
    box-shadow: 0 28px 60px rgba(29, 35, 48, 0.22);
    padding: 24px;
}

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

.modal-close {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    background: #eef3ff;
    color: #3157a3;
    font-size: 1.4rem;
    line-height: 1;
    padding: 0;
}

.slip-card {
    border: 1px solid var(--border);
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(248, 242, 232, 0.95));
    padding: 20px;
}

.slip-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}

.slip-label {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.slip-value {
    font-size: 1rem;
    font-weight: 600;
}

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

.slip-note {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

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

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid rgba(232, 220, 197, 0.8);
    }

    .brand-logo {
        max-width: 200px;
        max-height: 88px;
    }

    .stats-grid,
    .stats-grid-3,
    .two-col,
    .field-grid {
        grid-template-columns: 1fr;
    }

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

    .history-toolbar,
    .history-search {
        flex-direction: column;
        align-items: stretch;
    }

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