:root {
    --bg: #f5f8fd;
    --panel: #ffffff;
    --ink: #06133f;
    --muted: #64718f;
    --line: #dce5f2;
    --blue: #155bdc;
    --blue-soft: #eaf2ff;
    --green: #21a657;
    --purple: #7a55d9;
    --shadow: 0 12px 32px rgba(15, 34, 74, .10);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }

.loading-shell,
.boot-loader {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--blue);
    background:
        radial-gradient(circle at 50% 42%, rgba(21, 91, 220, .10), transparent 34%),
        var(--bg);
}

.loading-card,
.boot-loader-card {
    width: min(340px, 100%);
    display: grid;
    gap: 14px;
}

.loading-title {
    color: var(--blue);
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: .01em;
    text-align: center;
}

.loading-progress {
    width: 100%;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #dce8fb;
    box-shadow: inset 0 0 0 1px rgba(21, 91, 220, .08);
}

.loading-progress-bar {
    width: var(--blazor-load-percentage, 8%);
    min-width: 8%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #21a657, #155bdc);
    transition: width .18s ease;
}

.loading-progress-bar.is-indeterminate {
    width: 42%;
    min-width: 42%;
    animation: loading-progress-slide 1.1s ease-in-out infinite;
}

.loading-progress-text {
    min-height: 1rem;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
    text-align: center;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Загрузка...");
}

@keyframes loading-progress-slide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(240%); }
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    position: sticky;
    top: 0;
    width: 220px;
    min-width: 220px;
    height: 100vh;
    padding: 24px 18px;
    background: rgba(255, 255, 255, .94);
    border-right: 1px solid var(--line);
    overflow-y: auto;
}

