/* Arkivet: Modulysa design language (DM Serif Display + DM Sans, blue accent, soft greys) tuned for readers
   with reduced sight: large type, generous line height, strong contrast, one column, few controls. */
:root {
  --bg: #ffffff; --bg-soft: #f6f7fb; --bg-card: #f2f4f9; --bg-card-hover: #e9edf6;
  --text: #15161c; --text-2: #3f4350; --text-3: #6b7080;
  --accent: #2563eb; --accent-strong: #1d4ed8; --accent-tint: #e8efff; --accent-glow: rgba(37, 99, 235, 0.16);
  --amber: #f59e0b; --amber-tint: #fff4df; --green: #0f9f6e; --green-tint: #e3f7ef; --red: #c81e1e; --red-tint: #fdeaea;
  --mark: #ffe7a3; --border: rgba(20, 22, 30, 0.10); --border-strong: rgba(20, 22, 30, 0.22);
  --shadow-sm: 0 1px 2px rgba(20, 22, 30, 0.05), 0 2px 8px rgba(20, 22, 30, 0.04); --shadow-md: 0 6px 24px rgba(20, 22, 30, 0.08);
  --radius-sm: 10px; --radius-md: 14px; --radius-lg: 18px;
  --font-display: 'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --nav-h: 64px; --sidebar-w: 300px; --fs: 19px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font-body); font-size: var(--fs); line-height: 1.65; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; line-height: 1.2; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: 2rem; } h2 { font-size: 1.5rem; } h3 { font-size: 1.2rem; }
.muted { color: var(--text-3); }
.error { color: var(--red); }
.ok { color: var(--green); }
.small { font-size: .85rem; }
mark { background: var(--mark); padding: 0 2px; border-radius: 3px; }
mark.cur { background: var(--amber); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* auth */
body.auth { display: flex; align-items: center; justify-content: center; background: var(--bg-soft); padding: 16px; }
.auth-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px; width: min(94vw, 440px); display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow-md); }
.auth-card h1 { margin: 0 0 4px; font-size: 2.1rem; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: .95rem; color: var(--text-2); font-weight: 500; }
.auth-card input { padding: 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 1.05rem; }
.auth-link { font-size: .95rem; text-align: center; }

