:root {
    --bg: #eef3f7;
    --surface: #ffffff;
    --surface-soft: #f7fafc;
    --text: #15202b;
    --muted: #52606d;
    --border: #cdd8e2;
    --accent: #075985;
    --accent-strong: #064663;
    --accent-soft: #e7f5fb;
    --focus: #ffb000;
    --notice: #8a4b08;
    --notice-soft: #fff7e8;
    --danger: #9b1c1c;
    --ok: #176b3a;
    --shadow: 0 .35rem 1.25rem rgba(15, 38, 55, .08);
    --font-scale: 1;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
html { font-size: calc(16px * var(--font-scale)); }
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    line-height: 1.45;
    text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 4px solid var(--focus);
    outline-offset: 3px;
}

.skip-link {
    position: fixed;
    z-index: 1000;
    top: .5rem;
    left: .5rem;
    transform: translateY(-180%);
    padding: .75rem 1rem;
    background: #000;
    color: #fff;
    border-radius: .55rem;
    font-weight: 800;
}
.skip-link:focus { transform: translateY(0); }

.app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
}

.site-header {
    min-height: 4.35rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .65rem clamp(.8rem, 2vw, 1.5rem);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
}
.brand-mark {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 2.95rem;
    height: 2.95rem;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: .03em;
}
.brand-text {
    max-width: min(46rem, 58vw);
    font-size: 1.02rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-shrink: 0;
}
.icon-button, .header-link, .button {
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .55rem .9rem;
    border: 2px solid var(--accent);
    border-radius: .7rem;
    background: var(--surface);
    color: var(--accent);
    text-decoration: none;
    font-weight: 800;
    cursor: pointer;
}
.icon-button:hover, .header-link:hover, .button:hover { background: var(--accent-soft); }
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-strong); }
.button.danger { border-color: var(--danger); color: var(--danger); }

.accessibility-panel {
    position: fixed;
    z-index: 100;
    top: 4.7rem;
    right: .8rem;
    display: flex;
    flex-wrap: wrap;
    gap: .55rem;
    max-width: min(42rem, calc(100vw - 1.6rem));
    padding: .8rem;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: .8rem;
    box-shadow: 0 .6rem 2rem rgba(0,0,0,.16);
}
.accessibility-panel[hidden] { display: none; }
.accessibility-panel button {
    min-height: 2.75rem;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: .55rem;
    background: var(--surface);
    color: var(--text);
    font-weight: 750;
}

.primary-nav {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    background: var(--accent);
    box-shadow: 0 .15rem .5rem rgba(0,0,0,.08);
}
.primary-nav a {
    min-height: 3.1rem;
    display: grid;
    place-items: center;
    padding: .45rem .55rem;
    text-align: center;
    text-decoration: none;
    color: #fff;
    font-weight: 800;
    border-right: 1px solid rgba(255,255,255,.22);
}
.primary-nav a:last-child { border-right: 0; }
.primary-nav a:hover { background: rgba(0,0,0,.13); }
.primary-nav a[aria-current="page"] {
    background: var(--accent-strong);
    text-decoration: underline;
    text-underline-offset: .25em;
}
.home-page .primary-nav { display: none; }
.home-page .app-shell { grid-template-rows: auto minmax(0, 1fr); }

.screen-main {
    min-height: 0;
    overflow: hidden;
    padding: clamp(.8rem, 1.6vw, 1.5rem);
}

