:root {
    color-scheme: light;
    --ink: #28303d;
    --muted: #68707d;
    --line: #dfe6e5;
    --paper: #ffffff;
    --field: #f8faf9;
    --mint: #d1e4dd;
    --mint-strong: #70aa91;
    --blue: #d1dfe4;
    --blue-strong: #477286;
    --amber: #e4dad1;
    --amber-strong: #b16e3f;
    --danger: #b74b4b;
    --danger-soft: #f4e3df;
    --shadow: 0 18px 42px rgba(40, 48, 61, 0.11);
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    min-height: 100%;
    background:
        linear-gradient(135deg, rgba(209, 228, 221, 0.85), rgba(255, 255, 255, 0.74) 36%, rgba(209, 223, 228, 0.85)),
        #f6f8f7;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
}

button,
input,
select {
    font: inherit;
}

button {
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px 28px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(40, 48, 61, 0.1);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand img {
    width: 54px;
    height: 54px;
    object-fit: contain;
    background: var(--paper);
    border-radius: 8px;
    border: 1px solid var(--line);
    padding: 6px;
}

.brand p,
.operation-heading p {
    margin: 0;
    color: var(--blue-strong);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.brand h1 {
    margin: 2px 0 0;
    font-size: clamp(1.35rem, 2vw, 2rem);
    letter-spacing: 0;
}

.status-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.status-chip {
    min-width: 112px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--muted);
    padding: 8px 10px;
    text-align: center;
    font-size: 0.86rem;
    font-weight: 800;
}

.status-chip.ok {
    color: #2f7258;
    border-color: rgba(112, 170, 145, 0.42);
    background: rgba(209, 228, 221, 0.72);
}

.status-chip.warn {
    color: var(--amber-strong);
    border-color: rgba(177, 110, 63, 0.28);
    background: rgba(228, 218, 209, 0.72);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(300px, 380px);
    gap: 18px;
    width: min(1480px, calc(100% - 32px));
    margin: 24px auto;
    align-items: start;
}

.rail,
.operations,
.result-panel {
    border: 1px solid rgba(40, 48, 61, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.rail,
.result-panel {
    display: grid;
    gap: 14px;
    padding: 16px;
}

.operations {
    padding: 0;
    overflow: hidden;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: linear-gradient(180deg, #fff, #fafcfb);
}

.section-title,
.operation-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-title span {
    font-size: 0.95rem;
    font-weight: 900;
}

.section-title small,
.operation-heading small {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.province-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.province-button,
.tab,
.ghost,
.secondary {
    background: #f5f8f7;
    color: var(--ink);
    border: 1px solid var(--line);
}

.province-button.active,
.tab.active {
    color: #1f513e;
    border-color: rgba(112, 170, 145, 0.55);
    background: var(--mint);
}

.tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    border-bottom: 1px solid var(--line);
    background: #f4f8f7;
}

.tab {
    min-height: 54px;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
}

.tab:last-child {
    border-right: 0;
}

.operation {
    display: none;
    padding: 22px;
}

.operation.active {
    display: block;
}

.operation-heading {
    min-height: 58px;
    margin-bottom: 18px;
}

.operation-heading h2 {
    margin: 2px 0 0;
    font-size: 1.42rem;
    letter-spacing: 0;
}

.stack {
    display: grid;
    gap: 12px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 800;
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--ink);
    padding: 9px 10px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--mint-strong);
    box-shadow: 0 0 0 3px rgba(112, 170, 145, 0.18);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 14px;
    align-items: end;
}

.form-block {
    align-items: start;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.form-block h3 {
    grid-column: 1 / -1;
    margin: 0;
    font-size: 1rem;
}

.two-column {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.check-row {
    display: flex;
    align-items: center;
    min-height: 42px;
    gap: 10px;
    color: var(--ink);
}

.check-row input {
    width: 18px;
    height: 18px;
    min-height: 18px;
    accent-color: var(--mint-strong);
}

.primary {
    background: var(--ink);
    color: #fff;
}

.primary:hover {
    background: #1e2530;
}

.secondary {
    background: var(--blue);
    color: #213f4d;
}

.danger {
    background: var(--danger);
    color: #fff;
}

.ghost {
    min-width: 92px;
}

.split-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.form-action {
    align-self: end;
}

.cupo-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 14px;
    margin-top: 18px;
}

.metric-card {
    border: 1px solid rgba(112, 170, 145, 0.38);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(209, 228, 221, 0.66), rgba(255, 255, 255, 0.92));
    padding: 16px;
}

.metric-card span {
    display: block;
    color: var(--blue-strong);
    font-size: 0.78rem;
    font-weight: 900;
    text-transform: uppercase;
}

.metric-card strong {
    display: block;
    margin-top: 8px;
    color: #19392e;
    font-size: 1.42rem;
    letter-spacing: 0;
}

.affiliate-stack {
    display: grid;
    gap: 14px;
}

.affiliate-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(112px, auto);
    align-items: end;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px 16px;
    background: linear-gradient(180deg, #fff, #fafcfb);
}

.affiliate-fields {
    display: grid;
    gap: 12px;
    max-width: 280px;
}

.affiliate-row h3 {
    margin: 0;
    font-size: 1rem;
}

.affiliate-row button {
    min-width: 112px;
}

.save-note {
    margin: 0;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.4;
}

.result-panel {
    position: sticky;
    top: 102px;
}

.receipt-box {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(209, 223, 228, 0.45), rgba(209, 228, 221, 0.45));
    padding: 12px;
}

.receipt-box span {
    color: var(--blue-strong);
    font-size: 0.78rem;
    font-weight: 900;
}

.receipt-box strong {
    font-size: 0.92rem;
}

.retry-panel,
.progress-panel {
    display: grid;
    gap: 10px;
    margin: 12px 0;
    border: 1px solid rgba(112, 170, 145, 0.42);
    border-radius: 8px;
    background: #f7fbf9;
    padding: 12px;
}

.retry-panel[hidden],
.progress-panel[hidden] {
    display: none;
}

.retry-panel span,
.progress-panel span {
    display: block;
    color: var(--blue-strong);
    font-size: 0.76rem;
    font-weight: 900;
    text-transform: uppercase;
}

.retry-panel strong,
.progress-panel strong {
    display: block;
    margin-top: 4px;
    color: var(--ink);
    font-size: 0.92rem;
    letter-spacing: 0;
}

.retry-panel ol,
.progress-panel ol {
    display: grid;
    gap: 8px;
    margin: 0;
    padding-left: 20px;
}

.retry-panel li,
.progress-panel li {
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.retry-panel li strong,
.progress-panel li strong {
    display: inline;
    margin: 0 6px 0 0;
    font-size: 0.82rem;
}

.retry-panel li span,
.progress-panel li span {
    display: inline;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: none;
}

pre {
    min-height: 520px;
    max-height: calc(100vh - 260px);
    margin: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #18202b;
    color: #dce7e4;
    padding: 14px;
    font-size: 0.84rem;
    line-height: 1.52;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
    .workspace {
        grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
    }

    .result-panel {
        grid-column: 1 / -1;
        position: static;
    }

    pre {
        min-height: 280px;
        max-height: 460px;
    }
}

@media (max-width: 820px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 16px;
    }

    .status-strip {
        justify-content: stretch;
        width: 100%;
    }

    .status-chip {
        flex: 1 1 120px;
    }

    .workspace {
        width: calc(100% - 18px);
        grid-template-columns: 1fr;
        margin: 12px auto;
    }

    .tabs,
    .province-grid,
    .two-column,
    .form-grid,
    .cupo-summary,
    .affiliate-row {
        grid-template-columns: 1fr;
    }

    .affiliate-fields,
    .affiliate-row button {
        max-width: none;
        width: 100%;
    }

    .tab {
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .operation {
        padding: 16px;
    }

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

    .receipt-box {
        grid-template-columns: 1fr;
    }
}
