:root {
    --bg: #f5efe4;
    --panel: #fffdf8;
    --panel-border: #d8c9b2;
    --ink: #2d2418;
    --muted: #6b5d4b;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --success: #027a48;
    --success-soft: #ecfdf3;
    --shadow: 0 18px 40px rgba(80, 59, 29, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.14), transparent 25%),
        linear-gradient(180deg, #f8f3ea 0%, var(--bg) 100%);
    color: var(--ink);
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 24px auto 40px;
}

.topbar,
.card,
.userbar,
.flash {
    background: rgba(255, 253, 248, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 24px;
    align-items: center;
}

.topbar h1,
.card h2,
.card h3 {
    margin-top: 0;
}

.topbar p {
    margin: 8px 0 0;
    color: var(--muted);
}

nav {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.nav-account-meta {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 8px 14px;
    background: #efe4d4;
    color: var(--ink);
    border: 1px solid #d8c9b2;
    font-size: 0.92rem;
    white-space: nowrap;
}

nav a,
button {
    border: 0;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.98rem;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.button-link {
    display: inline-block;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.92rem;
    text-decoration: none;
    background: #e7ddd0;
    color: var(--ink);
}

.button-link:hover {
    opacity: 0.9;
}

.button-text {
    display: inline;
    background: none;
    color: var(--accent);
    border: none;
    padding: 0;
    font-size: inherit;
    cursor: pointer;
    text-decoration: underline;
    font-weight: normal;
}

.button-text:hover {
    opacity: 0.8;
}

nav a,
button {
    background: var(--accent);
    color: white;
}

nav a:hover,
button:hover {
    transform: translateY(-1px);
    opacity: 0.94;
}

button.secondary {
    background: #e7ddd0;
    color: var(--ink);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.userbar,
.flash {
    margin-top: 16px;
    padding: 14px 18px;
}

.flash-stack {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1200;
    width: min(420px, calc(100vw - 28px));
    display: grid;
    gap: 10px;
    pointer-events: none;
}

.flash-stack .flash {
    margin-top: 0;
    pointer-events: auto;
    transform: translateY(0);
    opacity: 1;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.flash-stack .flash.is-hiding {
    opacity: 0;
    transform: translateY(-8px);
}

.badge,
.status {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.85rem;
}

.badge,
.status-pending {
    background: #fff3cd;
    color: #7a5600;
}

.status-approved {
    background: var(--success-soft);
    color: var(--success);
}

.status-confirmed {
    background: var(--success-soft);
    color: var(--success);
}

.status-adjusted {
    background: #eef4ff;
    color: #1e40af;
}

.status-cancelled {
    background: #f3f4f6;
    color: #374151;
}

.status-rejected,
.flash-error {
    background: var(--danger-soft);
    color: var(--danger);
}

.flash-success {
    background: var(--success-soft);
    color: var(--success);
}

main {
    margin-top: 24px;
}

.grid {
    display: grid;
    gap: 20px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 20px;
}

.card {
    padding: 22px;
    margin-bottom: 20px;
}

.card.narrow {
    max-width: 520px;
    margin: 0 auto;
}

label,
input,
select,
textarea {
    display: block;
    width: 100%;
}

label {
    font-weight: 600;
    margin-bottom: 12px;
}

input,
select,
textarea {
    margin-top: 6px;
    border: 1px solid #c9b79d;
    border-radius: 12px;
    padding: 12px 14px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

.inline-input-action {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
}

.inline-action-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.inline-input-action input {
    margin-top: 0;
}

.inline-input-action button {
    white-space: nowrap;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-row input {
    width: auto;
    margin: 0;
}

.muted {
    color: var(--muted);
}

.preview-box,
.payout-item,
.product-admin-item {
    background: #fffaf1;
    border: 1px solid #e3d6c2;
    border-radius: 16px;
    padding: 16px;
}

.compact-head {
    margin-bottom: 12px;
}

.live-discount-preview {
    border: 1px dashed #d5b98f;
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff7eb;
}

.live-discount-preview p {
    margin: 6px 0;
}

.preview-grid-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.preview-card {
    border: 1px solid #eadcc6;
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
}

.preview-card h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.preview-card p {
    margin: 6px 0;
}

.preview-sale {
    background: #f6fbfa;
    border-color: #c7e7e2;
}

.preview-earn {
    background: #f3fcf6;
    border-color: #c6e7d0;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stats div {
    background: #fffaf1;
    border-radius: 14px;
    padding: 14px;
    border: 1px solid #eadcc6;
}

.stats span {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 6px;
}

.stats strong {
    font-size: 1.1rem;
}

.stack {
    display: flex;
    flex-direction: column;
}

.gap-sm {
    gap: 10px;
}

.gap-lg {
    gap: 18px;
}

.row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.wrap {
    flex-wrap: wrap;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.info-card {
    padding: 12px;
    border: 1px solid #e3d6c2;
    border-radius: 12px;
    background: #fffaf1;
}

.info-card-head {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: start;
}

.info-card-title {
    margin: 0 0 8px 0;
    font-weight: 700;
}

.info-card-meta {
    margin: 0 0 4px 0;
    font-size: 0.9em;
    color: var(--muted);
}

.info-card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.info-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.compact-card {
    padding: 10px;
}

.network-referral-grid {
    margin-bottom: 20px;
}

.network-child-card {
    background: #fff;
    border-color: #eadcc6;
}

.network-child-card .info-card-title {
    margin-bottom: 2px;
}

.network-child-card .info-card-head {
    align-items: center;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-scroll.wide table {
    min-width: 980px;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid #eadcc6;
    text-align: left;
    vertical-align: top;
}

.subgrid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 20px;
    margin-top: 18px;
}

.product-admin-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 18px;
}

.product-list-panel {
    border: 1px solid #e3d6c2;
    border-radius: 16px;
    background: #fffaf1;
    padding: 14px;
}

.product-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 460px;
    overflow: auto;
    padding-right: 4px;
}

.product-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--ink);
    border: 1px solid #eadcc6;
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
}

.product-list-item:hover {
    border-color: #d5b98f;
}

.product-list-item.is-active {
    border-color: var(--accent);
    background: #ecf8f7;
}

.product-form {
    grid-template-columns: 1.5fr 1fr auto auto;
    align-items: end;
    gap: 14px;
}

.preview-form {
    margin-bottom: 14px;
}

details summary {
    cursor: pointer;
    margin-bottom: 10px;
}

@media (max-width: 900px) {
    .grid.two,
    .subgrid,
    .product-admin-layout,
    .product-form,
    .stats,
    .preview-grid-two {
        grid-template-columns: 1fr;
    }

    .info-card-head {
        grid-template-columns: 1fr;
    }

    .info-card-actions {
        justify-content: flex-start;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Modal Dialog */
dialog.modal-dialog {
    border: none;
    border-radius: 18px;
    background: var(--panel);
    box-shadow: 0 28px 60px rgba(80, 59, 29, 0.24);
    padding: 0;
    max-width: min(90%, 420px);
}

dialog.modal-dialog::backdrop {
    background: rgba(0, 0, 0, 0.35);
}

.modal-content {
    padding: 24px;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 12px;
}

.modal-content p {
    margin: 0 0 16px 0;
    color: var(--muted);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-direction: row-reverse;
}

.modal-actions button {
    flex: 1;
}

fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

fieldset legend {
    font-weight: bold;
    margin-bottom: 8px;
}
