/* ─────────────────────────────────────────────────────────────
   Org Architect Cockpit — palette + typography match agenticar.ir
   Cream/grainy background, sharp dark lines, soft-green accents,
   apple-style minimalism, Persian RTL primary.
   ───────────────────────────────────────────────────────────── */

:root {
  /* Palette */
  --ink:        #1C1814;        /* deep dark — primary text + borders   */
  --ink-2:      #2B2620;        /* slightly softer dark                  */
  --muted:      #5A5147;        /* secondary text                        */
  --muted-2:    #8A8074;
  --paper:      #FBFAF6;        /* canvas                                */
  --paper-2:    #F4EEE2;        /* warmer cream                          */
  --paper-3:    #ECE3D0;        /* divider tint                          */
  --white:      #FFFFFF;
  --green:      #3F7A50;        /* primary green                         */
  --green-2:    #7DBE8A;
  --green-3:    #B7E0A8;
  --green-4:    #D6EFCB;
  --amber:      #E2B871;
  --rose:       #E27474;
  --line:       rgba(28, 24, 20, 0.16);
  --line-2:     rgba(28, 24, 20, 0.08);
  --shadow-1:   0 1px 0 rgba(28, 24, 20, 0.04);
  --shadow-2:   0 6px 24px rgba(28, 24, 20, 0.08);
  --shadow-3:   0 12px 40px rgba(28, 24, 20, 0.14);

  /* Spacing scale */
  --pad-1: 6px;
  --pad-2: 10px;
  --pad-3: 14px;
  --pad-4: 18px;
  --pad-5: 26px;
  --pad-6: 36px;
  --rail-w: 230px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Vazirmatn', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--paper);
  /* subtle grain via layered radial gradients */
  background-image:
    radial-gradient(circle at 20% 10%, rgba(183, 224, 168, 0.10), transparent 60%),
    radial-gradient(circle at 85% 90%, rgba(228, 184, 113, 0.06), transparent 55%);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
em { font-style: normal; color: var(--green); }

/* ─── Brand mark ─── */
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--green-3), var(--green));
  display: inline-block; position: relative;
  border: 1.2px solid var(--ink);
  flex-shrink: 0;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px;
  border: 1.2px solid var(--ink); border-radius: 3px;
  background: var(--white);
}
.brand-stack { display: flex; align-items: center; gap: 10px; }
.brand-title { font-weight: 800; font-size: 16px; letter-spacing: 0.2px; direction: ltr; }
.brand-sub { color: var(--muted); font-size: 12px; }

/* ─── Top bar ─── */
.topbar {
  height: var(--topbar-h);
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.hamburger {
  display: none;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  width: 36px; height: 36px;
  flex-direction: column; justify-content: center; align-items: center; gap: 3px;
}
.hamburger span { display:block; width:18px; height:1.6px; background: var(--ink); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--white); border: 1px solid var(--ink);
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-1);
  transition: all 0.15s ease;
}
.chip:hover { background: var(--paper-2); }
.chip.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.chip.ghost:hover { color: var(--ink); border-color: var(--ink); }
.chip-icon { color: var(--green); }
.heartbeat {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--white); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
  direction: ltr;
}
.heartbeat.alive { border-color: var(--green); color: var(--green); background: rgba(214,239,203,0.4); }
.heartbeat.stale { border-color: var(--amber); color: #946A1F; background: rgba(228,184,113,0.18); }
.heartbeat.dead  { border-color: var(--rose);  color: #8E2C2C; background: rgba(226,116,116,0.14); }
.hb-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2);
}
.heartbeat.alive .hb-dot { background: var(--green); animation: pulse 2s ease-out infinite; }
.heartbeat.stale .hb-dot { background: var(--amber); }
.heartbeat.dead  .hb-dot { background: var(--rose); }
.pulse-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block;
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(63,122,80,0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(63,122,80,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,122,80,0); }
}

/* ─── Shell ─── */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}
.rail {
  background: var(--paper-2);
  border-left: 1px solid var(--line);
  padding: 18px 14px 26px;
  display: flex; flex-direction: column;
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.nav-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  font-size: 14px; color: var(--ink-2);
  transition: background 0.12s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.6); }
.nav-item.active {
  background: var(--white);
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-1);
  font-weight: 700;
}
.nav-icon { width: 22px; text-align: center; color: var(--green); font-size: 15px; }
.rail-footer { margin-top: auto; padding-top: 18px; }
.rail-tip {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12px; color: var(--muted);
  padding: 10px 12px;
  background: var(--white);
  border: 1px dashed var(--line);
  border-radius: 10px;
  line-height: 1.7;
}
.kicker-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  display: inline-block; margin-top: 6px;
  flex-shrink: 0;
}

