/* ===== Базовые стили сайта (из страницы файлообменника) ===== */
:root {
    --bg: #ffffff; --text: #111111; --text-secondary: #666666;
    --footer-bg: #000000; --footer-text: #b3b3b3;
    --line: #e5e7eb; --workspace: #f3f4f6;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --transition-fast: 0.25s var(--ease);
    --header-h: 65px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 170px; scroll-padding-bottom: 70px; }
body {
    font-family: 'Montserrat', sans-serif; background: var(--bg); color: var(--text);
    line-height: 1.6; -webkit-font-smoothing: antialiased;
    padding-top: var(--header-h); display: flex; flex-direction: column;
    min-height: 100vh; overflow-x: hidden;
}
.header { position: fixed; top: 0; left: 0; width: 100%; padding: 1rem 1.5rem; display: flex; justify-content: space-between; align-items: center; background: #ffffff; border-bottom: 1px solid #f0f0f0; z-index: 1000; height: 65px; }
.logo { display: inline-flex; align-items: center; justify-content: center; padding: 0.3rem 0.6rem; border: 1.5px solid var(--text); border-radius: 6px; font-weight: 700; font-size: 0.7rem; letter-spacing: 2px; text-transform: uppercase; text-decoration: none; color: var(--text); transition: transform var(--transition-fast), background var(--transition-fast); }
.logo:hover { transform: scale(1.02); background: var(--text); color: #ffffff; }
.burger { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; padding: 6px; z-index: 1001; }
.burger span { display: block; width: 20px; height: 2px; background: var(--text); border-radius: 2px; transition: transform 0.4s var(--ease), opacity 0.25s var(--ease); transform-origin: center; }
.burger.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.burger.active span:nth-child(2) { opacity: 0; }
.burger.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.nav-menu { position: fixed; top: 0; right: -100%; width: min(260px, 85vw); height: 100vh; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(12px); border-left: 1px solid #e5e5e5; padding: 4.5rem 1.8rem 1.5rem; transition: right 0.4s var(--ease); box-shadow: -8px 0 20px rgba(0,0,0,0.04); z-index: 999; }
.nav-menu.active { right: 0; }
.nav-menu ul { list-style: none; }
.nav-menu li { margin-bottom: 1.2rem; }
.nav-menu a { text-decoration: none; color: var(--text); font-weight: 500; font-size: 1rem; display: inline-block; position: relative; }
.nav-menu a::after { content: ''; position: absolute; bottom: -3px; left: 0; width: 0; height: 1.5px; background: var(--text); transition: width 0.4s var(--ease); }
.nav-menu a:hover::after { width: 100%; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.2); opacity: 0; visibility: hidden; transition: opacity 0.4s var(--ease), visibility 0.4s var(--ease); z-index: 998; }
.overlay.active { opacity: 1; visibility: visible; }

.nav-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.8rem 1.2rem; border: 1.5px solid var(--text); border-radius: 8px; background: var(--text); color: #fff; font-family: inherit; font-weight: 600; font-size: 0.9rem; cursor: pointer; transition: all var(--transition-fast); white-space: nowrap; text-decoration: none; }
.nav-btn:hover { background: #333; transform: translateY(-1px); }
.nav-btn.ghost { background: #fff; color: var(--text); }
.nav-btn.ghost:hover { background: #f3f4f6; }

.footer { background: var(--footer-bg); color: var(--footer-text); padding: 1.8rem 1.5rem 1.3rem; margin-top: auto; }
.footer-content { max-width: 700px; margin: 0 auto; text-align: center; }
.footer-info p { margin: 0.3rem 0; font-size: 0.9rem; }
.footer-info a { color: #ffffff; text-decoration: none; }
.footer-info a:hover { opacity: 0.8; }
.divider { width: 30px; height: 1px; background: #222; margin: 0 auto 0.8rem; }
.copyright { font-size: 0.7rem; color: #555; }

/* ===== Каркас редактора ===== */
main { flex: 1; width: 100%; display: flex; flex-direction: column; }
.app { flex: 1; display: flex; flex-direction: column; min-height: calc(100vh - var(--header-h)); }

.topbar { position: sticky; top: var(--header-h); z-index: 50; background: #fff; border-bottom: 1px solid var(--line); }

/* Строка документа */
.docbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; padding: 0.6rem 1rem 0.4rem; }
.doc-title { flex: 1 1 200px; min-width: 0; max-width: 460px; font: inherit; font-size: 1.05rem; font-weight: 600; letter-spacing: -0.2px; color: var(--text); border: 1.5px solid transparent; border-radius: 8px; padding: 0.3rem 0.6rem; background: transparent; outline: none; transition: border-color var(--transition-fast), background var(--transition-fast); }
.doc-title:hover { border-color: var(--line); }
.doc-title:focus { border-color: var(--text); background: #fff; }
.save-state { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; }
.save-state.error { color: #dc2626; }
.docbar-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-left: auto; }

.btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0.8rem; border: 1.5px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); font-family: inherit; font-weight: 500; font-size: 0.8rem; cursor: pointer; transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast); white-space: nowrap; }
.btn:hover { border-color: var(--text); background: #f9fafb; }
.btn-primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn-primary:hover { background: #333; border-color: #333; }

.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,0.12); padding: 0.3rem; z-index: 60; }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button { display: block; width: 100%; text-align: left; padding: 0.55rem 0.8rem; border: none; background: none; border-radius: 6px; font: inherit; font-size: 0.85rem; font-weight: 500; color: var(--text); cursor: pointer; }
.dropdown-menu button:hover { background: #f3f4f6; }

/* Панель форматирования */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0; padding: 0.35rem 0.6rem 0.5rem; }
.tb-group { display: flex; align-items: center; gap: 2px; padding: 0 0.45rem; border-right: 1px solid var(--line); }
.tb-group:last-child { border-right: none; }
.tb { position: relative; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: none; background: none; border-radius: 6px; color: var(--text); cursor: pointer; font-family: inherit; font-size: 0.85rem; font-weight: 600; transition: background 0.15s; }
.tb:hover { background: #f3f4f6; }
.tb.active { background: var(--text); color: #fff; }
.tb svg { display: block; }
.tb sub, .tb sup { font-size: 0.6em; font-weight: 600; }
.tb-sm { width: 26px; height: 26px; font-size: 1rem; }
.tb-select { height: 32px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-family: inherit; font-size: 0.8rem; padding: 0 0.4rem; color: var(--text); cursor: pointer; outline: none; }
.tb-select:hover, .tb-select:focus { border-color: var(--text); }
.tb-select-block { width: 132px; }
.tb-select-font { width: 138px; }
.tb-select-size { width: 58px; }
.tb-select-line { width: 82px; }

.color-group { display: inline-flex; align-items: center; }
.tb-color { flex-direction: column; justify-content: center; gap: 2px; width: 28px; }
.ci-A { font-size: 0.95rem; font-weight: 700; line-height: 1; }
.ci-hl { display: inline-flex; line-height: 0; }
.ci-bar { display: block; width: 16px; height: 3px; border-radius: 2px; background: #dc2626; }
.tb-mini { width: 16px; font-size: 0.7rem; color: var(--text-secondary); cursor: pointer; margin-left: -4px; }
.tb-mini input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: none; }

/* Поиск и замена */
.findbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; padding: 0.5rem 1rem; background: #fafafa; border-top: 1px solid var(--line); }
.findbar input[type="text"] { width: 170px; padding: 0.4rem 0.7rem; border: 1.5px solid #d1d5db; border-radius: 8px; font: inherit; font-size: 0.82rem; background: #fff; outline: none; transition: border-color var(--transition-fast); }
.findbar input[type="text"]:focus { border-color: var(--text); }
.chk { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; font-weight: 600; cursor: pointer; user-select: none; }
.find-count { font-size: 0.78rem; color: var(--text-secondary); min-width: 72px; }

/* Инструменты таблицы — плавают под панелью, чтобы не сдвигать страницу */
.table-tools { position: absolute; left: 0; right: 0; top: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; padding: 0.4rem 1rem; background: #fafafa; border-bottom: 1px solid var(--line); box-shadow: 0 6px 14px rgba(0,0,0,0.05); }
.tt-label { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); margin-right: 0.3rem; }

/* Рабочая область и лист */
.workspace { flex: 1; background: var(--workspace); padding: 1.5rem 1rem 3rem; overflow-x: auto; }
.sheet { width: 210mm; max-width: 100%; margin: 0 auto; }
.page {
    width: 100%; min-height: 297mm; padding: 20mm; background: #fff; color: #111;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 10px 30px rgba(0,0,0,0.06);
    outline: none; font-family: Arial, Helvetica, sans-serif; font-size: 12pt; line-height: 1.4;
    overflow-wrap: anywhere; caret-color: #111;
    /* тонкие линии — примерные границы страниц A4 при печати (поля 2 см) */
    background-image: linear-gradient(to bottom, transparent calc(100% - 1px), #d9dce1 0);
    background-size: 100% 257mm; background-repeat: repeat-y;
    background-origin: content-box; background-clip: content-box;
}
.page.is-empty > p:first-child::before { content: 'Начните печатать…'; color: #9ca3af; pointer-events: none; }
.page p { margin: 0 0 0.6em; }
.page h1 { font-size: 22pt; line-height: 1.2; margin: 0.8em 0 0.4em; }
.page h2 { font-size: 17pt; line-height: 1.25; margin: 0.8em 0 0.4em; }
.page h3 { font-size: 14pt; line-height: 1.3; margin: 0.8em 0 0.4em; }
.page ul, .page ol { margin: 0 0 0.6em 1.6em; }
.page li { margin-bottom: 0.2em; }
.page blockquote { margin: 0.6em 0; padding: 0.2em 1em; border-left: 3px solid #d1d5db; color: #444; }
.page pre { font-family: 'Courier New', monospace; font-size: 11pt; background: #f3f4f6; padding: 0.6em 0.8em; border-radius: 4px; white-space: pre-wrap; margin: 0.6em 0; }
.page table { border-collapse: collapse; width: 100%; margin: 0.6em 0; table-layout: fixed; }
.page td, .page th { border: 1px solid #9ca3af; padding: 6px 8px; vertical-align: top; min-width: 24px; overflow-wrap: anywhere; }
.page img { max-width: 100%; height: auto; cursor: pointer; }
.page a { color: #1d4ed8; }
.page hr { border: 0; border-top: 1px solid #9ca3af; margin: 1em 0; }
.page hr.page-break { border-top: 1px dashed #6b7280; margin: 1.6em 0; }
.page ::selection { background: #bfdbfe; }

::highlight(find-all) { background-color: #fde68a; color: #111; }
::highlight(find-current) { background-color: #f59e0b; color: #111; }

/* Статус-строка */
.statusbar { position: sticky; bottom: 0; z-index: 40; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.4rem 1rem; padding: 0.3rem 1rem; background: #fff; border-top: 1px solid var(--line); font-size: 0.75rem; color: var(--text-secondary); }
.zoom { display: flex; align-items: center; gap: 0.3rem; }
.zoom input[type="range"] { width: 120px; accent-color: #111; }
.zoom-val { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* Уведомление */
.toast { position: fixed; left: 50%; bottom: 60px; transform: translate(-50%, 12px); max-width: min(92vw, 480px); padding: 0.7rem 1.1rem; background: var(--text); color: #fff; border-radius: 10px; font-size: 0.85rem; box-shadow: 0 10px 30px rgba(0,0,0,0.25); opacity: 0; pointer-events: none; transition: opacity 0.3s var(--ease), transform 0.3s var(--ease); z-index: 2000; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Диалоги */
dialog.dlg { border: none; border-radius: 14px; padding: 0; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,0.22); color: var(--text); font-family: 'Montserrat', sans-serif; }
dialog.dlg::backdrop { background: rgba(0,0,0,0.25); backdrop-filter: blur(2px); }
.dlg form { padding: 1.5rem; }
.dlg h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; letter-spacing: -0.2px; }
.dlg-text { font-size: 0.88rem; color: var(--text-secondary); line-height: 1.6; margin-bottom: 0.6rem; }
.dlg label { display: block; font-size: 0.8rem; font-weight: 500; margin-bottom: 0.9rem; }
.dlg label > span { display: block; margin-bottom: 0.3rem; color: var(--text-secondary); }
.dlg input, .dlg select { width: 100%; padding: 0.7rem 0.9rem; border: 1.5px solid #d1d5db; border-radius: 8px; font-family: inherit; font-size: 0.9rem; background: #fff; color: var(--text); outline: none; transition: border-color var(--transition-fast); }
.dlg input:focus, .dlg select:focus { border-color: var(--text); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.2rem; }
.kbd { display: grid; grid-template-columns: auto 1fr; gap: 0.45rem 1rem; margin-top: 0.4rem; color: var(--text); font-size: 0.82rem; }
.kbd dt { white-space: nowrap; }
.kbd dd { color: var(--text-secondary); }
kbd { display: inline-block; padding: 0.05rem 0.4rem; border: 1px solid #d1d5db; border-bottom-width: 2px; border-radius: 5px; background: #fafafa; font-family: inherit; font-size: 0.75rem; font-weight: 600; }

/* Фокус с клавиатуры */
.btn:focus-visible, .tb:focus-visible, .tb-select:focus-visible, .dropdown-menu button:focus-visible, .burger:focus-visible, .nav-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* ===== Адаптив ===== */
@media (max-width: 900px) {
    .toolbar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.6rem; }
    .tb-group { flex-shrink: 0; }
    .page { padding: 1.2rem; min-height: 70vh; background-image: none; box-shadow: none; }
    .workspace { padding: 0.6rem 0 2rem; }
    .zoom input[type="range"] { width: 80px; }
}
@media (max-width: 480px) {
    :root { --header-h: 60px; }
    .header { padding: 0.9rem 1rem; height: 60px; }
    .logo { font-size: 0.65rem; padding: 0.25rem 0.5rem; }
    .docbar-actions { margin-left: 0; width: 100%; }
    .save-state { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition-duration: 0.01ms !important; }
}

/* ===== Печать (и сохранение в PDF) ===== */
@media print {
    @page { size: A4; margin: 2cm; }
    html, body { background: #fff !important; }
    body { padding: 0 !important; display: block; min-height: 0; }
    .header, .nav-menu, .overlay, .topbar, .statusbar, .footer, .toast, dialog { display: none !important; }
    main, .app, .workspace, .sheet { display: block; padding: 0 !important; margin: 0 !important; background: none !important; min-height: 0 !important; width: auto !important; overflow: visible !important; zoom: 1 !important; }
    .page { width: auto; min-height: 0; padding: 0; box-shadow: none; background: none; }
    .page.is-empty > p:first-child::before { content: none; }
    .page hr.page-break { visibility: hidden; border: 0; height: 0; margin: 0; break-after: page; page-break-after: always; }
    .page a { color: inherit; text-decoration: underline; }
    .page tr, .page img { break-inside: avoid; }
}
