:root {
    --bg: hsl(220, 14%, 97%);
    --panel: hsl(0, 0%, 100%);
    --panel-soft: hsl(220, 20%, 98%);
    --border: hsl(220, 13%, 86%);
    --border-strong: hsl(220, 10%, 76%);
    --text: hsl(0, 0%, 9%);
    --muted: hsl(220, 6%, 46%);
    --accent: hsl(357, 76%, 46%);
    --accent-soft: hsl(357, 82%, 96%);
    --shadow: 0 8px 24px hsla(0, 0%, 0%, 0.08);
    --r: 8px;
    --font: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    line-height: 1.45;
}

.policy-app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.policy-topbar {
    height: 58px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 18px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.policy-title {
    font-size: 16px;
    font-weight: 700;
}

.policy-subtitle {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.chat-link {
    height: 32px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
    background: var(--panel);
}

.chat-link:hover {
    border-color: var(--border-strong);
    color: var(--accent);
}

.policy-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 260px 360px minmax(0, 1fr);
    gap: 1px;
    background: var(--border);
}

.province-pane,
.doc-pane,
.reader-pane {
    min-height: 0;
    background: var(--panel);
}

.province-pane,
.doc-pane {
    display: flex;
    flex-direction: column;
}

.pane-head {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 650;
}

.pane-head strong {
    color: var(--muted);
    font-size: 12px;
}

.province-list,
.doc-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.province-item,
.doc-item {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.province-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.province-item:hover,
.province-item.active {
    background: var(--accent-soft);
}

.province-name {
    font-weight: 650;
}

.province-count {
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}

.province-years {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-toolbar {
    display: grid;
    grid-template-columns: 118px 1fr;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.doc-toolbar select,
.doc-toolbar input {
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--panel);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    padding: 0 10px;
    outline: none;
    min-width: 0;
}

.doc-toolbar select:focus,
.doc-toolbar input:focus {
    border-color: var(--accent);
}

.doc-year-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--panel-soft);
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.doc-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
}

.doc-item:hover,
.doc-item.active {
    background: var(--accent-soft);
}

.doc-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.doc-meta {
    font-size: 12px;
    color: var(--muted);
}

.reader-pane {
    min-width: 0;
    overflow: hidden;
}

.reader-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--muted);
    padding: 24px;
}

.reader-empty-title {
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.reader-doc {
    height: 100%;
    overflow-y: auto;
    padding: 26px min(5vw, 58px) 56px;
}

.reader-meta {
    max-width: 860px;
    margin: 0 auto 22px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.reader-province {
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 8px;
}

.reader-meta h1 {
    font-size: 26px;
    line-height: 1.25;
    margin-bottom: 10px;
}

.reader-source {
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.reader-content {
    max-width: 860px;
    margin: 0 auto;
    font-size: 15px;
    color: var(--text);
}

.reader-content h1,
.reader-content h2,
.reader-content h3 {
    line-height: 1.25;
    margin: 1.2em 0 0.5em;
}

.reader-content h1 { font-size: 24px; }
.reader-content h2 { font-size: 20px; }
.reader-content h3 { font-size: 17px; }

.reader-content p,
.reader-content ul,
.reader-content blockquote,
.reader-content pre {
    margin: 0.75em 0;
}

.reader-content ul {
    padding-left: 1.3em;
}

.reader-content blockquote {
    padding: 8px 12px;
    border-left: 3px solid var(--accent);
    background: var(--panel-soft);
    color: var(--muted);
}

.reader-content code {
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 4px;
}

.reader-content pre {
    padding: 12px;
    overflow-x: auto;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: var(--r);
}

.reader-content a {
    color: var(--accent);
}

.loading,
.error,
.empty-list {
    padding: 14px;
    color: var(--muted);
    font-size: 13px;
}

.error {
    color: hsl(0, 65%, 48%);
}

@media (max-width: 980px) {
    body {
        overflow: auto;
    }
    .policy-app {
        min-height: 100%;
        height: auto;
    }
    .policy-layout {
        grid-template-columns: 1fr;
        min-height: 0;
    }
    .province-pane,
    .doc-pane,
    .reader-pane {
        min-height: 220px;
    }
    .province-list,
    .doc-list {
        max-height: 320px;
    }
    .reader-doc {
        height: auto;
        min-height: 480px;
        padding: 20px 16px 40px;
    }
}