/* ─── Canvas ─── */
.canvas {
  padding: 22px 26px 60px;
  min-width: 0;
}
.view-mount > section { animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ─── View headers ─── */
.view-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.view-head h1 { font-size: 24px; font-weight: 800; margin: 0; letter-spacing: -0.3px; }
.view-kicker { color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--ink);
  background: var(--white);
  font-weight: 600; font-size: 13.5px;
  box-shadow: var(--shadow-1);
  transition: transform 0.08s, background 0.12s;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--green);
  color: white;
  border-color: var(--green);
}
.btn.primary:hover { background: #357046; }
.btn.danger { color: #8E2C2C; border-color: var(--rose); }
.btn.danger:hover { background: rgba(226,116,116,0.10); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }

/* ─── Cards ─── */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 15px; font-weight: 800; margin: 0; }
.card-head .meta { color: var(--muted); font-size: 12px; }

/* ─── KPI tiles ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--white);
  border: 1px solid var(--ink);
  border-radius: 14px;
  padding: 14px 18px 16px;
  position: relative;
  box-shadow: var(--shadow-1);
}
.kpi::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--green) 0%, var(--green-3) 100%);
  border-top-left-radius: 14px; border-top-right-radius: 14px;
}
.kpi-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -0.3px; line-height: 1; direction: ltr; text-align: right; }
.kpi-meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.kpi.green .kpi-value { color: var(--green); }
.kpi.amber .kpi-value { color: #946A1F; }

/* ─── Charts row ─── */
.charts-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-bottom: 22px;
}
.chart-card { min-height: 320px; }
.chart-host {
  position: relative;
  width: 100%;
  /* avoid Chart.js infinite-resize: aspect-ratio + maintainAspectRatio:false */
  height: 280px;
}

/* ─── Tables ─── */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.table-toolbar {
  padding: 12px 16px;
  display: flex; gap: 10px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}
