:root {
    --blue: #0d74ce;
    --deep-blue: #074a8a;
    --navy: #001c33;
    --text: #092a48;
    --sky: #38bdf8;
    --ice: #f0f7ff;
    --orange: #f59e0b;
    --line: #d8e7f5;
    --muted: #60758a;
    --danger: #b42318;
    --success: #167b45;
}

* { box-sizing: border-box; }

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

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

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

.sidebar {
    background: var(--navy);
    color: white;
    padding: 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.brand img { width: 42px; height: 42px; object-fit: contain; }
.brand strong { display: block; font-size: 15px; }
.brand span { color: #b9d9f3; font-size: 12px; }

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

.nav a,
.nav button {
    width: 100%;
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    text-align: left;
    color: #b9d9f3;
    background: transparent;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: block;
}

.nav a:hover,
.nav button:hover {
    background: rgba(255, 255, 255, 0.06);
    color: white;
}

.nav .active {
    background: var(--blue) !important;
    color: white !important;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(13, 116, 206, 0.2);
}

.main {
    padding: 26px;
    min-width: 0;
}

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

h1, h2, h3 {
    color: var(--navy);
    margin: 0;
    letter-spacing: 0;
}

h1 { font-size: 28px; font-weight: 800; }
h2 {
    font-size: 17px;
    margin-bottom: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}
h3 { font-size: 14px; margin-bottom: 10px; font-weight: 700; }

.panel p {
    margin: 12px 0;
    line-height: 1.5;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.muted { color: var(--muted); font-size: 13px; }

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

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

.panel {
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 28, 51, 0.03);
}

.grid.cards .panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-left: 4px solid var(--blue);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.grid.cards .panel:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 28, 51, 0.08);
}

.grid.cards .panel:nth-child(1) { border-left-color: var(--blue); }
.grid.cards .panel:nth-child(2) { border-left-color: var(--sky); }
.grid.cards .panel:nth-child(3) { border-left-color: var(--orange); }
.grid.cards .panel:nth-child(4) { border-left-color: var(--success); }

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

.section-heading h2 {
    margin-bottom: 4px;
}

.earnings-panel {
    margin-top: 16px;
}

.earnings-chart {
    display: grid;
    gap: 12px;
}

.earning-row {
    display: grid;
    grid-template-columns: minmax(120px, 180px) minmax(180px, 1fr) minmax(180px, 240px);
    gap: 14px;
    align-items: center;
}