.sidebar-brand, .brand-inline, .admin-login-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-mark {
    width: 38px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: white;
    background: linear-gradient(145deg, #155bdc, #3a91ff);
    font-weight: 900;
}

.logo-copy strong {
    display: block;
    color: var(--blue);
    font-size: 1.2rem;
    line-height: 1;
}

.logo-copy small {
    display: block;
    max-width: 170px;
    margin-top: 4px;
    color: var(--ink);
    font-size: .67rem;
    line-height: 1.25;
}

.sidebar-nav {
    margin-top: 26px;
    display: grid;
    gap: 18px;
}

.sidebar-nav a, .nav-home {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 8px 10px;
    border-radius: 8px;
    color: #12204b;
    font-weight: 600;
    font-size: .9rem;
}

.sidebar-nav a.active {
    color: var(--blue);
    background: var(--blue-soft);
}

.grade-group {
    display: grid;
    gap: 2px;
}

.grade-group-header {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 8px;
    margin: 0 0 4px;
    padding: 2px 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #12204b;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.grade-group-link {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    min-height: 28px;
    font-weight: 800;
}

.grade-group-header:focus-visible {
    outline: 2px solid rgba(30, 99, 230, .35);
    outline-offset: 3px;
}

.grade-links {
    display: grid;
    gap: 2px;
}

.grade-links[hidden] {
    display: none;
}

.group-icon { color: var(--green); font-size: .8rem; }
.side-muted { color: var(--muted); font-size: .85rem; }

.app-main {
    flex: 1;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 76px;
    padding: 16px 40px;
    background: rgba(245, 248, 253, .86);
    backdrop-filter: blur(12px);
}

.brand-inline { display: none; }

.search-box {
    position: relative;
    width: min(520px, 100%);
}

.search-box input {
    width: 100%;
    height: 44px;
    padding: 0 42px 0 48px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: white;
    color: var(--ink);
    outline: none;
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 10px;
    color: var(--blue);
    font-size: 1.2rem;
}

.search-results {
    position: absolute;
    top: 64px;
    width: min(520px, calc(100% - 80px));
    display: grid;
    gap: 4px;
    padding: 8px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.search-results button {
    border: 0;
    padding: 10px 12px;
    text-align: left;
    color: var(--ink);
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
}

.search-results button:hover { background: var(--blue-soft); }

.content-shell {
    width: min(1180px, 100%);
    padding: 10px 40px 56px;
}

.admin-login-shell {
    width: 100%;
    min-height: 100vh;
    padding: 0;
}

.hero-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 28px;
    min-height: 300px;
    padding: 48px 56px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(135deg, #f4f9ff, #eaf4ff);
    box-shadow: var(--shadow);
}

.hero-panel h1 {
    max-width: 560px;
    margin: 0 0 18px;
    font-size: 2.35rem;
    line-height: 1.05;
}

.hero-panel p, .page-heading p, .admin-toolbar p {
    color: var(--muted);
    line-height: 1.6;
}

.hero-art {
    position: relative;
    min-height: 210px;
}

.book-stack span {
    position: absolute;
    right: 20px;
    width: 190px;
    height: 52px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.book-stack span:nth-child(1) { top: 28px; background: #3a91ff; transform: rotate(8deg); }
.book-stack span:nth-child(2) { top: 74px; background: #ffd45a; transform: rotate(-3deg); }
.book-stack span:nth-child(3) { top: 116px; background: #29b66f; transform: rotate(5deg); }

.math-card {
    position: absolute;
    left: 18px;
    bottom: 24px;
    padding: 24px 28px;
    border-radius: 8px;
    color: #1b3776;
    background: white;
    font-size: 1.6rem;
    font-weight: 800;
    box-shadow: var(--shadow);
    transform: rotate(10deg);
}

.stage-grid, .grade-card-grid, .subject-grid, .section-grid, .popular-grid, .admin-nav-grid {
    display: grid;
    gap: 22px;
}

.stage-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: -48px 56px 42px;
    position: relative;
    z-index: 1;
}

.stage-card, .grade-card, .popular-card, .subject-card, .section-card, .admin-nav-grid a, .admin-panel, .preview-card, .generator-form, .material-card, .page-section {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    box-shadow: var(--shadow);
}

.stage-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 16px;
    padding: 22px;
    align-items: center;
}

.stage-badge {
    grid-row: span 2;
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 8px;
    color: white;
    background: linear-gradient(145deg, var(--green), #5bd785);
    font-weight: 900;
}

.stage-card:nth-child(2) .stage-badge { background: linear-gradient(145deg, var(--blue), #58a1ff); }
.stage-card:nth-child(3) .stage-badge { background: linear-gradient(145deg, var(--purple), #9f7bff); }

.grade-card-grid {
    grid-template-columns: repeat(4, minmax(190px, 1fr));
}

.grade-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 16px;
    padding: 22px;
    align-items: center;
}

.grade-card-badge {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    color: white;
    background: linear-gradient(145deg, var(--blue), #58a1ff);
    font-weight: 900;
}

.grade-card h2 {
    margin: 0 0 6px;
    font-size: 1.1rem;
}

.grade-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.page-section, .page-heading {
    margin-top: 26px;
}

.page-section {
    padding: 28px;
}

.page-section.compact {
    max-width: 640px;
}

.page-heading h1, .admin-page h1 {
    margin: 0 0 8px;
    font-size: 2rem;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--blue);
    font-size: .85rem;
    margin: 0 0 22px;
}

.crumb-separator { color: var(--muted); }

.popular-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.popular-card {
    min-height: 150px;
    padding: 24px 18px;
    display: grid;
    gap: 8px;
    place-items: center;
    text-align: center;
}

.popular-card span, .section-card span, .subject-icon, .empty-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    color: var(--blue);
    background: var(--blue-soft);
    font-size: 1.4rem;
}

.subject-grid {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
}

.subject-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 22px;
    padding: 34px;
    align-items: start;
}

.subject-card h2, .section-card h2, .material-card h2, .preview-card h2, .generator-form h2, .admin-panel h2 {
    margin: 0 0 8px;
    font-size: 1.2rem;
}

.section-grid {
    grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.section-card {
    min-height: 210px;
    display: grid;
    gap: 12px;
    place-items: center;
    text-align: center;
    padding: 24px 18px;
}

.section-card.disabled {
    opacity: .55;
    pointer-events: none;
}

.material-list {
    display: grid;
    gap: 18px;
}

.material-card {
    display: grid;
    grid-template-columns: 82px 1fr auto;
    gap: 22px;
    align-items: center;
    padding: 18px 22px;
}

.material-cover {
    width: 72px;
    height: 96px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: white;
    background: linear-gradient(145deg, var(--purple), #59a7ff);
    font-weight: 900;
}

.material-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.material-card dl {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin: 12px 0 0;
}

.material-card dt {
    color: var(--muted);
    font-size: .75rem;
}

.material-card dd {
    margin: 0;
    font-weight: 700;
}

.generator-layout {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 28px;
}

.generator-form, .preview-card {
    padding: 28px;
}

.generator-form label {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 12px;
    align-items: center;
    margin: 14px 0;
}

.generator-form input, .generator-form select, .admin-form input, .admin-form textarea, .admin-form select, .admin-login-card input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--ink);
    background: white;
}

.generator-form .check-row {
    grid-template-columns: auto 1fr;
}

.check-row input {
    width: 20px;
    height: 20px;
}

.generator-choice-group {
    display: grid;
    gap: 8px;
    margin: 14px 0;
    padding: 0;
    border: 0;
}

.generator-choice-group legend {
    padding: 0;
    font-weight: 700;
}

.generator-choice-group .check-row {
    margin: 0;
}

.actions-row {
    display: flex;
    gap: 14px;
    margin-top: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 22px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 800;
    cursor: pointer;
}

.btn-primary { color: white; background: var(--blue); }
.btn-success { color: white; background: var(--green); }
.btn-outline { color: var(--blue); border-color: var(--line); background: white; }
.btn:disabled { opacity: .6; cursor: wait; }

.exercise-list {
    display: grid;
    gap: 14px;
    padding-left: 26px;
}

.exercise-list li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 20px;
}

.clock-preview-pages {
    display: grid;
    justify-items: center;
    gap: 22px;
}

.clock-preview-pages.is-scrollable {
    max-height: min(72vh, 900px);
    overflow-y: auto;
    padding-right: 8px;
    overscroll-behavior: contain;
}

.clock-preview-page {
    width: 100%;
    max-width: 680px;
    aspect-ratio: 595 / 842;
    padding: clamp(14px, 4%, 32px);
    border: 1px solid var(--line);
    background: white;
}

.clock-preview-page-grid {
    height: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(5, minmax(0, 1fr));
    gap: clamp(6px, 1.5vw, 14px);
}

.clock-preview-cell {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) 14px 18px;
    gap: 4px;
    align-items: start;
    justify-items: center;
}

.clock-preview-cell img {
    width: 100%;
    height: 100%;
    min-height: 0;
    aspect-ratio: 1;
    object-fit: contain;
}

.clock-answer-line {
    display: block;
    justify-self: center;
    width: min(96px, 70%);
    height: 12px;
    border-bottom: 1.5px solid currentColor;
}

.link-button {
    border: 0;
    color: var(--blue);
    background: transparent;
    font-weight: 800;
    cursor: pointer;
}

.state-panel, .empty-state {
    display: grid;
    place-items: center;
    text-align: center;
    gap: 12px;
    min-height: 180px;
    color: var(--muted);
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--line);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.alert {
    padding: 12px 14px;
    margin: 12px 0;
    border-radius: 8px;
    font-weight: 700;
}

.alert-danger { color: #8b1d1d; background: #fff0f0; border: 1px solid #ffd4d4; }
.alert-success { color: #116333; background: #eaf8f0; border: 1px solid #ccebd9; }
.alert-info { color: #174282; background: var(--blue-soft); border: 1px solid #d4e5ff; }

.admin-login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 24px;
    background: linear-gradient(180deg, #f9fbff, #edf4ff);
}

.admin-login-card {
    width: min(380px, calc(100vw - 32px));
    display: grid;
    gap: 14px;
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    box-shadow: var(--shadow);
}

.admin-login-card h1 {
    margin: 0 0 8px;
    text-align: center;
    font-size: 1.4rem;
}

.copyright { color: var(--muted); font-size: .85rem; }

.admin-page {
    display: grid;
    gap: 22px;
}

.admin-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.admin-nav-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.admin-nav-grid a {
    padding: 28px;
    color: var(--blue);
    font-weight: 900;
}

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

.admin-panel {
    padding: 22px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.admin-table th, .admin-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.admin-form {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.grid-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-form textarea {
    grid-column: 1 / -1;
    min-height: 90px;
}

.admin-file-field {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 800;
}

.file-picker {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 42px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    cursor: pointer;
}

.file-picker-button {
    flex: 0 0 auto;
    pointer-events: none;
}

.file-picker-name {
    min-width: 0;
    overflow: hidden;
    color: var(--ink);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-picker-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    opacity: 0;
}

.book-cover-preview,
.admin-book-cover {
    width: 72px;
    height: 96px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 8px;
    color: white;
    background: linear-gradient(145deg, #155bdc, #21a657);
    font-size: .72rem;
    font-weight: 900;
    text-align: center;
}

.book-cover-preview img,
.admin-book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: 12px 16px;
    color: white;
    background: #9c1c1c;
}

#blazor-error-ui .reload { color: white; text-decoration: underline; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

@media (max-width: 900px) {
    .app-shell { display: block; }
    .sidebar {
        position: static;
        width: 100%;
        min-width: 0;
        height: auto;
        padding: 16px;
    }
    .sidebar-brand { display: none; }
    .sidebar-nav { margin-top: 0; grid-template-columns: repeat(3, 1fr); align-items: start; }
    .topbar { justify-content: stretch; padding: 14px 18px; }
    .brand-inline { display: flex; }
    .content-shell { padding: 12px 18px 38px; }
    .hero-panel, .generator-layout, .admin-two-column { grid-template-columns: 1fr; }
    .hero-panel { padding: 32px 24px; }
    .stage-grid { grid-template-columns: 1fr; margin: 18px 0 34px; }
    .popular-grid, .grade-card-grid, .section-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .subject-grid, .admin-nav-grid { grid-template-columns: 1fr; }
    .material-card { grid-template-columns: 72px 1fr; }
    .material-card .btn { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
    .sidebar-nav { grid-template-columns: 1fr; }
    .topbar { display: grid; gap: 14px; }
    .popular-grid, .grade-card-grid, .section-grid, .grid-form { grid-template-columns: 1fr; }
    .hero-panel h1 { font-size: 1.9rem; }
    .hero-art { display: none; }
}
