:root {
    --bg: linear-gradient(135deg, #f5f0e7 0%, #e7eef5 52%, #dde9d8 100%);
    --panel: rgba(255, 255, 255, 0.84);
    --panel-strong: #ffffff;
    --text: #173042;
    --muted: #5b7487;
    --line: rgba(23, 48, 66, 0.12);
    --accent: #1d7f5f;
    --accent-soft: #d9efe5;
    --shadow: 0 24px 70px rgba(35, 58, 77, 0.12);
    --radius: 24px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Manrope", sans-serif;
    color: var(--text);
    background: var(--bg);
}

body.modal-open {
    overflow: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

input,
select {
    width: 100%;
    border-radius: 16px;
    border: 1px solid rgba(23, 48, 66, 0.14);
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
}

label {
    display: grid;
    gap: 8px;
}

label span {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.page-shell {
    display: grid;
    grid-template-columns: 360px 1fr;
    min-height: 100vh;
}

.hero-panel {
    padding: 42px 34px;
    background:
        radial-gradient(circle at top left, rgba(29, 127, 95, 0.24), transparent 42%),
        radial-gradient(circle at bottom right, rgba(185, 87, 51, 0.18), transparent 33%);
    border-right: 1px solid rgba(255, 255, 255, 0.36);
}

.hero-badge {
    display: inline-flex;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.62);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 12px;
}

.hero-panel h1 {
    margin: 28px 0 14px;
    font-size: 38px;
    line-height: 1.04;
}

.hero-panel p {
    margin: 0 0 26px;
    color: var(--muted);
    line-height: 1.7;
}

.hero-grid {
    display: grid;
    gap: 16px;
}

.hero-card,
.panel,
.toolbar,
.quick-nav,
.view-switch {
    border: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: blur(14px);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}

.hero-card {
    padding: 18px 20px;
}

.hero-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.content-panel {
    padding: 34px;
    display: grid;
    gap: 18px;
    align-content: start;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
    align-items: center;
    padding: 14px;
}

.quick-nav,
.view-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 12px;
}

.quick-nav {
    position: sticky;
    top: 12px;
    z-index: 10;
}

.quick-link,
.view-switch-btn,
.primary-btn,
.ghost-btn {
    border-radius: 16px;
    padding: 12px 18px;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.quick-link,
.view-switch-btn,
.ghost-btn {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    color: var(--text);
}

.quick-link.is-active,
.view-switch-btn.is-active {
    background: linear-gradient(135deg, rgba(29, 127, 95, 0.14), rgba(47, 152, 118, 0.22));
    border-color: rgba(29, 127, 95, 0.28);
    color: #114734;
}

.compact-link {
    padding-inline: 14px;
}

.primary-btn {
    border: none;
    background: linear-gradient(135deg, #206b55, #2f9876);
    color: #fff;
    box-shadow: 0 16px 28px rgba(29, 127, 95, 0.26);
}

.primary-btn:hover,
.ghost-btn:hover,
.quick-link:hover,
.view-switch-btn:hover {
    transform: translateY(-1px);
}

.panel {
    padding: 24px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
}

.section-head h2 {
    margin: 0 0 8px;
    font-size: 24px;
}

.section-head p {
    margin: 0;
    color: var(--muted);
}

.settings-view.hidden,
.debug-content.hidden,
.modal-shell.hidden,
.toast.hidden,
.hidden {
    display: none;
}

.settings-columns {
    display: grid;
    grid-template-columns: minmax(320px, 0.86fr) minmax(420px, 1.14fr);
    gap: 18px;
    align-items: start;
}

.settings-form,
.department-form {
    display: grid;
    gap: 16px;
}

.department-tab-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.6);
}

.department-tab-btn {
    flex: 1 1 180px;
    border: 0;
    border-radius: 14px;
    padding: 11px 14px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.department-tab-btn.is-active {
    background: linear-gradient(135deg, #206b55, #2f9876);
    color: #fff;
    box-shadow: 0 10px 20px rgba(29, 127, 95, 0.2);
}

.department-tab-panel {
    display: grid;
    gap: 16px;
}

.department-tab-panel.hidden {
    display: none;
}

.form-card {
    display: grid;
    gap: 16px;
    padding: 20px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.68);
}

.form-card h3 {
    margin: 0;
    font-size: 18px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.toggle-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.toggle {
    min-height: 58px;
    align-content: center;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid rgba(23, 48, 66, 0.12);
    background: rgba(255, 255, 255, 0.84);
}

.toggle input {
    width: 20px;
    height: 20px;
    justify-self: start;
    margin-top: 6px;
    accent-color: var(--accent);
}

.field-with-action {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
}

.inline-action-btn {
    white-space: nowrap;
}

.hint-box {
    margin-bottom: 18px;
    padding: 16px 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid var(--line);
}

.hint-box strong {
    display: block;
    margin-bottom: 10px;
}

.inline-note {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
}

.inline-note code {
    padding: 2px 6px;
    border-radius: 8px;
    background: rgba(23, 48, 66, 0.08);
}

.form-actions {
    display: flex;
    gap: 12px;
}

.full-span {
    grid-column: 1 / -1;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
}

.department-card {
    display: grid;
    gap: 10px;
    padding: 18px;
    border-radius: 18px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
}

.department-card h3 {
    margin: 0;
}

.department-card p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
}

.department-card strong {
    color: var(--text);
}

.selected-values-box {
    min-height: 54px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 16px;
    border: 1px solid rgba(23, 48, 66, 0.14);
    background: rgba(255, 255, 255, 0.92);
}

.selected-pill {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(29, 127, 95, 0.12), rgba(47, 152, 118, 0.18));
    border: 1px solid rgba(29, 127, 95, 0.18);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.selected-placeholder {
    color: var(--muted);
    font-size: 14px;
}

.option-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.option-chip {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(29, 127, 95, 0.18);
    background: var(--accent-soft);
    color: var(--text);
}

.multi-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.bounded-scroll {
    max-height: 380px;
    overflow-y: auto;
    padding-right: 6px;
}

.bounded-scroll::-webkit-scrollbar {
    width: 10px;
}

.bounded-scroll::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(29, 127, 95, 0.24);
}

.multi-option {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 14px;
    min-height: 54px;
    padding: 14px 16px;
    border-radius: 18px;
    border: 1px solid rgba(23, 48, 66, 0.12);
    background: rgba(255, 255, 255, 0.92);
    transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.multi-option:hover {
    transform: translateY(-1px);
    border-color: rgba(29, 127, 95, 0.28);
    box-shadow: 0 10px 22px rgba(23, 48, 66, 0.08);
}

.multi-option input {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--accent);
}

.multi-option.is-selected {
    background: linear-gradient(135deg, rgba(29, 127, 95, 0.12), rgba(47, 152, 118, 0.18));
    border-color: rgba(29, 127, 95, 0.34);
    box-shadow: 0 14px 26px rgba(29, 127, 95, 0.12);
}

.stage-rules-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.stage-rules-list {
    display: grid;
    gap: 12px;
}

.stage-rule-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.9);
}

