/* typeset_mccme — design system */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=PT+Serif:ital,wght@0,400;0,700;1,400;1,700&family=PT+Sans:wght@400;700&display=swap');

:root {
    --font: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bg: #f7f8fa;
    --surface: #fff;
    --border: #e5e7eb;
    --border-light: #f0f1f3;
    --text: rgba(0, 0, 0, 0.85);
    --text-secondary: rgba(0, 0, 0, 0.5);
    --text-tertiary: rgba(0, 0, 0, 0.3);
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    --primary-bg: #e8f0fe;
    --danger: #d93025;
    --danger-bg: #fce8e6;
    --success: #188038;
    --success-bg: #e6f4ea;
    --warning: #e37400;
    --warning-bg: #fef7e0;
    --info: #1a73e8;
    --info-bg: #e8f0fe;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --transition: 0.15s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Header ── */

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    align-items: center;
    gap: 20px;
    height: 48px;
}

header .logo {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

header .logo:hover { text-decoration: none; color: var(--primary); }

header .logo i { color: var(--primary); font-size: 16px; }

header .breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 0;
}

header .breadcrumb a {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

header .breadcrumb a:hover { color: var(--primary); text-decoration: none; }

header .breadcrumb .sep {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

header .container .spacer { flex: 1; }

.main { padding: 16px 0 40px; }

/* ── Login overlay ── */

.login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 320px;
    box-shadow: var(--shadow);
}

.login-logo {
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 24px;
    color: var(--text);
}

.login-logo i {
    color: var(--primary);
    margin-right: 6px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    padding: 8px 12px;
    font-size: 13px;
}

.login-submit {
    width: 100%;
    justify-content: center;
    padding: 8px 12px;
}

.login-error {
    color: var(--danger);
    font-size: 12px;
    text-align: center;
    margin: 0;
}

#logout-btn {
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

/* ── Cards ── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.card-header h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

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

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--transition);
    line-height: 1.5;
}

.btn:hover {
    border-color: #c5c9d0;
    background: #f8f9fa;
    text-decoration: none;
}

.btn:active { transform: translateY(1px); }

.btn i { font-size: 11px; }

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

.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover { background: rgba(0,0,0,0.04); color: var(--text); }

.btn-danger {
    border-color: transparent;
    background: transparent;
    color: var(--text-secondary);
}

.btn-danger:hover { background: var(--danger-bg); color: var(--danger); }

.btn-icon {
    padding: 4px 6px;
    border: none;
    background: none;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: all var(--transition);
}

.btn-icon:hover { background: rgba(0,0,0,0.06); color: var(--text); }

.btn-group {
    display: inline-flex;
    gap: 1px;
    background: var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.btn-group .btn {
    border: none;
    border-radius: 0;
}

/* ── Form inputs ── */

input[type="text"],
input[type="search"],
select,
textarea {
    font-family: var(--font);
    font-size: 13px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
    line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-bg);
}

select {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    padding-right: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

/* ── Tables ── */

table.list {
    width: 100%;
    border-collapse: collapse;
}

table.list th,
table.list td {
    text-align: left;
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
}

table.list th {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom-color: var(--border);
    padding-bottom: 6px;
}

table.list tbody tr {
    transition: background var(--transition);
}

table.list tbody tr:hover { background: rgba(0,0,0,0.015); }
table.list tbody tr:last-child td { border-bottom: none; }

table.list a { font-weight: 500; }
table.list a:hover { text-decoration: underline; }

/* ── Status badges ── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.6;
}

.badge-done { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--danger-bg); color: var(--danger); }
.badge-pending { background: #f3f4f6; color: var(--text-secondary); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }

.badge i { font-size: 9px; }

/* ── Upload zone ── */

.upload-zone {
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 12px;
}

.upload-zone:hover {
    border-color: var(--primary);
    background: var(--primary-bg);
    color: var(--primary);
}

.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-bg);
}

.upload-zone input[type="file"] { display: none; }

.upload-zone i { font-size: 20px; display: block; margin-bottom: 6px; }

.upload-zone p { margin-top: 4px; font-size: 11px; color: var(--text-tertiary); }

/* ── Tabs ── */

.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.tab {
    padding: 8px 14px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: none;
    transition: color var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
}

.tab:hover { color: var(--text); }

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab i { font-size: 11px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Toolbar ── */

.toolbar {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar + .toolbar { margin-top: 8px; }

.toolbar .spacer { flex: 1; }

.toolbar h2 {
    font-size: 15px;
    font-weight: 600;
}

.toolbar .sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
}

/* ── Content layout with TOC sidebar ── */

.content-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
}

.content-layout #content-view {
    grid-column: 2;
    margin: 0 auto 12px;
}

/* ── TOC panel ── */