/* Головний екран */
.home-screen {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: clamp(.7rem, 1.5vh, 1.1rem);
}
.home-intro { text-align: center; }
.home-eyebrow {
    margin: 0 0 .08rem;
    color: var(--accent);
    font-size: .82rem;
    font-weight: 900;
    letter-spacing: .11em;
    text-transform: uppercase;
}
.home-heading {
    margin: 0;
    font-size: clamp(1.5rem, 2.7vw, 2.45rem);
    line-height: 1.12;
}
.home-lead {
    margin: .2rem 0 0;
    color: var(--muted);
    font-size: clamp(.92rem, 1.25vw, 1.05rem);
    font-weight: 650;
}
.home-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: clamp(.55rem, 1.35vw, 1rem);
}
.home-tile {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: clamp(.7rem, 1.25vw, 1.05rem);
    padding: clamp(1rem, 2vw, 1.8rem);
    border: 2px solid transparent;
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
}
.home-tile::after {
    content: "→";
    position: absolute;
    right: .9rem;
    bottom: .55rem;
    color: var(--accent);
    font-size: 1.15rem;
    font-weight: 900;
    opacity: .7;
}
.home-tile:hover {
    border-color: var(--accent);
    background: #fbfdff;
    transform: translateY(-1px);
}
.tile-icon {
    width: clamp(3.6rem, 6vw, 5.8rem);
    height: clamp(3.6rem, 6vw, 5.8rem);
    display: grid;
    place-items: center;
    border-radius: .95rem;
    background: var(--accent-soft);
    color: var(--accent);
}
.tile-icon svg { width: 58%; height: 58%; fill: currentColor; }
.tile-copy { min-width: 0; display: grid; gap: .22rem; padding-right: 1rem; }
.tile-copy strong {
    font-size: clamp(1.15rem, 1.8vw, 1.65rem);
    line-height: 1.16;
}
.tile-copy small {
    color: var(--muted);
    font-size: clamp(.86rem, 1.1vw, 1rem);
    line-height: 1.25;
}

/* Внутрішні екрани */
.screen-card {
    width: min(1200px, 100%);
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: .8rem;
}
.screen-card > header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
h1 { margin: 0; font-size: clamp(1.45rem, 2.6vw, 2.1rem); }
h2, h3 { margin-top: .25rem; }
.subtle { color: var(--muted); }

