:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --ink: #172033;
    --muted: #687386;
    --line: #dfe5ef;
    --nav: #121b31;
    --nav-soft: #1c2947;
    --primary: #2857d6;
    --primary-dark: #1f43a7;
    --success: #117a55;
    --danger: #b42318;
    --warning: #a15c00;
    --radius: 14px;
    --shadow: 0 10px 32px rgba(23, 32, 51, .07);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--ink); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2vw, 1.8rem); }
h2 { margin-bottom: .45rem; font-size: 1.1rem; }
small { display: block; color: var(--muted); margin-top: .2rem; }
code { font-size: .82rem; color: #304264; overflow-wrap: anywhere; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 1.35rem 1rem; background: var(--nav); color: #dce4f5; z-index: 30; }
.brand { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; flex: none; border-radius: 12px; background: linear-gradient(145deg, #4f7cff, #2451cb); color: #fff; font-weight: 800; letter-spacing: -.03em; }
.brand strong, .brand small { display: block; }
.brand small { max-width: 160px; color: #93a2bd; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { margin-top: 2rem; display: grid; gap: .35rem; }
.nav a { padding: .72rem .8rem; border-radius: 9px; color: #b9c5da; transition: background .15s ease, color .15s ease; }
.nav a:hover, .nav a.active { color: #fff; background: var(--nav-soft); }

.main-shell { min-width: 0; }
.topbar { min-height: 88px; padding: 1.1rem clamp(1rem, 3vw, 2.3rem); display: flex; align-items: center; gap: 1rem; justify-content: space-between; background: rgba(255, 255, 255, .92); border-bottom: 1px solid var(--line); }
.topbar > div:nth-child(2) { margin-right: auto; }
.user-box { display: flex; align-items: center; gap: 1rem; text-align: right; }
.user-box span { max-width: 220px; }
.user-box small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-button { display: none; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.content { padding: 1.4rem clamp(1rem, 3vw, 2.3rem) 3rem; }
.content > * + * { margin-top: 1rem; }

.eyebrow { margin: 0 0 .28rem; color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.muted { color: var(--muted); }
.panel { padding: 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.narrow { max-width: 720px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.section-heading p:last-child { margin-bottom: 0; }
.grid { display: grid; gap: 1rem; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric { min-height: 112px; padding: 1rem; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.metric span { color: var(--muted); }
.metric strong { font-size: 1.75rem; }
.metric.accent { color: #fff; background: var(--primary); border-color: var(--primary); }
.metric.accent span { color: #dce5ff; }
.welcome-card { padding: 1.4rem; display: flex; justify-content: space-between; align-items: center; gap: 1.2rem; color: #fff; border-radius: var(--radius); background: linear-gradient(125deg, #15203a, #2857d6); box-shadow: var(--shadow); }
.welcome-card .eyebrow { color: #bfcfff; }
.welcome-card p:last-child { margin-bottom: 0; color: #d7e0f7; }
.role-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.process-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.process-card { border-left: 4px solid #bec7d7; }
.process-card.state-started { border-left-color: #f59e0b; }
.process-card.state-finished { border-left-color: #16a36e; }
.process-card.state-not_used { border-left-color: #7d8797; }

.btn { min-height: 38px; padding: .52rem .82rem; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; font-weight: 700; line-height: 1; white-space: nowrap; }
.btn:hover { border-color: #bec9da; }
.btn-primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.btn-primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.btn-success { color: #fff; border-color: var(--success); background: var(--success); }
.btn-danger { color: #fff; border-color: var(--danger); background: var(--danger); }
.btn-light { color: #15203a; border-color: #fff; background: #fff; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 32px; padding: .4rem .62rem; font-size: .82rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: end; }
.form-grid.single { grid-template-columns: 1fr; }
.form-grid > .full, .form-grid > fieldset.full { grid-column: 1 / -1; }
label { display: grid; gap: .4rem; color: #38445a; font-size: .88rem; font-weight: 700; }
input, select, textarea { width: 100%; padding: .62rem .7rem; color: var(--ink); border: 1px solid #cfd7e5; border-radius: 8px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(40, 87, 214, .12); }
input:disabled, select:disabled, textarea:disabled { color: #697386; background: #f2f4f8; }
textarea { resize: vertical; }
fieldset { min-width: 0; margin: 0; padding: 1rem; display: grid; align-content: start; gap: .6rem; border: 1px solid var(--line); border-radius: 10px; }
legend { padding: 0 .35rem; color: #38445a; font-size: .85rem; font-weight: 800; }
.check-label, .assignment-card { display: flex; align-items: center; gap: .65rem; }
.check-label input, .assignment-card input, .permission-table input { width: 18px; height: 18px; flex: none; accent-color: var(--primary); }
.assignment-grid { margin-bottom: 1rem; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem; }
.assignment-card { padding: .8rem; border: 1px solid var(--line); border-radius: 9px; }
.inline-form { display: flex; align-items: end; gap: .5rem; }
.reset-form { margin-top: .8rem; }

.permission-table { display: grid; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.permission-table > div { padding: .65rem .8rem; display: grid; grid-template-columns: minmax(0, 1fr) 90px 90px; align-items: center; gap: .5rem; border-top: 1px solid var(--line); }
.permission-table > div:first-child { border-top: 0; background: #f5f7fb; }
.permission-table input, .permission-table strong:not(:first-child) { justify-self: center; }

.table-wrap { overflow-x: auto; }
.table-wrap.panel { padding: 0; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .78rem .9rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { color: #667186; background: #f7f9fc; font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
td input, td select, td textarea { min-width: 100px; }
.import-table { max-height: 65vh; }
.import-table table { min-width: 1750px; }
.import-table th { position: sticky; top: 0; z-index: 2; }
.import-table td input + input { margin-top: .35rem; }
.review-toolbar { position: sticky; top: .5rem; z-index: 8; padding: .75rem 1rem; display: flex; align-items: center; gap: 1rem; }
.review-toolbar .muted { margin-left: auto; }
.review-table { max-height: none; }
.review-table table { min-width: 2140px; font-size: .75rem; }
.review-table th, .review-table td { padding: .4rem .45rem; }
.review-table td { vertical-align: top; }
.review-table input, .review-table select, .review-table textarea { width: 82px; min-width: 0; padding: .34rem .38rem; border-radius: 6px; font-size: .75rem; }
.review-table .review-datetime { width: 148px; }
.review-table input[type="checkbox"] { width: 17px; height: 17px; padding: 0; accent-color: var(--primary); }
.review-select-col { width: 34px; text-align: center; }
.review-message { min-width: 150px; max-width: 220px; }
.review-message small { margin: 0; }
.review-actions { min-width: 92px; }
.review-actions form { margin-bottom: .3rem; }
.review-actions .btn { width: 100%; }
.review-more { position: relative; color: var(--primary); font-weight: 700; cursor: pointer; }
.review-more > div { position: absolute; right: 0; z-index: 12; width: 310px; padding: .7rem; display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: var(--shadow); }
.review-more .full { grid-column: 1 / -1; }
.row-invalid { background: #fff5f4; }
.row-duplicate { background: #fff9eb; }

.badge { padding: .25rem .52rem; display: inline-block; border-radius: 999px; color: #42506a; background: #edf1f7; font-size: .72rem; font-weight: 800; }
.badge.active, .badge.valid, .badge.finished, .badge.completed, .badge.imported { color: #087049; background: #e8f8f1; }
.badge.inactive, .badge.archived, .badge.revoked { color: #5d6879; background: #edf0f4; }
.badge.scheduled, .badge.preview, .badge.processing, .badge.started { color: #1c55aa; background: #e9f1ff; }
.badge.cancelled, .badge.invalid, .badge.failed { color: #a1281e; background: #ffebe9; }
.badge.duplicate, .badge.completed_with_errors { color: #8c5200; background: #fff3d5; }
.tabs { margin-top: 1rem; display: flex; gap: .3rem; overflow-x: auto; }
.tabs a { padding: .5rem .72rem; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.tabs a.active { color: var(--primary); background: #eaf0ff; font-weight: 800; }
.notice { color: #36435a; background: #f3f6fc; border-color: #d8e1f1; }
.danger-zone { border-color: #f2c7c3; }
.danger-zone h2, .text-danger, .error-text { color: var(--danger); }
.error-text { margin-top: .35rem; }
.summary-row { margin-top: 1rem; display: flex; flex-wrap: wrap; gap: .6rem; }
.summary-row span { padding: .4rem .65rem; border-radius: 8px; background: #f2f5fa; }
.commit-bar { margin-top: 1rem; padding: 1rem 1.2rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; color: #fff; border-radius: var(--radius); background: #17233c; }
.commit-bar p { margin: .25rem 0 0; color: #bcc8df; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }
.flash { margin: 1rem clamp(1rem, 3vw, 2.3rem) 0; padding: .8rem 1rem; border: 1px solid; border-radius: 10px; }
.flash.success { color: #096c49; border-color: #b7e5d4; background: #ebfaf4; }
.flash.error { color: #96241b; border-color: #f3c5c1; background: #fff0ef; }

.auth-page { display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top right, #334f98, #121b31 55%); }
.auth-card { width: min(100%, 430px); padding: 1.6rem; border-radius: 18px; background: #fff; box-shadow: 0 24px 70px rgba(0, 0, 0, .28); }
.auth-brand { margin-bottom: 1.5rem; }
.auth-brand small { color: var(--muted); }
.auth-note { margin: 1.2rem 0 0; text-align: center; font-size: .84rem; }

@media (max-width: 1100px) {
    .cards-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .role-grid, .assignment-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: 250px; transition: transform .2s ease; box-shadow: 16px 0 40px rgba(0, 0, 0, .25); }
    .menu-open .sidebar { transform: translateX(0); }
    .menu-button { display: inline-block; }
    .user-box > span { display: none; }
}

@media (max-width: 680px) {
    .topbar { min-height: 76px; }
    .content { padding-bottom: 2rem; }
    .cards-4, .role-grid, .process-grid, .form-grid, .assignment-grid { grid-template-columns: 1fr; }
    .form-grid > .full, .form-grid > fieldset.full { grid-column: auto; }
    .section-heading, .welcome-card, .commit-bar { align-items: stretch; flex-direction: column; }
    .permission-table > div { grid-template-columns: minmax(0, 1fr) 55px 55px; }
    .review-toolbar { position: static; align-items: stretch; flex-direction: column; }
    .review-toolbar .muted { margin-left: 0; }
    .review-table { overflow: visible; background: transparent; border: 0; box-shadow: none; }
    .review-table table { min-width: 0; }
    .review-table thead { display: none; }
    .review-table tbody { padding: 0; display: grid; gap: .7rem; }
    .review-table tr { padding: .65rem; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .45rem; border: 1px solid var(--line); border-radius: 11px; background: #fff; box-shadow: var(--shadow); }
    .review-table tr.row-invalid { background: #fff5f4; }
    .review-table tr.row-duplicate { background: #fff9eb; }
    .review-table td { padding: 0; display: grid; align-content: start; gap: .25rem; border: 0; }
    .review-table td::before { content: attr(data-label); color: var(--muted); font-size: .62rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
    .review-table .review-select-col, .review-table .review-message, .review-table .review-actions { grid-column: 1 / -1; }
    .review-table .review-select-col { display: flex; justify-content: flex-end; }
    .review-table .review-select-col::before { margin-right: auto; }
    .review-table input, .review-table select, .review-table textarea, .review-table .review-datetime { width: 100%; }
    .review-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
    .review-actions form { margin: 0; }
    .review-more { grid-column: 1 / -1; }
    .review-more > div { position: static; width: 100%; margin-top: .45rem; }
}
