:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #697386;
    --line: #d9dee7;
    --accent: #126a72;
    --accent-dark: #0b4f55;
    --danger: #b42318;
    --success: #1f7a4d;
    --warning: #9a6700;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 14px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 800;
    font-size: 20px;
}

.brand img {
    display: block;
    width: auto;
    height: 34px;
    object-fit: contain;
}

.auth-logo {
    display: block;
    width: min(260px, 70vw);
    height: auto;
    margin-bottom: 20px;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 14px;
}

.shell {
    width: min(1120px, calc(100% - 32px));
    margin: 32px auto 56px;
}

.auth-panel {
    min-height: calc(100vh - 180px);
    display: grid;
    grid-template-columns: 1fr minmax(320px, 420px);
    align-items: center;
    gap: 56px;
}

.auth-panel h1,
.page-head h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1.15;
}

.auth-panel p,
.page-head p,
.muted,
.hint {
    color: var(--muted);
}

.page-head {
    margin-bottom: 22px;
}

.page-head.row,
.row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.card,
.table-card,
.proposal-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(20, 31, 44, 0.06);
}

.card { padding: 22px; }
.narrow { max-width: 620px; }
.wide { max-width: 920px; }

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

label,
.label,
legend {
    display: grid;
    gap: 7px;
    font-weight: 700;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 11px 12px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

input[readonly] {
    background: #eef1f5;
}

textarea {
    resize: vertical;
}

fieldset {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 6px 16px 6px 0;
    font-weight: 500;
}

.check input {
    width: auto;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 0;
    border-radius: 6px;
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--accent-dark);
    text-decoration: none;
}

.danger {
    background: var(--danger);
}

.danger:hover {
    background: #7a1b14;
}

.ghost {
    min-height: auto;
    padding: 0;
    background: transparent;
    color: var(--danger);
}

.ghost:hover {
    background: transparent;
    text-decoration: underline;
}

.alerts {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    background: #e9eef6;
    border: 1px solid var(--line);
}

.alert.success { background: #e8f5ee; color: var(--success); }
.alert.danger { background: #fff0ed; color: var(--danger); }
.alert.warning { background: #fff8e6; color: var(--warning); }
.alert.info { background: #eef6ff; color: #235a8f; }

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

.inline-form,
.department-form,
.filters-bar,
.master-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-bottom: 20px;
}

.filters-bar {
    grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(220px, 1.4fr) minmax(180px, 1.2fr) auto;
    align-items: end;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.audit-filter {
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(120px, 160px) auto;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.master-form {
    grid-template-columns: minmax(220px, 1fr) minmax(110px, 160px) minmax(220px, 1fr) auto;
}

.department-form {
    grid-template-columns: minmax(220px, 1fr) minmax(110px, 160px) auto;
}

.table-card {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

td pre {
    max-width: 360px;
    max-height: 220px;
    overflow: auto;
    margin: 8px 0 0;
    white-space: pre-wrap;
    word-break: break-word;
}

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

tr:last-child td {
    border-bottom: 0;
}

.actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.actions.left {
    justify-content: flex-start;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.proposal-card {
    padding: 18px;
    display: grid;
    gap: 10px;
}

.proposal-card h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
}

.proposal-card p {
    margin: 0;
    color: var(--muted);
}

.meta,
.meta-line {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0;
}

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

.meta span {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2px 8px;
}

.list {
    display: grid;
    gap: 10px;
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    margin-top: 16px;
}

.rich-field {
    display: grid;
    gap: 8px;
}

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

.toolbar button {
    min-height: 34px;
    padding: 6px 10px;
    background: #edf2f4;
    color: var(--text);
}

.toolbar button:hover {
    background: #dfe8ea;
}

.editor,
.rich-content {
    min-height: 180px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #fff;
}

.rich-content {
    min-height: auto;
    border: 0;
    padding: 0;
    background: transparent;
}

.editor:focus {
    outline: 2px solid rgba(18, 106, 114, 0.22);
}

.editor img,
.rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.existing-files {
    display: grid;
    gap: 8px;
}

.existing-files > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
}

.upload-panel {
    display: grid;
    gap: 10px;
}

.upload-drop {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 14px;
    background: #fff;
    cursor: pointer;
}

.upload-drop input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.upload-drop span {
    color: var(--accent);
    font-weight: 800;
}

.upload-progress {
    width: min(100%, 520px);
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #d8dde6;
}

.upload-progress div {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 120ms ease;
}

.detail {
    display: grid;
    gap: 22px;
}

.detail section h2 {
    margin: 0 0 8px;
}

.empty {
    max-width: 560px;
    margin: 80px auto;
    text-align: center;
}

.import-result {
    margin-top: 18px;
}

.import-result h2,
.import-result h3 {
    margin-top: 0;
}

.strength {
    display: grid;
    grid-template-columns: repeat(5, 1fr) auto;
    gap: 6px;
    align-items: center;
}

.strength span {
    height: 8px;
    border-radius: 999px;
    background: #d8dde6;
}

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

.strength.score-1 span:nth-child(-n+1),
.strength.score-2 span:nth-child(-n+2) { background: #d92d20; }
.strength.score-3 span:nth-child(-n+3) { background: #dc8a00; }
.strength.score-4 span:nth-child(-n+4) { background: #238457; }
.strength.score-5 span:nth-child(-n+5) { background: #126a72; }

@media (max-width: 760px) {
    .topbar,
    .page-head.row,
    .row,
    .actions {
        align-items: stretch;
        flex-direction: column;
    }

    .auth-panel,
    .two-cols,
    .inline-form,
    .department-form,
    .filters-bar,
    .audit-filter,
    .master-form {
        grid-template-columns: 1fr;
    }

    .auth-panel {
        gap: 24px;
        align-items: start;
    }

    .nav {
        justify-content: flex-start;
    }
}