.news-list, .document-list {
    min-height: 0;
    display: grid;
    grid-template-rows: repeat(5, minmax(0, 1fr));
    gap: .55rem;
}
.news-row, .document-row {
    min-height: 0;
    display: grid;
    grid-template-columns: 8.5rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    padding: .6rem .85rem;
    border: 1px solid var(--border);
    border-radius: .75rem;
    background: var(--surface);
    overflow: hidden;
}
.news-row time { font-weight: 750; }
.news-copy { min-width: 0; }
.news-copy h2 { margin: 0; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.news-copy p { margin: .18rem 0 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.news-row .button, .document-row .button { min-height: 2.4rem; }
.empty-state { display: grid; place-items: center; min-height: 0; text-align: center; background: var(--surface); border: 1px dashed var(--border); border-radius: .75rem; }

.pager {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: .8rem;
}
.pager > :first-child { justify-self: start; }
.pager > :last-child { justify-self: end; }
.pager-status { font-weight: 750; white-space: nowrap; }

.article-card {
    width: min(1000px, 100%);
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: .8rem;
}
.article-header { display: grid; gap: .4rem; }
.article-meta { color: var(--muted); }
.scroll-panel {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 1rem 1.1rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .8rem;
    scrollbar-gutter: stable;
}
.scroll-panel p:first-child { margin-top: 0; }
.scroll-panel img { max-width: 100%; height: auto; }

.form-card {
    width: min(720px, 100%);
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: .8rem;
}
.form-panel {
    min-height: 0;
    overflow: auto;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .8rem;
}
.field { display: grid; gap: .35rem; margin-bottom: .8rem; }
.field label { font-weight: 750; }
.field input, .field textarea, .field select {
    width: 100%;
    min-height: 2.8rem;
    padding: .6rem .7rem;
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: .55rem;
}
.field textarea { min-height: 7rem; resize: vertical; }
.alert { padding: .7rem .9rem; border-radius: .55rem; margin-bottom: .8rem; }
.alert.error { background: #ffe4e6; color: #7f1d1d; }
.alert.ok { background: #dcfce7; color: #14532d; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

.dashboard-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .8rem;
}
.dashboard-card { padding: 1rem; border: 1px solid var(--border); border-radius: .8rem; background: var(--surface); overflow: hidden; }
.dashboard-card h2 { margin: 0 0 .45rem; }

/* Режими доступності */
body.high-contrast {
    --bg: #000;
    --surface: #000;
    --surface-soft: #000;
    --text: #fff;
    --muted: #fff;
    --border: #fff;
    --accent: #ffeb00;
    --accent-strong: #ffeb00;
    --accent-soft: #111;
    --focus: #00ffff;
    --notice: #ffeb00;
    --notice-soft: #000;
    --shadow: none;
}
body.high-contrast .primary-nav a,
body.high-contrast .button.primary,
body.high-contrast .home-tile:hover { background: #111; }
body.underline-links a { text-decoration: underline !important; text-underline-offset: .18em; }

/* Планшети */
@media (max-width: 900px) {
    .brand-text { max-width: 44vw; }
    .primary-nav { grid-template-columns: repeat(3, 1fr); }
    .primary-nav a { min-height: 2.75rem; }
    .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); }
    .news-row, .document-row { grid-template-columns: 6.5rem minmax(0, 1fr); }
    .news-row > .button, .document-row > .button { display: none; }
    .dashboard-grid { grid-template-columns: 1fr; overflow: auto; }
}

/* Телефони */
@media (max-width: 560px) {
    .site-header { min-height: 3.7rem; padding: .42rem .55rem; }
    .brand-mark { width: 2.4rem; height: 2.4rem; }
    .brand-text { display: none; }
    .header-actions { gap: .35rem; }
    .icon-button, .header-link { min-height: 2.55rem; padding: .42rem .58rem; font-size: .9rem; }
    .screen-main { padding: .48rem; }

    .home-screen { gap: .42rem; }
    .home-eyebrow { display: none; }
    .home-heading { font-size: clamp(1.18rem, 5.1vw, 1.5rem); }
    .home-lead { margin-top: .1rem; font-size: .82rem; }
    .home-grid { gap: .42rem; }
    .home-tile {
        grid-template-columns: auto minmax(0, 1fr);
        gap: .55rem;
        padding: .48rem .52rem;
        border-radius: .72rem;
    }
    .tile-icon { width: clamp(2.2rem, 11vw, 3rem); height: clamp(2.2rem, 11vw, 3rem); border-radius: .7rem; }
    .tile-copy { padding-right: .35rem; }
    .tile-copy strong { font-size: clamp(.88rem, 3.8vw, 1.02rem); }
    .tile-copy small { font-size: .72rem; }
    .home-tile::after { display: none; }

    .news-list, .document-list { grid-template-rows: repeat(4, minmax(0, 1fr)); }
    .news-row, .document-row { grid-template-columns: 5.8rem minmax(0,1fr); gap: .6rem; padding: .45rem .6rem; }
    .news-copy p { display: none; }
    .pager-status { font-size: .86rem; }
}

/* Дуже низькі екрани: зберігаємо повний екран, прибираючи лише другорядні підписи */
@media (max-height: 690px) {
    .site-header { min-height: 3.6rem; }
    .brand-mark { width: 2.35rem; height: 2.35rem; }
    .screen-main { padding-top: .45rem; padding-bottom: .45rem; }
    .home-intro { line-height: 1.1; }
    .home-lead { display: none; }
    .tile-copy small { display: none; }
    .home-tile { padding-top: .45rem; padding-bottom: .45rem; }
}

/* При значному збільшенні тексту не допускаємо втрати вмісту. */
@media (max-width: 900px) {
    html[style*="--font-scale: 1.3"],
    html[style*="--font-scale: 1.4"],
    html[style*="--font-scale: 1.5"] { height: auto; min-height: 100%; }
    html[style*="--font-scale: 1.3"] body,
    html[style*="--font-scale: 1.4"] body,
    html[style*="--font-scale: 1.5"] body { overflow: auto; height: auto; min-height: 100%; }
}

.accessibility-panel { max-height: min(70vh, 28rem); overflow: auto; }
body.large-text { overflow: auto; }
body.large-text .app-shell { height: auto; min-height: 100dvh; }
body.large-text .screen-main { overflow: visible; }
body.large-text .home-screen,
body.large-text .screen-card,
body.large-text .article-card,
body.large-text .form-card { height: auto; min-height: calc(100dvh - 6rem); }
body.large-text .home-grid { min-height: 28rem; }
body.large-text .news-list,
body.large-text .document-list { min-height: 28rem; }