.toc-panel {
    grid-column: 1;
    align-self: start;
    position: sticky;
    top: 12px;
    padding: 8px 16px 8px 0;
    font-size: 11.5px;
    line-height: 1.4;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
}

.toc-panel:empty { display: none; }

.toc-panel::-webkit-scrollbar { width: 3px; }
.toc-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.toc-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-tertiary);
    padding: 0 4px 6px;
    margin-bottom: 6px;
}

.toc-tree, .toc-children {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-children { padding-left: 12px; }

.toc-entry {
    display: flex;
    align-items: flex-start;
}

.toc-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 8px;
    color: var(--text-tertiary);
    padding: 3px 4px;
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    transition: transform var(--transition), color var(--transition);
}

.toc-toggle:hover { color: var(--text); }

.toc-spacer { width: 16px; flex-shrink: 0; }

.toc-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 2px 4px;
    border-radius: 3px;
    display: block;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all var(--transition);
}

.toc-link:hover {
    color: var(--text);
    background: rgba(0,0,0,0.04);
    text-decoration: none;
}

.toc-link.active {
    color: var(--primary);
    background: var(--primary-bg);
    font-weight: 500;
}

.toc-chapter > .toc-entry > .toc-link {
    font-weight: 600;
    color: var(--text);
}

.toc-section > .toc-entry > .toc-link {
    font-weight: 500;
}

.toc-item.collapsed > .toc-children { display: none; }
.toc-item.collapsed > .toc-entry > .toc-toggle { transform: rotate(-90deg); }

/* ── Page-like card for document content ── */

#content-view {
    max-width: 680px;
    margin: 0 auto 12px;
    padding: 48px 64px;
    border-radius: 2px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08), 0 2px 12px rgba(0,0,0,0.04);
}

/* ── Document content rendering (textbook style) ── */

.document {
    font-family: 'PT Serif', 'Georgia', 'Times New Roman', serif;
    font-size: 15px;
    line-height: 1.55;
    color: #1a1a1a;
}

/* ── Headings ── */

.document .chapter {
    font-family: 'PT Sans', 'Arial', sans-serif;
    font-size: 28px;
    font-weight: 700;
    color: #00a0e3;
    margin: 36px 0 8px;
    padding: 0;
    border: none;
    line-height: 1.2;
}

.document .section {
    font-family: 'PT Serif', serif;
    font-size: 19px;
    font-weight: 700;
    font-style: normal;
    color: #00a0e3;
    margin: 32px 0 12px;
    border: none;
    line-height: 1.3;
}

.document .subsection {
    font-family: 'PT Sans', sans-serif;
    font-size: 16px;
    font-weight: 700;
    font-style: normal;
    color: #1a1a1a;
    margin: 24px 0 10px;
}

/* ── Theorem blocks (bordered boxes) ── */

.document .theorem {
    border: 2.5px solid #00a0e3;
    padding: 14px 18px;
    margin: 18px 0;
    border-radius: 0;
    background: #fff;
    font-size: 15px;
    line-height: 1.55;
    text-indent: 0;
}

.document .theorem-label {
    font-family: 'PT Sans', sans-serif;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.3px;
}

/* Определение — cyan border */
.document .theorem-definition {
    border-color: #00a0e3;
}

/* Замечание — cyan border */
.document .theorem-remark {
    border-color: #00a0e3;
}

/* Утверждение/Теорема — cyan border */
.document .theorem-statement,
.document .theorem-theorem-proper {
    border-color: #00a0e3;
}

/* Заметка (tcolorbox info blocks) — dark border, rounded corners */
.document .theorem-note {
    border-color: #999;
    border-width: 1.5px;
    border-radius: 10px;
}

/* Generic (unknown type) */
.document .theorem-generic {
    border-color: #888;
}

/* Defined terms in definitions — italic per textbook convention */
.document .theorem-definition b {
    font-style: italic;
}

/* ── Proof ── */

.document .proof {
    margin: 10px 0;
    padding: 0 0 0 20px;
    border: none;
    font-style: italic;
    font-size: 15px;
    color: #1a1a1a;
}

.document .proof-label {
    font-style: italic;
    font-weight: 700;
}

/* ── Problems (ПРИМЕР N.) ── */

.document .problem {
    margin: 20px 0 4px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
    font-size: 15px;
    text-indent: 24px;
}

.document .problem-label {
    font-family: 'PT Sans', sans-serif;
    font-weight: 700;
    font-size: 15px;
    display: inline;
    margin: 0;
    text-transform: none;
    letter-spacing: 0.2px;
    color: #1a1a1a;
}

/* ── Exercises (numbered problems) ── */

.document .exercise-num {
    font-family: 'PT Sans', sans-serif;
    font-weight: 700;
    font-size: 15px;
}