.table-toolbar input, .table-toolbar select {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data th, table.data td {
  padding: 10px 14px;
  text-align: right;
  border-bottom: 1px solid var(--line-2);
}
table.data th {
  background: var(--paper-2);
  font-weight: 700;
  color: var(--ink);
  font-size: 12.5px;
  letter-spacing: 0.2px;
  cursor: pointer; user-select: none;
  position: sticky; top: 0;
}
table.data tr:hover td { background: rgba(214,239,203,0.16); }
table.data td.num { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.2px;
  background: var(--paper-2); color: var(--muted);
  border: 1px solid var(--line);
}
.badge.green { background: var(--green-4); color: var(--green); border-color: var(--green-3); }
.badge.amber { background: rgba(228,184,113,0.18); color: #946A1F; border-color: var(--amber); }
.badge.rose  { background: rgba(226,116,116,0.10); color: #8E2C2C; border-color: var(--rose); }
.badge.indigo{ background: rgba(77,75,193,0.10); color: #4338CA; border-color: rgba(77,75,193,0.5); }

/* ─── Tree ─── */
.tree { font-size: 14px; }
.tree details { padding: 4px 0 4px 0; }
.tree summary {
  cursor: pointer; padding: 6px 8px; border-radius: 6px;
  list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary:hover { background: var(--paper-2); }
.tree summary .twig { color: var(--green); }
.tree details[open] > summary { font-weight: 700; }
.tree .branch { margin-right: 18px; border-right: 1px dashed var(--line); padding-right: 14px; }
.tree .leaf {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 8px; font-size: 13px; color: var(--ink-2);
}
.tree .leaf:hover { background: var(--paper-2); border-radius: 6px; }

/* ─── Connection cards ─── */
.conn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.conn-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--shadow-1);
}
.conn-card .conn-row1 { display: flex; align-items: center; gap: 10px; }
.conn-card .conn-kind { font-size: 11.5px; color: var(--muted); letter-spacing: 0.2px; text-transform: uppercase; direction: ltr; }
.conn-card .conn-name { font-weight: 800; font-size: 15px; }
.conn-card .conn-note { color: var(--muted); font-size: 13px; line-height: 1.6; }
.conn-card .conn-actions { display: flex; gap: 6px; margin-top: 8px; }
.add-card {
  border: 1.6px dashed var(--green);
  background: linear-gradient(180deg, rgba(214,239,203,0.3), rgba(214,239,203,0.05));
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  min-height: 130px;
  cursor: pointer;
  transition: background 0.12s;
}
.add-card:hover { background: rgba(214,239,203,0.5); }
.add-card .add-plus { font-size: 22px; color: var(--green); margin-bottom: 4px; }

/* ─── Settings ─── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.weight-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-2);
}
.weight-row:last-child { border-bottom: none; }
.weight-row label { flex: 1; font-weight: 600; font-size: 13.5px; }
.weight-row input[type="number"] {
  width: 76px; padding: 5px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--white); direction: ltr; text-align: center;
}
.weight-bar {
  flex: 1.5;
  height: 6px;
  border-radius: 999px;
  background: var(--paper-3);
  overflow: hidden;
}
.weight-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--green-3), var(--green)); border-radius: 999px; }

/* ─── Recommendations ─── */
.rec-list { display: flex; flex-direction: column; gap: 12px; }
.rec-card {
  background: var(--white); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px; box-shadow: var(--shadow-1);
}
.rec-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  margin-bottom: 8px;
}
.rec-name { font-weight: 800; font-size: 15px; }
.rec-meta { color: var(--muted); font-size: 12px; }
.rec-narrative { font-size: 14px; line-height: 1.75; }
.rec-foot { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.rec-question {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--paper-2);
  border-right: 3px solid var(--green);
  font-size: 13.5px;
  border-radius: 6px;
}

/* ─── Chat drawer ─── */
.chat-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: 460px;
  max-width: 100vw;
  background: var(--white);
  border-left: 1px solid var(--ink);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column;
  z-index: 70;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.chat-drawer[data-open="true"] { transform: translateX(0); }
.chat-drawer[hidden] { display: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}
.drawer-title { font-weight: 800; }
.drawer-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.drawer-head .ghost {
  background: transparent; border: 1px solid var(--line); width: 30px; height: 30px;
  border-radius: 8px;
}
.chat-log {
  flex: 1; overflow-y: auto;
  padding: 22px 18px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--paper);
}
.msg { display: flex; max-width: 100%; }
.msg .bubble {
  max-width: 90%;
  padding: 11px 14px;
  border-radius: 14px;
  line-height: 1.7;
  font-size: 14px;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: var(--shadow-1);
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--green); color: white; border: 1px solid var(--green); border-bottom-left-radius: 4px; }
.msg.agent .bubble { background: var(--white); color: var(--ink); border: 1px solid var(--line); border-bottom-right-radius: 4px; }
.msg.system .bubble {
  background: rgba(214,239,203,0.4); color: var(--muted);
  border: 1px dashed var(--green-3); font-size: 13.5px;
}
.msg .hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.msg.pending .bubble { color: var(--muted); font-style: italic; }
.markdown h1, .markdown h2, .markdown h3 { margin: 12px 0 4px; font-weight: 800; }
.markdown h1 { font-size: 17px; }
.markdown h2 { font-size: 15px; }
.markdown h3 { font-size: 14px; }
.markdown p { margin: 4px 0; }
.markdown code { background: var(--paper-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; direction: ltr; display: inline-block; }
.markdown pre { background: var(--paper-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; direction: ltr; font-size: 12.5px; }
.markdown blockquote { border-right: 3px solid var(--green-3); padding-right: 10px; color: var(--muted); }
.markdown ul, .markdown ol { padding-right: 22px; }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 14px 16px;
  border-top: 1px solid var(--line);
  background: var(--white);
}
.composer textarea {
  flex: 1; resize: none;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  max-height: 160px;
  outline: none;
}
.composer textarea:focus { border-color: var(--green); background: var(--white); }
.composer button {
  width: 38px; height: 38px;
  background: var(--green); color: white; border: 0; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.composer button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Login ─── */
.login-body {
  display: grid; place-items: center;
  min-height: 100vh;
  padding: 24px;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(183, 224, 168, 0.14), transparent 60%),
    radial-gradient(circle at 80% 90%, rgba(228, 184, 113, 0.08), transparent 55%);
}
.login-card {
  background: var(--white);
  border: 1px solid var(--ink);
  border-radius: 22px;
  padding: 28px 30px;
  width: 380px; max-width: 100%;
  box-shadow: var(--shadow-3);
}
.login-card .brand-stack { margin-bottom: 22px; }
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { font-size: 13px; color: var(--muted); }
.login-form input {
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px;
  outline: none;
}
.login-form input:focus { border-color: var(--green); }
.login-form button {
  background: var(--green); color: white; border: 0;
  padding: 11px; border-radius: 10px; font-weight: 700;
  margin-top: 10px;
}
.login-error { color: #8E2C2C; font-size: 13px; min-height: 18px; margin-top: 4px; }
.login-footer {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  margin-top: 16px; color: var(--muted); font-size: 12.5px;
}

/* ─── Mobile breakpoints ─── */
@media (max-width: 1080px) {
  .charts-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .topbar { padding: 0 12px; }
  .topbar-brand { display: none; }
  .hamburger { display: inline-flex; }
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; top: var(--topbar-h); right: -260px; bottom: 0;
    height: auto; width: 250px; z-index: 60;
    transition: right 0.22s ease;
    box-shadow: 0 0 30px rgba(0,0,0,0.18);
  }
  .rail[data-open="true"] { right: 0; }
  .canvas { padding: 14px 12px 44px; }
  .view-head h1 { font-size: 20px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chat-drawer { width: 100%; border-left: 0; }
  .kpi-value { font-size: 22px; }
}
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar-actions .chip-label { display: none; }
}
