/* Anvar RAG chatbot — shared styles (RTL, light/dark) */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #f6f4ef;
  --bg-soft: #fffdf9;
  --panel: #ffffff;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --ink-faint: #8b95a3;
  --line: #e4e0d7;
  --accent: #1f6f5c;
  --accent-soft: #e7f2ee;
  --accent-ink: #14503f;
  --gold: #b4893c;
  --danger: #b23c3c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(24, 30, 40, .05), 0 8px 24px rgba(24, 30, 40, .06);
  --font: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  /* Without this the browser paints its own (white) background inside form
     controls while our inherited text colour is light — white on white. */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a;
    --bg-soft: #171b22;
    --panel: #1b2029;
    --ink: #e8eaed;
    --ink-soft: #a8b0bd;
    --ink-faint: #79828f;
    --line: #2a313c;
    --accent: #4fbf9f;
    --accent-soft: #16302a;
    --accent-ink: #8ad9c1;
    --gold: #d3a95e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.85;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Text-bearing controls state both colours explicitly. Relying on `inherit`
   for the text while the UA supplies the background is what made these
   unreadable in dark mode. */
input, select, textarea {
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
input[type=checkbox], input[type=radio] {
  padding: 0;
  accent-color: var(--accent);
  width: auto;
}
input[type=file] { padding: 7px 10px; color: var(--ink-soft); }
input::placeholder, textarea::placeholder { color: var(--ink-faint); opacity: 1; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
option { color: var(--ink); background: var(--panel); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--line); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: 13px; }

/* ---------------- admin shell ---------------- */
.admin-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--panel);
  border-inline-start: 1px solid var(--line);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar h1 { font-size: 16px; margin: 0 0 4px; }
.sidebar .sub { font-size: 12px; color: var(--ink-faint); margin-bottom: 22px; }
.sidebar nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--ink-soft);
  margin-bottom: 3px;
}
.sidebar nav a:hover { background: var(--bg-soft); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.content { flex: 1; padding: 28px 34px; max-width: 1180px; }
.page-title { margin: 0 0 4px; font-size: 22px; }
.page-sub { margin: 0 0 24px; color: var(--ink-soft); font-size: 14px; }

/* Grid and flex items default to min-width:auto, so one wide table forces the
   whole track wider than the viewport. Letting them shrink is what makes the
   inner .scroll-x wrappers actually take effect. */
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.card { min-width: 0; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat { padding: 18px; }
.stat .k { font-size: 13px; color: var(--ink-soft); }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .v small { font-size: 13px; font-weight: 400; color: var(--ink-faint); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 11px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
tbody tr:hover { background: var(--bg-soft); }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.tag-off { background: #eee; color: #777; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag-off { background: #2a313c; color: #97a0ad; }
}

.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--ink-soft); }
.field input[type=text], .field input[type=number], .field input[type=password],
.field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
}
.field textarea { min-height: 110px; resize: vertical; line-height: 1.9; }
.field .hint { font-size: 12px; color: var(--ink-faint); margin-top: 5px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.notice {
  padding: 11px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  margin-bottom: 18px;
  font-size: 14px;
}
.notice-error { background: #fdecec; color: #9b2c2c; }

.chunk {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--bg-soft);
}
.chunk .meta { font-size: 12px; color: var(--ink-faint); margin-bottom: 7px; }

pre.log {
  background: #10141a;
  color: #b9c6d6;
  padding: 14px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.8;
  max-height: 260px;
  overflow: auto;
  direction: ltr;
  text-align: left;
}

/* Wide content (tables with inputs, code) scrolls inside its own box instead
   of pushing the card wider than the grid column it sits in. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x > table { min-width: 100%; }

/* Below the phone breakpoint a table stops trying to fit and scrolls instead:
   squashing six columns into a 375px screen makes every one of them unreadable,
   and it was the source list that showed it worst. */
@media (max-width: 700px) {
  .scroll-x > table { min-width: 620px; }
  .scroll-x { border-radius: 10px; }
}

/* ---------------- mobile admin shell ---------------- */
.admin-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  /* The closed sidebar sits just outside the viewport. Without this the page
     itself grows by its width and scrolls sideways; `clip` (not `hidden`)
     because `hidden` would make html a containing block for the fixed panel. */
  html { overflow-x: clip; }

  .admin-layout { display: block; }

  .admin-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
  }
  .admin-topbar .brand { font-size: 15px; font-weight: 600; flex: 1; }
  .burger {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 38px;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-soft);
    cursor: pointer;
  }
  .burger span {
    display: block;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
  }

  /* Physical `right`, not a logical inset: the admin shell is always dir="rtl",
     and a dir-scoped override would out-specify the `.open` rule below. The
     drawer slides in from the same edge the desktop sidebar sits on. */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    width: 268px;
    max-width: 84vw;
    flex: none;
    height: 100dvh;
    z-index: 60;
    transform: translateX(100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  .sidebar-backdrop.on { opacity: 1; pointer-events: auto; }

  .content { padding: 18px 14px 40px; max-width: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { border-radius: 12px; }
  th, td { padding: 9px 8px; }
  .page-title { font-size: 19px; }
}


/* ---- file picker -------------------------------------------------------
   A native <input type=file> renders "Choose Files" and "No file chosen" in
   the browser's own locale; no attribute changes that text. The input is
   therefore visually hidden and driven by a label, so the button and the
   chosen-file text are ours and in Persian. The input stays focusable from the
   keyboard through the label's `for`. */
.filepick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filepick input[type="file"] {
  position: absolute; width: 1px; height: 1px; opacity: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.filepick .pickbtn {
  display: inline-block; cursor: pointer;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--ink);
  font-size: 13px; font-weight: 600;
}
.filepick .pickbtn:hover { border-color: var(--accent); color: var(--accent); }
.filepick input[type="file"]:focus-visible + .pickbtn { outline: 2px solid var(--accent); }
.filepick .picked { font-size: 12px; color: var(--ink-faint); }