.stage-rule-remove {
    justify-self: start;
}

.mapping-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.mapping-item {
    display: grid;
    gap: 10px;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
}

.mapping-item-title {
    font-weight: 800;
}

.debug-table {
    width: 100%;
    border-collapse: collapse;
}

.debug-table th,
.debug-table td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

.modal-shell {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 40;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(14, 28, 40, 0.46);
}

.modal-panel {
    position: relative;
    width: min(880px, 100%);
    max-height: min(82vh, 900px);
    overflow-y: auto;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    box-shadow: 0 30px 90px rgba(15, 33, 49, 0.24);
    padding: 24px;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.modal-head h3 {
    margin: 0 0 8px;
}

.modal-head p {
    margin: 0;
    color: var(--muted);
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    padding: 14px 18px;
    border-radius: 16px;
    background: #173042;
    color: white;
    box-shadow: var(--shadow);
    z-index: 60;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 80;
}

.loading-overlay.hidden {
    display: none;
}

.loading-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(14, 28, 40, 0.42);
    backdrop-filter: blur(5px);
}

.loading-overlay-card {
    position: relative;
    width: min(420px, 100%);
    display: grid;
    justify-items: center;
    gap: 14px;
    text-align: center;
    padding: 28px 24px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.42);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 30px 90px rgba(15, 33, 49, 0.24);
}

.loading-overlay-card strong {
    font-size: 20px;
}

.loading-overlay-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.loading-spinner {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 4px solid rgba(29, 127, 95, 0.16);
    border-top-color: var(--accent);
    animation: loading-spin 0.85s linear infinite;
}

@keyframes loading-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1260px) {
    .page-shell {
        grid-template-columns: 1fr;
    }

    .settings-columns {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .content-panel,
    .hero-panel {
        padding: 24px;
    }

    .card-grid,
    .toggle-grid,
    .stage-rule-row {
        grid-template-columns: 1fr;
    }

    .field-with-action {
        grid-template-columns: 1fr;
    }

    .toolbar {
        justify-content: stretch;
    }

    .toolbar > * {
        flex: 1 1 100%;
    }

    .quick-nav,
    .view-switch {
        gap: 8px;
    }
}