.earning-label,
.earning-value {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.earning-label strong,
.earning-value strong {
    overflow-wrap: anywhere;
}

.earning-label span,
.earning-value span {
    color: var(--muted);
    font-size: 12px;
}

.earning-value {
    text-align: right;
}

.earning-track {
    height: 18px;
    border-radius: 6px;
    background: var(--ice);
    border: 1px solid var(--line);
    overflow: hidden;
}

.earning-bar {
    position: relative;
    height: 100%;
    min-width: 0;
    border-radius: 5px;
    background: linear-gradient(90deg, var(--orange), #fbbf24);
    overflow: hidden;
}

.earning-completed {
    display: block;
    height: 100%;
    min-width: 0;
    background: linear-gradient(90deg, var(--blue), var(--success));
}

.metric {
    font-size: 30px;
    font-weight: 800;
    color: var(--navy);
    line-height: 1.1;
}

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

.button,
button {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 16px;
    background: var(--blue);
    color: white;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.button:hover,
button:hover {
    background: var(--deep-blue);
}

.button.secondary,
button.secondary {
    background: white;
    color: var(--deep-blue);
    border-color: var(--line);
}

.button.secondary:hover,
button.secondary:hover {
    background: var(--ice);
    border-color: var(--blue);
}

.button.warning {
    background: var(--orange);
    color: var(--navy);
}

.button.warning:hover {
    background: #e08e00;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 11px;
    font: inherit;
    color: var(--text);
    background: white;
    transition: all 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(13, 116, 206, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
}

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

/* Constrain wide form inputs (e.g. Settings) on large monitors */
.form-constrained,
.form-constrained .form-grid {
    max-width: 600px;
}

.form-constrained .form-grid {
    grid-template-columns: 1fr;
}

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

    .earning-row {
        grid-template-columns: 1fr;
        gap: 7px;
    }

    .earning-value {
        text-align: left;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
    padding-top: 14px;
    padding-bottom: 14px;
}

.sort-button {
    width: 100%;
    border: 0;
    border-radius: 6px;
    padding: 0 18px 0 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    justify-content: flex-start;
    position: relative;
}

.sort-button:hover {
    background: transparent;
    color: var(--deep-blue);
}

.sort-button::after {
    content: "-";
    position: absolute;
    right: 0;
    color: #9ab0c4;
    font-size: 11px;
}

th[data-sort-direction="asc"] .sort-button::after { content: "^"; color: var(--blue); }
th[data-sort-direction="desc"] .sort-button::after { content: "v"; color: var(--blue); }

/* Prevent inline forms in tables from stretching and wrapping awkwardly */
td .actions,
td form.actions,
form.actions.js-live-edit-form {
    display: inline-flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    width: auto;
}

td .actions select,
td form.actions select,
.js-live-edit-form select {
    width: auto !important;
    min-width: 100px;
    max-width: 150px;
    height: 32px;
    padding: 4px 24px 4px 8px; /* Extra right padding for dropdown arrow */
    font-size: 13px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background-color: white;
    cursor: pointer;
}

td .actions input,
td form.actions input,
.js-live-edit-form input {
    width: auto !important;
    max-width: 90px;
    height: 32px;
    padding: 4px 8px;
    font-size: 13px;
    border-radius: 6px;
    border: 1px solid var(--line);
}

td .actions button,
td form.actions button,
.js-live-edit-form button {
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
    border-radius: 6px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

td .actions label,
td form.actions label,
.js-live-edit-form label {
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    white-space: nowrap;
    cursor: pointer;
}

/* Specific styling for dropdown arrows in standard selects */
select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2360758a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
    padding-right: 28px !important;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    background: var(--ice);
    color: var(--deep-blue);
    font-size: 12px;
    font-weight: 700;
}

.badge.danger { background: #fee4e2; color: var(--danger); }
.badge.success { background: #dcfae6; color: var(--success); }
.badge.warning { background: #fef3c7; color: #92400e; }

.flash {
    margin-bottom: 14px;
    padding: 11px 13px;
    border-radius: 8px;
    background: #dcfae6;
    color: var(--success);
    border: 1px solid #a9efc5;
}

.flash.error {
    background: #fee4e2;
    color: var(--danger);
    border-color: #fecdca;
}

.banner {
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.banner.info {
    background: var(--ice);
    color: var(--deep-blue);
    border: 1px solid var(--line);
}

/* Dropdown menu (e.g., Dashboard Quick Sync) */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.dropdown summary::-webkit-details-marker {
    display: none;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px;
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0, 28, 51, 0.1);
    z-index: 20;
}

.dropdown-menu form {
    margin: 0;
}

.dropdown-menu button {
    width: 100%;
    text-align: left;
    background: white;
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.dropdown-menu button:hover {
    background: var(--ice);
    color: var(--blue);
}

.dropdown-menu button.warning {
    background: white;
    color: var(--navy);
}

.dropdown-menu button.warning:hover {
    background: #fff7e6;
}

.pagination {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.pagination nav {
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination nav > div {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.pagination nav a,
.pagination nav span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: white;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.pagination nav a:hover {
    background: var(--ice);
    border-color: var(--blue);
    color: var(--blue);
}

.pagination nav .current {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
    font-weight: 700;
}

.pagination nav .disabled {
    opacity: 0.5;
    background: var(--ice);
    cursor: not-allowed;
    color: var(--muted);
}

.pagination nav .dots {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    cursor: default;
}

.progress-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.progress-row span {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 7px;
    background: var(--ice);
    font-size: 12px;
    font-weight: 700;
}

/* Modal dialog (e.g., Add User) */
dialog.modal {
    border: none;
    border-radius: 12px;
    padding: 0;
    background: transparent;
    box-shadow: 0 20px 60px rgba(0, 28, 51, 0.2);
    max-width: 500px;
    width: min(500px, calc(100% - 32px));
}

dialog.modal::backdrop {
    background: rgba(0, 28, 51, 0.4);
    backdrop-filter: blur(3px);
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.modal-header h2 {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.modal-close:hover {
    color: var(--danger);
    background: #fee4e2;
}

.commission-modal-form {
    display: grid;
    gap: 16px;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
}

.checkbox-row input {
    width: auto;
}

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

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

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

pre.payload {
    max-height: 420px;
    overflow: auto;
    background: #071f38;
    color: #d8ecff;
    padding: 14px;
    border-radius: 8px;
    font-size: 12px;
}

.sidebar-toggle {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--ice);
    border-color: var(--blue);
    color: var(--blue);
}

.app-shell {
    transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed {
    grid-template-columns: 0 1fr;
}

.sidebar-collapsed .sidebar {
    overflow: hidden;
    opacity: 0;
    padding: 0;
    border: none;
    width: 0;
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .main { padding: 18px; }
    .grid.cards,
    .form-grid { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .topbar h1 { margin-top: 0; }
    table { font-size: 13px; }
    .sidebar-toggle { display: none; }
}

/* =====================================================================
   Design system additions (Phase 1)
   Reusable components shared across admin + affiliate screens.
   ===================================================================== */

:root {
    --radius: 0.75rem;          /* brand corner radius */
    --radius-sm: 8px;
    --shadow-card: 0 1px 3px rgba(0, 28, 51, 0.05);
    --shadow-pop: 0 10px 15px -3px rgba(92, 70, 35, 0.18);
    --pending: #b45309;
    --pending-bg: #fef3c7;
    --refunded: #6b21a8;
    --refunded-bg: #f3e8ff;
}

.panel { border-radius: var(--radius); }
.button, button { border-radius: var(--radius-sm); }

/* Section subtitle used under panel headings */
.panel-sub { color: var(--muted); font-size: 13px; margin: -8px 0 16px; }

/* ---- Status-colored badges (orders + commissions) ----
   Use: <span class="badge status-{{ $status }}">{{ $status }}</span> */
.badge.status-completed,
.badge.status-processing { background: #dcfae6; color: var(--success); }
.badge.status-pending,
.badge.status-on-hold    { background: var(--pending-bg); color: var(--pending); }
.badge.status-cancelled,
.badge.status-failed     { background: #fee4e2; color: var(--danger); }
.badge.status-refunded   { background: var(--refunded-bg); color: var(--refunded); }
.badge.status-unknown,
.badge.status-inactive   { background: #eef2f6; color: var(--muted); }
.badge.status-active     { background: #dcfae6; color: var(--success); }

/* ---- Filter / toolbar row above tables ---- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 16px;
}

.toolbar .field {
    display: grid;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.toolbar .field input,
.toolbar .field select {
    width: auto;
    min-width: 150px;
    height: 38px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
}

.toolbar .field.grow { flex: 1; }
.toolbar .field.grow input { width: 100%; }
.toolbar .spacer { flex: 1; }

/* ---- Bulk action bar (shown by JS when rows are selected) ---- */
.bulk-bar {
    display: none;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: var(--deep-blue);
    color: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
}

.bulk-bar strong { font-weight: 800; }
.bulk-bar .spacer { flex: 1; }
.bulk-bar select { width: auto; min-width: 160px; height: 36px; }

/* ---- Checkboxes for row selection ---- */
input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--blue);
    cursor: pointer;
}

th.col-check, td.col-check { width: 36px; text-align: center; }

/* ---- Responsive table wrapper (horizontal scroll on small screens) ---- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- Chips / pills for inline metadata ---- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--ice);
    border: 1px solid var(--line);
    color: var(--deep-blue);
    font-size: 12px;
    font-weight: 600;
}

.chip.muted { background: #f4f7fa; color: var(--muted); }

/* ---- Empty states ---- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
}

.empty-state .icon {
    font-size: 28px;
    margin-bottom: 8px;
    opacity: 0.5;
}

.empty-state strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---- Stat card delta (trend) ---- */
.metric-sub { font-size: 12px; color: var(--muted); font-weight: 500; }
.metric-sub.up { color: var(--success); }
.metric-sub.down { color: var(--danger); }

/* ---- Affiliate statement / earnings tables ---- */
.statement th { background: var(--ice); }
.statement tfoot td { font-weight: 800; color: var(--navy); border-top: 2px solid var(--line); }

.text-right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---- Sidebar section labels (grouped nav) ---- */
.nav .nav-label {
    color: #6f93b3;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 14px 14px 4px;
}

/* ---- Affiliate dashboard: source bars and status breakdown ---- */
.panel.accent {
    border-top: 4px solid var(--blue);
}

.metric.small {
    font-size: 18px;
    font-weight: 800;
    color: var(--deep-blue);
}

.bar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.bar-row:last-child { border-bottom: none; }

.progress-bar {
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 14px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), #2b9aff);
    border-radius: 999px;
    transition: width 0.4s ease;
}

.status-breakdown {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--ice);
    border-radius: var(--radius);
}
