/* Belfort ResearchOps Lite — self-contained stylesheet (no external CDN).
   Clean, neutral, professional. Light + dark via prefers-color-scheme. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e6ea;
  --text: #1c2430;
  --muted: #5b6672;
  --primary: #2f5bd0;
  --primary-ink: #ffffff;
  --sidebar-bg: #131b2b;
  --sidebar-ink: #c7d0dc;
  --sidebar-ink-active: #ffffff;
  --sidebar-active: #26324a;
  --ok: #1f8f5f; --ok-bg: #e5f5ec;
  --warn: #b9791b; --warn-bg: #fbf0dc;
  --danger: #c0392b; --danger-bg: #fbe8e6;
  --info: #2f5bd0; --info-bg: #e7edfb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #171f2e; --surface-2: #1e2838; --border: #2a3446;
    --text: #e6ebf2; --muted: #94a1b2; --primary: #5b83e6; --sidebar-bg: #0b1017;
    --sidebar-active: #1d2740; --shadow: none;
    --ok-bg:#12321f; --warn-bg:#32270f; --danger-bg:#331a17; --info-bg:#131f38;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Modern themed scrollbars (Firefox + WebKit), light/dark aware */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px;
  border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}
.sidebar .brand { padding: 1.1rem 1.1rem .6rem; font-weight: 700; color: #fff; font-size: 1.05rem; }
.sidebar .brand small { display:block; font-weight: 400; color: var(--sidebar-ink); font-size:.72rem; letter-spacing:.03em; }
.nav { padding: .4rem .5rem; overflow-y: auto; flex: 1; }
.nav .group { color: #6b7688; text-transform: uppercase; font-size: .68rem; letter-spacing: .06em; padding: .8rem .6rem .3rem; }
.nav a {
  display: flex; align-items: center; gap: .55rem; padding: .5rem .65rem; border-radius: 8px;
  color: var(--sidebar-ink); font-size: .92rem; margin-bottom: 1px;
}
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: var(--sidebar-ink-active); font-weight: 600; }
.nav a .ico { width: 1.1rem; text-align: center; opacity: .9; }
.sidebar .who { padding: .8rem 1rem; border-top: 1px solid #222c3d; font-size: .82rem; color: var(--sidebar-ink); }
.sidebar .who a { color: #9fb2d8; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1.4rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
/* Fills the whole visible width beside the sidebar on any monitor / scale. */
.content { padding: 1.35rem clamp(1rem, 2.2vw, 2.6rem); width: 100%; max-width: none; flex: 1; min-width: 0; }

/* Cards / grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card h3 { margin-bottom: .6rem; }
.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .n { font-size: 1.7rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .82rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
.table-wrap { overflow-x: auto; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--surface-2); }

/* Buttons */
.btn { display: inline-flex; align-items:center; gap:.4rem; padding: .5rem .85rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: .9rem; font-weight: 500; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.06); background: var(--primary); }
.btn-sm { padding: .3rem .55rem; font-size: .82rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }
.actions { display:flex; gap:.5rem; flex-wrap: wrap; align-items:center; }

/* Forms */
.form-row { margin-bottom: .9rem; }
label { display:block; font-size: .82rem; color: var(--muted); margin-bottom: .25rem; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 92px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .9rem; }
.help { color: var(--muted); font-size: .78rem; margin-top: .2rem; }

/* Badges */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border:1px solid var(--border); white-space: nowrap; }
.badge[data-status="active"], .badge[data-status="approved"], .badge[data-status="completed"], .badge[data-status="done"], .badge[data-status="accepted"] { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge[data-status="blocked"], .badge[data-status="rejected"], .badge[data-status="failed"], .badge[data-status="cancelled"] { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge[data-status="at_risk"], .badge[data-status="in_review"], .badge[data-status="paused"], .badge[data-status="pending"], .badge[data-status="processing"] { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge[data-priority="high"], .badge[data-priority="critical"] { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge[data-priority="medium"] { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

/* Flash */
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .7rem; font-size: .9rem; border:1px solid transparent; }
.flash.success { background: var(--ok-bg); color: var(--ok); }
.flash.error, .flash.danger { background: var(--danger-bg); color: var(--danger); }
.flash.info { background: var(--info-bg); color: var(--info); }
.flash.warning { background: var(--warn-bg); color: var(--warn); }

/* Toasts — overlay notifications (used for all flash messages) */
.toasts {
  position: fixed; top: 1rem; inset-inline-end: 1rem; z-index: 1000;
  display: flex; flex-direction: column; gap: .5rem; max-width: min(92vw, 380px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: .6rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-inline-start-width: 4px; border-inline-start-color: var(--muted);
  border-radius: 10px; padding: .7rem .8rem; box-shadow: 0 10px 28px rgba(16,24,40,.22);
  font-size: .9rem; pointer-events: auto; animation: toastin .18s ease-out;
}
.toast.toast-error, .toast.toast-danger { border-inline-start-color: var(--danger); background: var(--danger-bg); }
.toast.toast-success { border-inline-start-color: var(--ok); background: var(--ok-bg); }
.toast.toast-info { border-inline-start-color: var(--info); background: var(--info-bg); }
.toast.toast-warning { border-inline-start-color: var(--warn); background: var(--warn-bg); }
.toast-msg { flex: 1; line-height: 1.35; }
.toast-x {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: .95rem; line-height: 1; padding: .05rem .15rem;
}
.toast-x:hover { color: var(--text); }
.toast.hiding { animation: toastout .25s ease-in forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastout { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* Misc */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.page-head { display:flex; align-items:center; justify-content: space-between; gap:1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.pill-row { display:flex; gap:.4rem; flex-wrap: wrap; align-items:center; }
.crumbs { color: var(--muted); font-size: .82rem; margin-bottom: .3rem; }
.crumbs a { color: var(--muted); }
.empty { color: var(--muted); padding: 1.2rem; text-align:center; }
.kv { display:grid; grid-template-columns: 150px 1fr; gap: .35rem .8rem; }
.kv dt { color: var(--muted); font-size:.85rem; }
.kv dd { margin: 0; }
.filters { display:flex; gap:.6rem; flex-wrap: wrap; align-items:end; }
.filters .form-row { margin: 0; }
.token-box { background: var(--surface-2); border:1px dashed var(--border); padding:.7rem; border-radius:8px; word-break: break-all; }
.tag { display:inline-block; background: var(--surface-2); border:1px solid var(--border); border-radius: 6px; padding: .05rem .4rem; font-size:.78rem; margin: 0 .2rem .2rem 0; }

/* Gantt */
.gantt-ticks { position: relative; height: 18px; margin-left: 220px; border-bottom: 1px solid var(--border); }
.gantt-tick { position: absolute; font-size: .68rem; color: var(--muted); transform: translateX(-50%); white-space: nowrap; }
.gantt-group-name { font-weight: 700; margin: .9rem 0 .35rem; font-size: .9rem; }
.gantt-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.gantt-label { width: 214px; flex-shrink: 0; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gantt-label a { color: var(--text); }
.gantt-track { position: relative; flex: 1; height: 22px; background: var(--surface-2); border-radius: 5px; }
.gantt-bar { position: absolute; top: 3px; height: 16px; border-radius: 5px; background: var(--primary); min-width: 6px; }
.gantt-bar[data-status="blocked"], .gantt-bar[data-status="rejected"] { background: var(--danger); }
.gantt-bar[data-status="in_review"], .gantt-bar[data-status="at_risk"], .gantt-bar[data-status="paused"] { background: var(--warn); }
.gantt-bar[data-status="done"], .gantt-bar[data-status="approved"] { background: var(--ok); }
.gantt-dep { position: absolute; right: -14px; top: 0; color: var(--warn); font-size: .8rem; }

/* Kanban */
.kanban { display: flex; gap: .7rem; overflow-x: auto; padding-bottom: .5rem; align-items: flex-start; }
.kanban-col { flex: 0 0 250px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .5rem; }
.kanban-col h4 { margin: .1rem .2rem .55rem; font-size: .8rem; display: flex; justify-content: space-between; align-items: center; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.kanban-col h4 .count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; font-size: .72rem; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid transparent; border-radius: 8px; padding: .5rem .6rem; margin-bottom: .5rem; box-shadow: var(--shadow); }
.kcard.blocked { border-left-color: var(--danger); }
.kcard .ktitle { font-weight: 600; font-size: .88rem; line-height: 1.25; }
.kcard .ktitle a { color: var(--text); }
.kcard .kmeta { display: flex; flex-wrap: wrap; gap: .25rem .5rem; margin-top: .35rem; font-size: .72rem; color: var(--muted); align-items: center; }
.kcard .kchips { display: flex; gap: .25rem; flex-wrap: wrap; margin-top: .35rem; }
.kcard form.kmove { margin-top: .45rem; display: flex; gap: .3rem; }
.kcard form.kmove select { padding: .2rem .3rem; font-size: .74rem; }
.kcard form.kmove button { padding: .2rem .5rem; font-size: .74rem; }

/* Task graph */
.graph-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); max-height: 72vh; }
.glegend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: .78rem; margin: .2rem 0 .6rem; color: var(--muted); }
.glegend span { display: inline-flex; align-items: center; gap: .35rem; }
.gswatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.gnode text { font: 600 11px system-ui, sans-serif; fill: #10233f; }
.gnode .gsub { font-weight: 400; fill: #33455f; }

/* RTL (Persian). With <html dir="rtl"> the flex sidebar naturally moves to the
   right; these tweaks fix text alignment and keep IDs/dates/mono left-to-right. */
html[dir="rtl"] body { direction: rtl; }
html[dir="rtl"] th, html[dir="rtl"] td { text-align: right; }
html[dir="rtl"] .right { text-align: left; }
html[dir="rtl"] .nav .group { text-align: right; }
html[dir="rtl"] .kv { grid-template-columns: 150px 1fr; }
html[dir="rtl"] .mono, html[dir="rtl"] .gantt-tick, html[dir="rtl"] time {
  direction: ltr; unicode-bidi: isolate;
}
.langswitch { padding: .5rem 1rem; border-top: 1px solid #222c3d; display: flex; gap: .5rem; font-size: .82rem; }
.langswitch a { color: #9fb2d8; }
.langswitch a.active { color: #fff; font-weight: 700; }

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: column; }
  .nav { display: flex; flex-wrap: wrap; }
  .form-grid, .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}