.document .exercise-num::before {
    content: '';
    display: block;
    margin-top: 10px;
}

.document .problem-content {
    display: inline;
}

/* ── Solution (РЕШЕНИЕ.) ── */

.document .solution {
    margin: 4px 0 4px;
    padding: 0;
    border: none;
    font-size: 15px;
}

.document .solution-label {
    font-family: 'PT Sans', sans-serif;
    font-weight: 700;
    font-size: 14px;
    color: #00a0e3;
}

/* ── Answer (Ответ:) ── */

.document .answer {
    margin: 6px 0 16px;
    padding: 0;
    background: none;
    border-radius: 0;
    font-size: 15px;
    font-weight: 400;
}

.document .answer-label {
    font-style: italic;
    color: #00a0e3;
    font-weight: 400;
}

/* ── Pictures ── */

.document .picture-placeholder {
    margin: 12px 0;
    padding: 20px;
    background: #fafbfc;
    border: 1px dashed #ccc;
    text-align: center;
    color: #999;
    border-radius: 2px;
    font-size: 13px;
    font-family: var(--font);
}

/* ── References ── */

.document .ref {
    color: #00a0e3;
    font-size: inherit;
}

/* ── Captions ── */

.document .caption {
    text-align: center;
    font-size: 14px;
    color: #555;
    margin: 4px 0 14px;
}

/* ── Tables ── */

.document .data-table {
    border-collapse: collapse;
    margin: 14px auto;
    font-size: 15px;
}

.document .data-table th,
.document .data-table td {
    border: 1px solid #ccc;
    padding: 6px 14px;
    text-align: center;
}

.document .data-table th {
    background: #f5f5f5;
    font-weight: 700;
    font-size: 14px;
}

/* ── Lists ── */

.document .itemize,
.document .enumerate {
    margin: 8px 0;
    padding-left: 28px;
    font-size: 16px;
}

.document .itemize li::marker {
    color: #1a1a1a;
}

.document .center {
    text-align: center;
    margin: 8px 0;
}

/* ── Math — clickable for editing ── */

.document .math-inline,
.document .math-block {
    cursor: pointer;
    transition: background var(--transition);
}

.document .math-inline:hover {
    background: #e3f4fd;
    border-radius: 2px;
}

.document .math-block:hover {
    background: #e3f4fd;
}

.document .math-block {
    margin: 14px 0;
    padding: 8px 0;
    text-align: center;
    text-indent: 0;
}

/* ── Stats ── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.stats-group {
    padding: 12px;
}

.stats-group h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 6px;
    letter-spacing: 0.4px;
    font-weight: 600;
}

.stats-group table {
    width: 100%;
    border-collapse: collapse;
}

.stats-group td {
    padding: 3px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
}

.stats-group tr:last-child td { border-bottom: none; }

.stats-group td:last-child {
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* ── Validation issues ── */

.validation-summary {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.issue {
    padding: 6px 10px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.issue-error { background: var(--danger-bg); }
.issue-warning { background: var(--warning-bg); }
.issue-info { background: var(--info-bg); }

.issue-level {
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    min-width: 55px;
    flex-shrink: 0;
}

.issue-path {
    color: var(--text-tertiary);
    font-size: 11px;
    font-family: monospace;
    margin-left: auto;
    flex-shrink: 0;
}

/* ── Modal (formula editor) ── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 480px;
    max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.modal h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal .modal-actions {
    margin-top: 12px;
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* ── Empty state ── */

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--text-tertiary);
    font-size: 12px;
}

.empty-state i {
    font-size: 24px;
    display: block;
    margin-bottom: 8px;
}

/* ── Inline form ── */

.inline-form {
    display: flex;
    gap: 6px;
    align-items: center;
}

.inline-form input { flex: 1; }

/* ── Utility ── */

.text-muted { color: var(--text-secondary); }
.text-xs { font-size: 11px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }
.gap-6 { gap: 6px; }

/* ── Document page: fixed header, independent content scrolling ── */

body.document-page {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.document-page .main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: 0;
    width: 100%;
}

body.document-page .main > .card,
body.document-page .main > .tabs {
    flex-shrink: 0;
}

body.document-page .tab-panel.active {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* ── Page indicator ── */

.page-indicator {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    padding: 0 2px;
}

.page-indicator input[type="number"] {
    width: 40px;
    text-align: center;
    padding: 2px 4px;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-variant-numeric: tabular-nums;
    color: var(--text);
    background: var(--surface);
    line-height: 1.4;
    -moz-appearance: textfield;
}

.page-indicator input[type="number"]::-webkit-inner-spin-button,
.page-indicator input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.page-indicator input[type="number"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-bg);
    outline: none;
}

.page-indicator .page-sep {
    color: var(--text-tertiary);
}