/* controls */
.primary { background: var(--accent); color: #fff; border: 0; border-radius: var(--radius-sm); padding: 13px 22px; font-size: 1rem; font-weight: 600; min-height: 48px; box-shadow: 0 6px 16px var(--accent-glow); }
.primary:hover { background: var(--accent-strong); }
.primary:disabled { opacity: .5; cursor: default; box-shadow: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: #fff; color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 11px 18px; font-weight: 500; min-height: 46px; text-decoration: none; }
.btn:hover { background: var(--bg-card); color: var(--text); }
.btn.danger { color: var(--red); }
.btn.sm, .btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: transparent; border: 0; border-radius: 10px; padding: 8px 12px; font-size: 1.1rem; color: var(--text); min-width: 44px; min-height: 44px; }
.icon-btn:hover { background: var(--bg-card); }
.wide { width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .95rem; color: var(--text-2); font-weight: 500; }
.field input, .field select, .field textarea { padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; font-size: 1rem; font-weight: 400; color: var(--text); }
.field textarea { min-height: 170px; font-family: var(--font-body); }
.field.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 400; }
.field.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.chip { display: inline-block; background: var(--bg-card); border-radius: 999px; padding: 3px 12px; font-size: .85rem; color: var(--text-2); margin: 2px 4px 2px 0; }
.chip.accent { background: var(--accent-tint); color: var(--accent-strong); }
.seg { display: inline-flex; background: var(--bg-card); border-radius: 999px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 8px 18px; font-weight: 600; color: var(--text-2); min-height: 42px; }
.seg button.active { background: #fff; color: var(--accent-strong); box-shadow: var(--shadow-sm); }
.seg.sm button { padding: 5px 14px; min-height: 36px; font-size: .9rem; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 12px; height: var(--nav-h); padding: 0 16px; background: rgba(255,255,255,.92); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.5rem; color: var(--text); text-decoration: none; margin-right: 10px; }
.brand:hover { color: var(--text); }
.brand-mark { width: 36px; height: 36px; border-radius: 11px; background: linear-gradient(135deg, var(--accent) 0%, #60a5fa 100%); color: #fff; display: grid; place-items: center; font-family: var(--font-display); font-size: 1.25rem; box-shadow: 0 6px 16px var(--accent-glow); }
.topnav { display: flex; gap: 4px; }
.topnav a { padding: 10px 18px; border-radius: 999px; text-decoration: none; color: var(--text-2); font-weight: 600; font-size: 1rem; }
.topnav a.active, .topnav a:hover { background: var(--bg-card); color: var(--text); }
.spacer { flex: 1; }
.usermenu { position: relative; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px 6px 6px; min-height: 44px; font-weight: 600; color: var(--text); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-tint); color: var(--accent-strong); display: grid; place-items: center; font-weight: 700; }
.dropdown { position: absolute; right: 0; top: 112%; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); min-width: 240px; display: flex; flex-direction: column; box-shadow: var(--shadow-md); z-index: 30; padding: 6px; }
.dropdown button, .dropdown a { text-align: left; padding: 12px 14px; background: transparent; border: 0; color: var(--text); text-decoration: none; border-radius: 10px; font-size: 1rem; }
.dropdown button:hover, .dropdown a:hover { background: var(--bg-card); }
.dd-langs { display: flex; gap: 4px; padding: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dd-langs button { flex: 1; text-align: center; padding: 8px 4px; font-size: .9rem; font-weight: 600; color: var(--text-2); }
.dd-langs button.active { background: var(--accent-tint); color: var(--accent-strong); }

/* layout */
.layout { display: flex; height: calc(100vh - var(--nav-h)); height: calc(100dvh - var(--nav-h)); }
.sidebar { width: var(--sidebar-w); flex: none; background: var(--bg-soft); border-right: 1px solid var(--border); padding: 14px; display: flex; flex-direction: column; gap: 12px; overflow: hidden; transition: margin .2s; }
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
.who { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.who select { padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; font-size: .95rem; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text); }
.chatlist { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; cursor: pointer; color: var(--text); text-decoration: none; }
.chat-item:hover, .chat-item.active { background: var(--bg-card-hover); color: var(--text); }
.chat-item .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .95rem; }
.chat-item .owner { font-size: .75rem; color: var(--text-3); display: block; }
.chat-item .x { opacity: 0; font-size: .85rem; padding: 4px; }
.chat-item:hover .x { opacity: .7; }
.main { flex: 1; min-width: 0; overflow-y: auto; }

/* ask view */
.ask { max-width: 820px; margin: 0 auto; padding: 24px 20px 220px; min-height: 100%; }
.welcome { text-align: center; margin: 10vh 0 30px; }
.welcome h1 { font-size: 2.4rem; margin: 0 0 12px; }
.welcome p { color: var(--text-2); font-size: 1.1rem; max-width: 560px; margin: 0 auto; }
.examples { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 22px; }
.examples button { background: #fff; border: 1px solid var(--border-strong); border-radius: 999px; padding: 10px 18px; color: var(--text-2); font-size: .95rem; }
.examples button:hover { background: var(--bg-card); }
.owner-note { background: var(--amber-tint); border-radius: var(--radius-md); padding: 14px 18px; margin: 0 0 16px; color: #6b4a00; font-size: 1rem; }
.msg { margin: 22px 0; }
.msg.user { text-align: right; }
.msg.user .bubble { background: var(--accent-tint); color: var(--text); border-radius: 20px 20px 6px 20px; padding: 14px 20px; display: inline-block; max-width: 85%; white-space: pre-wrap; text-align: left; }
.msg.assistant .bubble { background: transparent; }
.msg .meta { font-size: .8rem; color: var(--text-3); margin-top: 8px; }
.msg .kind { display: inline-block; font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-strong); margin-bottom: 6px; }
.status-line { color: var(--text-2); font-size: .95rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.status-line .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3 } to { opacity: 1 } }
.sources { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; font-size: .95rem; }
.sources h4 { margin: 0 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); font-weight: 700; }
.source { display: flex; gap: 10px; align-items: baseline; padding: 5px 0; }
.source .n { font-weight: 700; color: var(--accent); min-width: 30px; }
.source a { color: var(--text); text-decoration: none; font-weight: 600; }
.source a:hover { text-decoration: underline; }
.source .d { color: var(--text-3); font-size: .85rem; }
.sources summary { cursor: pointer; padding: 6px 0; }
sup.cite a { color: var(--accent); text-decoration: none; font-weight: 700; padding: 0 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.actions .btn { min-height: 40px; padding: 6px 14px; font-size: .9rem; }
.actions select { padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; font-size: .9rem; min-height: 40px; }
.composer { position: fixed; bottom: 0; left: 0; right: 0; padding: 14px 20px 22px; background: linear-gradient(transparent, var(--bg) 35%); pointer-events: none; z-index: 10; }
.composer-inner { max-width: 820px; margin: 0 auto; pointer-events: auto; display: flex; flex-direction: column; gap: 10px; }
.composer-box { background: #fff; border: 1px solid var(--border-strong); border-radius: 22px; box-shadow: var(--shadow-md); display: flex; gap: 10px; padding: 10px 10px 10px 20px; align-items: flex-end; }
.composer textarea { flex: 1; border: 0; resize: none; font-size: 1.1rem; line-height: 1.5; max-height: 240px; outline: none; background: transparent; padding: 10px 0; }
.composer .primary { border-radius: 16px; padding: 12px 20px; }
.composer-foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; font-size: .9rem; color: var(--text-3); }
body:not(.sidebar-collapsed) .composer { left: var(--sidebar-w); }

/* markdown content */
.md { line-height: 1.7; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--font-display); line-height: 1.25; margin: 1.4em 0 .5em; }
.md h1 { font-size: 1.7rem; } .md h2 { font-size: 1.45rem; } .md h3 { font-size: 1.2rem; } .md h4 { font-size: 1.05rem; font-family: var(--font-body); font-weight: 700; }
.md p { margin: .7em 0; }
.md ul, .md ol { padding-left: 1.5em; }
.md li { margin: .3em 0; }
.md blockquote { border-left: 4px solid var(--accent-tint); margin: .9em 0; padding: .3em 1.1em; color: var(--text-2); }
.md table { border-collapse: collapse; margin: 1em 0; font-size: .9rem; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--bg-card); }
.md code { background: var(--bg-card); padding: 1px 6px; border-radius: 5px; font-size: 90%; }
.md pre { background: var(--bg-card); padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; }
.md img { max-width: 100%; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md[dir=rtl] { text-align: right; }

/* find view */
.page { max-width: 1040px; margin: 0 auto; padding: 28px 20px 80px; }
.page > h1 { margin-bottom: 18px; }
.searchbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.searchbar input[type=search] { flex: 1; padding: 15px 18px; border: 1px solid var(--border-strong); border-radius: 16px; font-size: 1.1rem; background: #fff; min-height: 56px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; margin-bottom: 18px; }
.toolbar details { font-size: .95rem; }
.toolbar summary { cursor: pointer; color: var(--accent-strong); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.filters select { padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; font-size: .95rem; }
.result { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 20px; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.result h3 { margin: 0 0 4px; font-size: 1.15rem; font-family: var(--font-body); font-weight: 600; }
.result h3 a { color: var(--text); text-decoration: none; }
.result h3 a:hover { text-decoration: underline; color: var(--accent-strong); }
.result .d { color: var(--text-3); font-size: .85rem; margin-bottom: 8px; }
.result .snip { font-size: 1rem; color: var(--text-2); margin: 5px 0; }
.result .snip .h { color: var(--text-3); font-size: .85rem; }
.doclist { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.doclist th, .doclist td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: .95rem; vertical-align: top; }
.doclist th { background: var(--bg-card); font-size: .8rem; color: var(--text-3); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.doclist tr:hover td { background: var(--bg-soft); }
.doclist a { color: var(--text); text-decoration: none; font-weight: 600; }
.doclist a:hover { text-decoration: underline; color: var(--accent-strong); }
.doclist .path { color: var(--text-3); font-size: .82rem; word-break: break-all; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 18px 0; }
.grp-tag { display: inline-block; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 6px; background: var(--bg-card); color: var(--text-2); }
.grp-tag.image { background: #fde9f3; color: #a3155f; } .grp-tag.audio { background: var(--amber-tint); color: #8a5a00; } .grp-tag.video { background: #e9e4ff; color: #4c2bb3; } .grp-tag.document { background: var(--accent-tint); color: var(--accent-strong); }

/* document view */
.docview { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }
.doc-content { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 30px 40px; min-width: 0; box-shadow: var(--shadow-sm); }
.doc-content h1.doc-title { font-size: 1.9rem; margin: 10px 0 4px; }
.doc-side { position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column; gap: 12px; }
.meta-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; font-size: .95rem; }
.meta-card dt { color: var(--text-3); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; margin-top: 12px; font-weight: 700; }
.meta-card dd { margin: 2px 0 0; word-break: break-word; }
.meta-card .btns { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.meta-card .btns .btn { justify-content: flex-start; }
.findbox { display: flex; gap: 8px; align-items: center; }
.findbox input { flex: 1; padding: 11px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 1rem; }
.translate-box { display: flex; flex-direction: column; gap: 8px; }
.translate-box select { padding: 11px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 1rem; background: #fff; }
.doc-tabs { margin: 12px 0 16px; }
.trans-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* upload */
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); padding: 30px; text-align: center; background: var(--bg-soft); margin: 16px 0; }
.dropzone .row { justify-content: center; }
.progress { height: 10px; background: var(--bg-card); border-radius: 5px; overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.joblist .job { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 18px; margin-bottom: 10px; }
.status-pill { display: inline-block; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 9px; border-radius: 999px; background: var(--bg-card); color: var(--text-2); }
.status-pill.done { background: var(--green-tint); color: var(--green); } .status-pill.running, .status-pill.queued { background: var(--accent-tint); color: var(--accent-strong); } .status-pill.error { background: var(--red-tint); color: var(--red); }

/* admin */
.tabs { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.tabs button { background: #fff; border: 1px solid var(--border-strong); border-radius: 999px; padding: 9px 18px; font-weight: 600; color: var(--text-2); min-height: 44px; }
.tabs button.active { background: var(--text); color: #fff; border-color: var(--text); }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.card h2 { margin: 0 0 14px; font-size: 1.3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--bg-card); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat b { display: block; font-size: 1.6rem; font-family: var(--font-display); font-weight: 400; }
.stat span { font-size: .8rem; color: var(--text-3); }
.bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.bar i { display: block; height: 100%; background: var(--accent); }
table.plain { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.plain th, table.plain td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.plain th { color: var(--text-3); font-weight: 700; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
table.plain select, table.plain input { padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: .9rem; }
.tpl-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.tpl-grid textarea { min-height: 150px; font-size: .9rem; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,22,30,.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: var(--radius-lg); padding: 26px; width: min(94vw, 460px); display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-md); }
.modal-card h3 { margin: 0; }

@media (max-width: 960px) {
  :root { --fs: 18px; }
  .docview { grid-template-columns: 1fr; }
  .doc-side { position: static; }
  .doc-content { padding: 20px; }
  .grid2 { grid-template-columns: 1fr; }
  .sidebar { position: absolute; z-index: 15; height: calc(100vh - var(--nav-h)); height: calc(100dvh - var(--nav-h)); box-shadow: var(--shadow-md); }
  body:not(.sidebar-collapsed) .composer { left: 0; }
  .topnav a { padding: 8px 12px; }
  .user-btn .uname { display: none; }
  .brand span:last-child { display: none; }
  .ask { padding-bottom: 240px; }
}
@media print {
  .topbar, .sidebar, .doc-side, .composer, .actions { display: none !important; }
  .layout { height: auto; }
  .doc-content { border: 0; padding: 0; box-shadow: none; }
}
