:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e3e6eb;
  --text: #1b1f27;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-soft: #e8efff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1d222a;
    --line: #2a3039;
    --text: #e8eaee;
    --muted: #9aa3af;
    --accent: #6b9bff;
    --accent-soft: #1d2a45;
    --ok: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --bad-soft: #3a1d1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", "Rubik", "Assistant", system-ui, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2 { margin: 0; }
button { font: inherit; }

/* ---- כפתורים ---- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- מותג ---- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand.big { font-size: 22px; justify-content: center; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--accent) url("icon.svg") center / 20px no-repeat;
}

/* ---- התחברות ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; display: grid; gap: 14px; text-align: center; }
.login-card p { margin: 0; }
input[type=password] {
  width: 100%; padding: 11px 13px; font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
input[type=password]:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }

/* ---- סרגל עליון ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.model {
  margin-inline-start: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 6px 6px;
  padding-inline-start: 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2);
}
.model-text { display: grid; line-height: 1.25; }
.model-text strong { font-size: 14px; }
.model-text span { font-size: 12.5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.off { background: var(--muted); }
.dot.bad { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---- פריסה ---- */
.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
}
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.drop {
  display: grid; justify-items: center; gap: 4px; text-align: center;
  padding: 26px 16px;
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.drop .muted { font-size: 13px; }
.drop-icon {
  width: 38px; height: 38px; margin-bottom: 6px;
  background: var(--accent);
  mask: url("upload.svg") center / contain no-repeat;
}
.upload-msg { margin: 0; font-size: 13.5px; }
.upload-msg:empty { display: none; }

.list-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 6px; }
.list-head h2 { font-size: 15px; }
.list-head span { font-size: 13px; }

.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.doc {
  padding: 12px 14px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  display: grid; gap: 6px;
  transition: border-color .15s;
}
.doc:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.doc.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.doc-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.doc-sub { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); flex: none; }
.badge.processing { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.error { background: var(--bad-soft); color: var(--bad); }
.bar { height: 5px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.empty { text-align: center; padding: 18px 0; margin: 0; }

/* ---- תצוגת מסמך ---- */
.viewer { min-width: 0; }
.placeholder {
  height: 60vh; display: grid; place-content: center; justify-items: center; gap: 8px;
  color: var(--muted); text-align: center;
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.ph-icon { width: 46px; height: 46px; background: var(--line); mask: url("doc.svg") center / contain no-repeat; }

.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.doc-head h1 { font-size: 20px; word-break: break-word; }
.doc-head p { margin: 2px 0 0; font-size: 13.5px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; margin: 16px 0 12px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; color: var(--muted); padding: 8px 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.error-box {
  background: var(--bad-soft); color: var(--bad);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;
}

.error-box.info { background: var(--accent-soft); color: var(--accent); }

.page { margin-bottom: 18px; overflow: hidden; }
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; background: var(--panel-2); border-bottom: 1px solid var(--line);
  font-size: 13.5px; font-weight: 600;
}
.page-body { display: grid; grid-template-columns: 2fr 3fr; }
.page-body.text-only { grid-template-columns: 1fr; }
.page-img { border-inline-end: 1px solid var(--line); background: #fff; padding: 10px; }
.page-img img { width: 100%; display: block; }
.text-only .page-img { display: none; }
.page-md { padding: 14px 18px; min-width: 0; overflow-x: auto; }
.pending { color: var(--muted); font-style: italic; }
.pending.now::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); margin-inline-end: 8px; animation: pulse 1.2s infinite;
}

.raw {
  white-space: pre-wrap; word-break: break-word;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; font: 13.5px/1.6 "Cascadia Mono", Consolas, monospace;
}

/* ---- Markdown ---- */
.md h1, .md h2, .md h3, .md h4 { margin: .8em 0 .4em; line-height: 1.3; }
.md h1 { font-size: 1.3em; } .md h2 { font-size: 1.15em; } .md h3, .md h4 { font-size: 1.02em; }
.md > :first-child { margin-top: 0; }
.md p { margin: .45em 0; }
.md ul, .md ol { margin: .4em 0; padding-inline-start: 1.4em; }
.md li.check { list-style: none; margin-inline-start: -1.2em; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md code { background: var(--panel-2); padding: 0 4px; border-radius: 4px; font-size: .92em; }
.md table { border-collapse: collapse; margin: .6em 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: start; vertical-align: top; }
.md th { background: var(--panel-2); }
.md .tag { color: var(--muted); font-style: italic; }

/* ---- הודעה קופצת ---- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- מסכים צרים ---- */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .placeholder { height: auto; padding: 32px 16px; }
  .page-body { grid-template-columns: 1fr; }
  .page-img { border-inline-end: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .model { order: 3; width: 100%; margin: 0; }
  .model .btn { margin-inline-start: auto; }
  #logout { margin-inline-start: auto; }
}
