/* ───── Дизайн систем ───── */
:root {
  --brand-1: #0ea5e9;
  --brand-2: #1e40af;
  --accent: #10b981;
  --warn: #d97706;
  --danger: #dc2626;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg-soft: #f8fafc;
  --bg: #f1f5f9;
  --paper: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --radius: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", "Inter", sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
  height: 100vh; display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ───── Header ───── */
header {
  padding: 10px 20px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
  color: #fff; display: flex; gap: 14px; align-items: center;
  box-shadow: var(--shadow-sm);
}
header h1 { font-size: 0.95rem; margin: 0; font-weight: 500; opacity: 0.85; }
.brand-link { display: flex; align-items: center; }
.header-logo { height: 32px; background: #fff; padding: 5px 10px; border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
#logoutBtn, #adminLink {
  padding: 5px 12px; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18); color: #fff;
  border-radius: 5px; cursor: pointer; font-size: 0.82rem; transition: background 0.15s;
}
#logoutBtn:hover, #adminLink:hover { background: rgba(255,255,255,0.18); }
header select {
  flex: 1; max-width: 600px; padding: 6px 10px; border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.2); background: rgba(255,255,255,0.1); color: #fff;
}
header select option { background: #1e293b; color: #fff; }
#statusSelect { max-width: 130px; }
#status { font-size: 0.78rem; opacity: 0.75; min-width: 80px; }

/* ───── Layout ───── */
main {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  background: var(--bg); padding: 8px; overflow: hidden;
}
section {
  background: var(--paper); overflow: auto; padding: 18px 20px;
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}

/* ───── PDF pane ───── */
#pdfControls { display: flex; gap: 8px; align-items: center; margin-bottom: 10px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); }
#pdfControls button { padding: 4px 12px; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 5px; cursor: pointer; }
#pdfControls button:hover { background: #fff; border-color: var(--brand-1); color: var(--brand-1); }
#pageInfo { font-family: ui-monospace, monospace; font-size: 0.85rem; color: var(--muted); }
#pdfCanvas { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

/* ───── Tabs ───── */
.tabs {
  display: flex; gap: 2px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border); padding-bottom: 0; flex-wrap: wrap;
}
.tab {
  background: none; border: none; padding: 8px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500;
  font-size: 0.85rem; transition: all 0.15s; margin-bottom: -1px; border-radius: 4px 4px 0 0;
}
.tab:hover { color: var(--ink); background: var(--bg-soft); }
.tab.active {
  border-bottom-color: var(--brand-1); color: var(--brand-2);
  font-weight: 600; background: var(--bg-soft);
}
/* ───── Sections / clauses ───── */
.section-block { margin-bottom: 1.5rem; }
.section-title {
  background: linear-gradient(90deg, var(--bg-soft), transparent);
  padding: 8px 12px; margin: 16px 0 8px; font-weight: 600; font-size: 0.95rem;
  border-left: 3px solid var(--brand-1); border-radius: 0 4px 4px 0;
  display: flex; align-items: center; gap: 8px;
}
.sec-title-text { flex: 1; }
.clause { padding: 10px 0; border-bottom: 1px solid var(--bg); display: flex; align-items: flex-start; gap: 8px; }
.clause:hover { background: var(--bg-soft); border-radius: 4px; padding-left: 6px; padding-right: 6px; margin: 0 -6px; }
.btn-col { display: flex; flex-direction: column; gap: 3px; flex-shrink: 0; }
.btn-col button {
  width: 28px; height: 24px; padding: 0; font-size: 0.8rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px; cursor: pointer; transition: all 0.15s;
}
.clause > span[contenteditable="true"] {
  flex: 1; min-height: 1.4em; padding: 4px 6px; border-radius: 4px;
  line-height: 1.6;
}
.clause > span[contenteditable="true"]:focus { background: #fffbeb; outline: 1px dashed var(--brand-1); }
.clause > span[contenteditable="true"]:empty::before { content: "(заалтын текст…)"; color: #cbd5e1; font-style: italic; }
.clause-num { font-weight: 600; color: var(--brand-2); }
.clause-page {
  font-size: 0.7rem; color: var(--muted); cursor: pointer; white-space: nowrap;
  align-self: center; padding: 2px 6px; border-radius: 10px;
  background: var(--bg-soft); transition: all 0.15s;
}
.clause-page:hover { background: var(--brand-1); color: #fff; }
.num-input {
  width: 64px; padding: 4px 6px; border: 1px solid var(--border);
  border-radius: 4px; font-family: ui-monospace, monospace; font-size: 0.8rem;
  background: var(--bg-soft);
}
.num-input:focus { outline: none; border-color: var(--brand-1); background: #fff; }
.add-btn {
  background: #ecfdf5; border: 1px solid var(--accent); color: #065f46;
  padding: 4px 10px; font-size: 0.78rem; cursor: pointer; border-radius: 5px;
  transition: all 0.15s; font-weight: 500;
}
.add-btn:hover { background: #10b981; color: #fff; }
.add-btn:hover { background: var(--accent); color: #fff; transform: translateY(-1px); }
.del-btn {
  background: #fef2f2; border: 1px solid #fca5a5; color: var(--danger);
  padding: 4px 10px; cursor: pointer; border-radius: 5px; line-height: 1; transition: all 0.15s;
}
.del-btn:hover { background: var(--danger); color: #fff; }
.split-btn {
  background: #fffbeb; border: 1px solid #fcd34d; color: #92400e;
  padding: 4px 10px; cursor: pointer; border-radius: 5px; font-size: 0.85rem; transition: all 0.15s;
}
.split-btn:hover { background: var(--warn); color: #fff; }
.add-line { padding: 6px 0 10px; }

/* ───── TOC ───── */
.toc-help {
  color: var(--muted); font-size: 0.82rem; margin-bottom: 12px;
  padding: 10px 14px; background: #eff6ff; border-left: 3px solid var(--brand-1); border-radius: 0 5px 5px 0;
}
.toc-section { margin-bottom: 1.2rem; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.toc-sec-row {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  background: linear-gradient(90deg, var(--bg-soft), transparent);
  font-weight: 600; border-left: 3px solid var(--brand-1);
}
.toc-sec-title { flex: 1; }
.toc-count { font-size: 0.72rem; color: var(--muted); font-weight: 400;
  background: var(--bg); padding: 2px 8px; border-radius: 10px; }
.toc-clause {
  display: flex; gap: 8px; align-items: center; padding: 6px 12px 6px 28px;
  font-size: 0.88rem; border-top: 1px solid var(--bg);
}
.toc-clause-text { flex: 1; color: #334155; }
.toc-clause:hover { background: var(--bg-soft); }
.toc-mini { padding: 2px 8px !important; font-size: 0.72rem !important; line-height: 1.4; }

/* ───── Terms ───── */
.term {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 8px; background: var(--paper); transition: all 0.15s;
}
.term:hover { border-color: var(--brand-1); box-shadow: var(--shadow-sm); }
.term-row { display: flex; align-items: center; gap: 8px; }
.term-name { flex: 1; font-weight: 600; color: var(--ink); font-size: 0.95rem; }
.term-meta { display: flex; gap: 8px; align-items: center; font-size: 0.78rem; }
.term-count {
  background: linear-gradient(135deg, #fef3c7, #fde68a); color: #78350f;
  padding: 2px 10px; border-radius: 12px; font-weight: 700; font-size: 0.75rem;
  cursor: pointer; transition: all 0.15s;
}
.term-count:hover { background: var(--warn); color: #fff; }
.term-def { margin-top: 6px; padding-left: 14px; color: #475569; font-size: 0.9rem; line-height: 1.5;
  border-left: 2px solid var(--bg); }
.term-hit {
  text-decoration: underline; text-decoration-color: var(--warn);
  text-decoration-thickness: 2px; text-underline-offset: 3px; cursor: help;
}

/* ───── Modal ───── */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px); z-index: 1000; align-items: center; justify-content: center;
}
.modal {
  background: var(--paper); max-width: 760px; width: 92%; max-height: 82vh;
  display: flex; flex-direction: column; border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-head {
  padding: 14px 18px; background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff; display: flex; justify-content: space-between; align-items: center;
}
.modal-close { background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; line-height: 1;
  opacity: 0.8; }
.modal-close:hover { opacity: 1; }
.modal-body { padding: 12px 18px; overflow-y: auto; }
.occ {
  padding: 10px 12px; border-bottom: 1px solid var(--bg); cursor: pointer;
  border-radius: 5px; transition: all 0.1s;
}
.occ:hover { background: var(--bg-soft); }
.occ-meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.occ-page { color: var(--brand-1); font-weight: 500; }
.occ-snippet { font-size: 0.88rem; line-height: 1.5; color: var(--ink); }
.occ-snippet mark { background: #fef08a; padding: 1px 3px; border-radius: 2px; }

/* ───── Duplicates ───── */
.dup-controls {
  display: flex; gap: 1rem; margin-bottom: 1rem; padding: 10px 14px;
  background: var(--bg-soft); border-radius: 6px; font-size: 0.85rem;
}
.dup-cluster { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 14px; overflow: hidden; }
.dup-head {
  background: linear-gradient(90deg, var(--bg-soft), transparent);
  padding: 8px 14px; display: flex; gap: 8px; align-items: center; font-size: 0.85rem;
}
.dup-cross { background: var(--brand-1); color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 0.7rem; }
.dup-current { background: var(--warn); color: #fff; padding: 2px 8px; border-radius: 3px; font-size: 0.7rem; margin-left: 6px; }
.dup-member { padding: 10px 14px; border-top: 1px solid var(--bg); cursor: pointer; transition: background 0.1s; }
.dup-member:hover { background: var(--bg-soft); }
.dup-member.is-current { background: #fffbeb; border-left: 3px solid var(--warn); }
.dup-member.is-current:hover { background: #fef3c7; }
.dup-meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.dup-text { font-size: 0.88rem; line-height: 1.5; color: var(--ink); }
.clause.flash { animation: flash 1.5s ease-out; }
@keyframes flash { 0% { background: #fef3c7; } 100% { background: transparent; } }

/* ───── Tables (in clauses) ───── */
table { border-collapse: collapse; width: 100%; margin-bottom: 1rem; font-size: 0.85rem; }
th, td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
th { background: var(--bg-soft); font-weight: 600; color: var(--ink); }
.table-meta { font-size: 0.8rem; color: var(--muted); margin: 8px 0 4px; }

/* ───── Raw / JSON ───── */
pre {
  white-space: pre-wrap; font-size: 0.78rem; background: #f8fafc;
  padding: 12px; border-radius: 6px; border: 1px solid var(--border);
  font-family: ui-monospace, "SF Mono", monospace;
}
.json-bar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 12px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}

/* ───── Upload ───── */
.upload-form {
  display: flex; flex-direction: column; gap: 12px; max-width: 520px;
  margin: 1rem 0; padding: 18px; background: var(--bg-soft);
  border-radius: var(--radius-lg); border: 1px solid var(--border);
}
.upload-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem;
  color: var(--ink); font-weight: 500; }
.upload-form input[type="text"], .upload-form input[type="file"] {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 0.9rem; background: #fff; transition: border-color 0.15s;
}
.upload-form input:focus { outline: none; border-color: var(--brand-1); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }
.upload-form button { align-self: flex-start; padding: 9px 18px !important; font-size: 0.9rem !important; }
.upload-progress { padding: 14px; background: linear-gradient(135deg, #fffbeb, #fef3c7); border-radius: 6px; border: 1px solid #fcd34d; }
.progress-msg { color: #78350f; font-size: 0.9rem; margin-bottom: 8px; font-weight: 500; }
.progress-bar { background: #fef3c7; border: 1px solid #fcd34d; border-radius: 10px; height: 14px; overflow: hidden; }
.progress-fill { background: linear-gradient(90deg, #f59e0b, var(--warn)); height: 100%; transition: width 0.3s ease; }
.progress-pct { font-size: 0.75rem; color: #78350f; margin-top: 6px; text-align: right; font-weight: 600; }

/* ───── Uploads list ───── */
.uploads-table { width: 100%; font-size: 0.85rem; }
.uploads-table th { background: var(--bg-soft); text-align: left; padding: 8px 10px; font-weight: 600; }
.uploads-table td { padding: 6px 10px; border-bottom: 1px solid var(--bg); vertical-align: middle; }
.uploads-table tr:hover { background: var(--bg-soft); }
.uploads-table input { width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.85rem; background: #fff; }
.uploads-table .upl-fn { color: var(--muted); font-family: ui-monospace, monospace; font-size: 0.72rem; }
.upl-actions { white-space: nowrap; display: flex; gap: 4px; }
.upl-status { background: #d1fae5; color: #065f46; padding: 2px 8px; border-radius: 10px; font-size: 0.72rem; font-weight: 500; }
.upl-status.err { background: #fef2f2; color: var(--danger); }

/* ───── Comments ───── */
.comments-bar {
  display: flex; gap: 1rem; align-items: center; padding: 12px 14px;
  background: var(--bg-soft); border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem;
}
.cmt {
  background: var(--paper); border: 1px solid var(--border); border-left: 4px solid var(--brand-1);
  padding: 12px 16px; margin-bottom: 10px; border-radius: 6px; transition: all 0.15s;
}
.cmt:hover { box-shadow: var(--shadow-sm); }
.cmt-head { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; margin-bottom: 6px; }
.cmt-meta { flex: 1; color: var(--muted); font-size: 0.78rem; }
.cmt-time { color: #94a3b8; }
.cmt-body { font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap; color: var(--ink); }

/* ───── Save / Undo buttons in header ───── */
#undoBtn, #saveBtn {
  padding: 6px 12px; cursor: pointer; border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08); color: #fff; border-radius: 5px; font-size: 0.82rem;
  transition: all 0.15s;
}
#undoBtn:hover, #saveBtn:hover { background: rgba(255,255,255,0.18); }
#saveBtn.dirty { background: var(--warn); border-color: var(--warn); animation: pulse 2s infinite; }
#undoBtn:disabled { opacity: 0.35; cursor: default; }
#saveBtn:disabled { opacity: 0.5; cursor: wait; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.5); } 50% { box-shadow: 0 0 0 6px rgba(217, 119, 6, 0); } }
[contenteditable="true"]:focus { background: #fffbeb; outline: 1px dashed var(--brand-1); }
.upload-ok { color: #065f46; padding: 10px; background: #d1fae5; border-radius: 3px; line-height: 1.5; }
.upload-err { color: #991b1b; padding: 10px; background: #fef2f2; border-radius: 3px; }
#jsonView { max-height: 75vh; overflow: auto; font-family: ui-monospace, "SF Mono", monospace; }
[contenteditable="true"]:focus { background: #fffbe6; outline: 1px dashed #2563eb; }
#undoBtn, #saveBtn { padding: 4px 10px; cursor: pointer; border: 1px solid #4b5563; background: #374151; color: #fff; border-radius: 3px; }
#undoBtn:disabled { opacity: 0.4; cursor: default; }
#saveBtn.dirty { background: #d97706; border-color: #d97706; }
#saveBtn:disabled { opacity: 0.5; cursor: wait; }
#statusSelect { padding: 4px; }

/* ─── ISO 19650 status select colors ─── */
#statusSelect option[value="S0"] { background: #f1f5f9; }
#statusSelect option[value="S1"] { background: #fef3c7; }
#statusSelect option[value="S2"] { background: #ecfdf5; }
#statusSelect option[value="S3"] { background: #dbeafe; }
#statusSelect option[value="S4"] { background: #fae8ff; }

/* ─── BIM annotation badge + modal ─── */
.bim-badge {
  background: linear-gradient(135deg, #0ea5e9, #1e40af); color: #fff;
  font-size: 0.7rem; padding: 2px 7px; border-radius: 10px;
  font-weight: 600; white-space: nowrap; align-self: center;
}
.bim-req {
  border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 10px; padding: 10px; background: var(--bg-soft);
}
.bim-req-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.bim-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px;
}
.bim-grid label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 0.78rem; color: var(--muted);
}
.bim-grid input, .bim-grid select {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.85rem; background: #fff; color: var(--ink);
}
.bim-grid input:focus, .bim-grid select:focus {
  outline: none; border-color: var(--brand-1);
}

/* ─── Term i18n tags ─── */
.term-i18n {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--bg);
  display: flex; flex-wrap: wrap; gap: 4px;
}
.term-tag { font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; }
.term-tag.bsdd {
  background: #ecfeff; color: #0e7490;
  border: 1px solid #67e8f9; text-decoration: none;
}
.term-tag.bsdd:hover { background: #06b6d4; color: #fff; }
.term-tag.ifc { background: #f3e8ff; color: #6b21a8; }
.term-tag.lang {
  background: var(--bg-soft); color: var(--muted);
  font-family: ui-monospace, monospace;
}

/* ─── BIM attribution + state + lock (Task 3, 4) ─── */
.bim-attr {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--muted); padding: 2px 6px;
  background: #f8fafc; border-radius: 10px;
}
.bim-state {
  color: #fff; font-weight: 600; padding: 1px 7px; border-radius: 8px;
  font-size: 0.65rem; text-transform: uppercase;
}
.bim-lock {
  background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  padding: 2px 8px; border-radius: 10px; font-size: 0.72rem; font-weight: 600;
  margin-left: 4px;
}

/* ─── Export tab (Task 5) ─── */
.export-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px; margin-top: 1rem;
}
.export-card {
  display: flex; gap: 12px; padding: 16px;
  background: var(--paper); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: all 0.15s; text-align: left;
  font-family: inherit; font-size: inherit; color: var(--ink);
  align-items: center;
}
.export-card:hover:not(:disabled) {
  border-color: var(--brand-1); box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.export-card:disabled { opacity: 0.5; cursor: not-allowed; }
.export-icon { font-size: 1.8rem; flex-shrink: 0; }
.export-desc { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* ─── Drag-drop bulk upload ─── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: 8px; padding: 28px;
  text-align: center; margin: 1rem 0; transition: all 0.15s; cursor: pointer;
  background: var(--bg-soft);
}
.drop-zone.over { border-color: var(--brand-1); background: #eff6ff; }
.drop-icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.6; }
.bulk-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.bulk-item {
  display: grid; grid-template-columns: 24px 1fr auto; gap: 10px;
  padding: 6px 10px; background: var(--paper); border-radius: 4px;
  border-left: 3px solid var(--border); font-size: 0.85rem;
}
.bulk-pending { border-left-color: #cbd5e1; opacity: 0.7; }
.bulk-uploading { border-left-color: var(--warn); }
.bulk-done { border-left-color: var(--accent); background: #ecfdf5; }
.bulk-error { border-left-color: var(--danger); background: #fef2f2; color: #991b1b; }
.bulk-icon { font-weight: 700; text-align: center; }
.bulk-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bulk-msg { color: var(--muted); font-size: 0.78rem; }

/* ─── Mobile responsive (≤900px) ─── */
@media (max-width: 900px) {
  /* Header — buttons wrap */
  header {
    flex-wrap: wrap; padding: 8px 12px; gap: 8px;
  }
  header h1 { font-size: 0.85rem; flex-basis: 100%; order: -1; margin-bottom: 4px; }
  .brand-link { order: -2; }
  .header-logo { height: 28px; }
  header select { min-width: 0; flex: 1 1 200px; font-size: 0.82rem; padding: 5px 8px; }
  #status { font-size: 0.7rem; flex-basis: 100%; min-width: 0; }
  #adminLink, #logoutBtn, #undoBtn, #saveBtn { padding: 4px 8px; font-size: 0.75rem; }

  /* Layout — vertical stack */
  main {
    grid-template-columns: 1fr;
    grid-template-rows: 40vh 1fr;
    gap: 4px; padding: 4px;
  }
  section { padding: 12px; border-radius: 6px; }
  #pdfPane { max-height: 40vh; overflow: auto; }
  #pdfCanvas { max-height: 32vh; object-fit: contain; }

  /* Tabs — scrollable horizontal */
  .tabs {
    flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; padding-bottom: 4px;
  }
  .tab {
    flex-shrink: 0; scroll-snap-align: start;
    padding: 6px 10px; font-size: 0.78rem;
  }

  /* Clause row — stack vertically */
  .clause {
    flex-direction: column; align-items: stretch; gap: 6px;
    padding: 10px 4px;
  }
  .clause > input.num-input { width: 80px; }
  .btn-col {
    flex-direction: row; flex-wrap: wrap; gap: 4px;
    border-top: 1px solid var(--bg); padding-top: 6px;
  }
  .btn-col button { width: 32px; height: 28px; }

  /* TOC */
  .toc-clause { padding: 4px 6px 4px 16px; font-size: 0.85rem; flex-wrap: wrap; }
  .toc-mini { width: 28px; height: 24px; padding: 0 !important; }

  /* Term card */
  .term { padding: 10px 12px; }
  .term-row { flex-wrap: wrap; gap: 6px; }
  .term-name { flex: 1 1 100%; }

  /* Modal — full screen-ийн ойролцоо */
  .modal { width: 96%; max-height: 90vh; }
  .modal-head { padding: 10px 12px; font-size: 0.95rem; }
  .modal-body { padding: 8px 12px; }
  .bim-grid { grid-template-columns: 1fr; gap: 6px; }
  .bim-grid label[style*="span 2"] { grid-column: span 1 !important; }

  /* Upload */
  .upload-form { padding: 12px; max-width: 100%; }
  .drop-zone { padding: 18px 12px; }
  .uploads-table { font-size: 0.78rem; }
  .uploads-table th, .uploads-table td { padding: 4px 6px; }
  .uploads-table .upl-fn { display: none; } /* нэр баган мобайлд хасах */

  /* Export */
  .export-grid { grid-template-columns: 1fr; }

  /* Comments */
  .cmt { padding: 8px 10px; }
  .cmt-head { flex-wrap: wrap; }
  .cmt-meta { flex-basis: 100%; font-size: 0.72rem; }

  /* Duplicates */
  .dup-controls { flex-wrap: wrap; gap: 0.5rem; }
  .dup-controls label { flex-basis: 100%; }
  .dup-text { font-size: 0.85rem; }

  /* JSON view */
  pre { font-size: 0.7rem; }
  #jsonView { max-height: 60vh; }
  .json-bar { flex-wrap: wrap; }

  /* Tables hide scroll bars but allow swipe */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  th, td { padding: 4px 6px; font-size: 0.78rem; }
}

/* ─── Phone (≤480px) ─── */
@media (max-width: 480px) {
  body { font-size: 13px; }
  header h1 { display: none; } /* зайны хувьд гарчиг хасах */
  main { grid-template-rows: 35vh 1fr; }
  .tab { padding: 5px 8px; font-size: 0.72rem; }
  .section-title { font-size: 0.85rem; padding: 6px 10px; }
  .clause { padding: 8px 2px; }
}

/* ─── Touch гадаргуунд hover-аас сэрвэгчилэх ─── */
@media (hover: none) {
  .clause .actions, .clause .btn-col { opacity: 1; } /* hover тооцохгүй ил */
  .add-btn:hover { transform: none; }
}
