:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-muted: #edf2f5;
    --text: #18202a;
    --muted: #657181;
    --line: #d8dee6;
    --primary: #176b87;
    --primary-dark: #0f5167;
    --accent: #b7791f;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --shadow: 0 10px 24px rgba(24, 32, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.6;
}

a {
    color: var(--primary);
}

input,
textarea,
button {
    font: inherit;
}

textarea,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="file"],
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.75rem;
    background: var(--surface);
    color: var(--text);
}

textarea:focus,
input:focus,
select:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(23, 107, 135, 0.15);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.site-header {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 34px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}

.brand-name,
.user-status {
    white-space: nowrap;
}

.app-body {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: calc(100vh - 64px);
}

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 1rem;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    max-height: calc(100vh - 64px);
    max-height: calc(100dvh - 64px);
    overflow: hidden;
    padding: 1rem;
    background: #23313c;
    color: #fff;
}

.side-nav {
    display: grid;
    align-content: start;
    gap: 0.35rem;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 0.15rem;
}

.side-section-title {
    margin-top: 1rem;
    color: #b7c4cd;
    font-size: 0.85rem;
    font-weight: 700;
}

.side-link {
    display: block;
    padding: 0.7rem 0.75rem;
    border-radius: 6px;
    color: #eef5f7;
    text-decoration: none;
}

.side-link:hover,
.side-link.is-active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.logout-form {
    flex: 0 0 auto;
    margin: 0;
}

.main-content {
    width: 100%;
    max-width: 1120px;
    padding: 2rem;
}

.site-footer {
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--line);
    color: var(--muted);
}

.page-heading {
    margin-bottom: 1.5rem;
}

.page-heading h1 {
    margin: 0 0 0.4rem;
    font-size: 1.8rem;
}

.page-heading p {
    margin: 0;
    color: var(--muted);
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.tool-card,
.tool-form,
.result-panel,
.login-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.tool-card {
    padding: 1.25rem;
}

.tool-card h2 {
    margin: 0 0 0.5rem;
    font-size: 1.15rem;
}

.tool-card p {
    color: var(--muted);
}

.tool-form,
.result-panel {
    display: grid;
    gap: 1rem;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.tool-help {
    margin: 0 0 1.25rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.tool-help summary {
    padding: 0.9rem 1rem;
    cursor: pointer;
    color: var(--primary-dark);
    font-weight: 700;
}

.tool-help summary:hover {
    background: var(--surface-muted);
}

.tool-help-body {
    padding: 0 1.25rem 1.25rem;
    border-top: 1px solid var(--line);
}

.tool-help-body h1 {
    margin: 1rem 0 0.5rem;
    font-size: 1.35rem;
}

.tool-help-body h2 {
    margin: 1.1rem 0 0.45rem;
    padding-top: 0.2rem;
    border-top: 1px solid var(--line);
    font-size: 1.1rem;
}

.tool-help-body h3 {
    margin: 0.9rem 0 0.35rem;
    font-size: 1rem;
}

.tool-help-body p,
.tool-help-body ul,
.tool-help-body ol {
    margin: 0.45rem 0;
}

.tool-help-body ul,
.tool-help-body ol {
    padding-left: 1.35rem;
}

.tool-help-body li + li {
    margin-top: 0.2rem;
}

.tool-help-body code {
    border-radius: 4px;
    padding: 0.1rem 0.25rem;
    background: var(--surface-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}

.tool-help-body pre {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.75rem;
    background: #f8fafc;
}

.tool-help-body pre code {
    padding: 0;
    background: transparent;
}

.tool-form label,
.result-panel label,
.form-stack label {
    display: grid;
    gap: 0.35rem;
    font-weight: 700;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.75rem;
}

legend {
    padding: 0 0.35rem;
    font-weight: 700;
}

.radio-row,
.tool-form label.radio-row,
.result-panel label.radio-row,
.form-stack label.radio-row {
    display: inline-flex;
    grid-template-columns: none;
    align-items: center;
    justify-content: flex-start;
    gap: 0.4rem;
    margin-right: 1rem;
    width: auto;
    font-weight: 400;
    cursor: pointer;
}

.tool-form label.radio-row {
    margin-bottom: 0.35rem;
}

.radio-row span {
    display: inline;
    min-width: 0;
    line-height: 1.4;
}

.radio-row input[type="checkbox"],
.radio-row input[type="radio"] {
    width: auto;
    min-width: 0;
    margin: 0;
    flex: 0 0 auto;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.5rem 0.9rem;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
}

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

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    width: 100%;
    background: #fff;
    color: #23313c;
}

.alert {
    border-radius: 6px;
    padding: 0.75rem 1rem;
}

.alert-error {
    border: 1px solid rgba(180, 35, 24, 0.25);
    background: var(--danger-bg);
    color: var(--danger);
}

.result-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin: 0;
}

.result-list div {
    padding: 0.75rem;
    background: var(--surface-muted);
    border-radius: 6px;
}

.result-list dt {
    color: var(--muted);
    font-size: 0.85rem;
}

.result-list dd {
    margin: 0.2rem 0 0;
    font-size: 1.4rem;
    font-weight: 800;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 1rem;
}

.login-panel {
    width: min(100%, 420px);
    padding: 1.5rem;
}

.login-brand {
    display: grid;
    gap: 0.75rem;
    justify-items: start;
    margin-bottom: 1.25rem;
}

.login-brand h1 {
    margin: 0;
    font-size: 1.45rem;
}

.form-stack {
    display: grid;
    gap: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.field-help {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 400;
}

.required {
    color: var(--danger);
    font-size: 0.82rem;
}

.alert-success {
    border: 1px solid rgba(23, 107, 135, 0.22);
    background: #edf8fb;
    color: var(--primary-dark);
}

.warning-box {
    border: 1px solid #ead7b7;
    border-radius: 6px;
    padding: 1rem;
    background: #fff8ec;
}

.warning-box h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.proceedings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.75rem;
}

.proceedings-tabs a {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    background: var(--surface-muted);
    text-decoration: none;
    font-weight: 700;
}

.settings-section {
    display: grid;
    gap: 1rem;
    border-top: 1px solid var(--line);
    padding-top: 1rem;
}

.settings-section h2 {
    margin: 0;
    font-size: 1.2rem;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.data-table {
    width: 100%;
    min-width: 1280px;
    border-collapse: collapse;
    background: var(--surface);
}

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--line);
    padding: 0.45rem;
    vertical-align: top;
}

.data-table th {
    background: var(--surface-muted);
    text-align: left;
    white-space: nowrap;
}

.data-table input,
.data-table select,
.data-table textarea {
    min-width: 90px;
    padding: 0.4rem;
    font-size: 0.9rem;
}

.data-table textarea {
    min-width: 220px;
}

.data-table tr.is-warning {
    background: #fff8ec;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    position: sticky;
    bottom: 0;
    border-top: 1px solid var(--line);
    padding-top: 1rem;
    background: var(--surface);
}

.pdf-preview {
    width: 100%;
    min-height: 620px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-muted);
}

.skip-link {
    position: absolute;
    left: -999px;
    top: 0;
}

.skip-link:focus {
    left: 1rem;
    top: 1rem;
    z-index: 10;
    background: #fff;
    padding: 0.5rem;
}

@media (max-width: 760px) {
    .site-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem;
    }

    .app-body {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: block;
        position: static;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .side-nav {
        overflow-y: visible;
        padding-right: 0;
    }

    .main-content {
        padding: 1rem;
    }
}
