:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e3e8f0;
  --text: #16233b;
  --muted: #6b7a90;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #12855a;
  --ok-soft: #e7f7ef;
  --danger: #c92a2a;
  --danger-soft: #fdeceb;
  --warn: #b26a00;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(22, 35, 59, .06);
}

* { box-sizing: border-box; }

/* attribute hidden باید بر هر display دستی اولویت داشته باشد */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.95;
  min-height: 100%;
}

h1, h2, h3, h4 { margin: 0 0 .35rem; line-height: 1.5; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.4rem; background: var(--panel);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.logo {
  height: 44px; max-width: 150px; object-fit: contain;
  background: #fff; border-radius: 10px; padding: 4px 6px;
  border: 1px solid var(--line);
}
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.brand-text .sub { margin: 0; font-size: .78rem; color: var(--muted); }

.status { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.status.busy .dot { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ------------------------------------------------------------------ layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem; max-width: 1180px; margin: 0 auto; padding: 1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { order: 2; }
}

.chat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  min-height: 76vh; max-height: 88vh; overflow: hidden;
}

.log { flex: 1; overflow-y: auto; padding: 1.1rem 1.2rem; display: flex;
  flex-direction: column; gap: .9rem; }
.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: #d6dde9; border-radius: 8px; }

.welcome { color: var(--muted); max-width: 62ch; }
.welcome h2 { color: var(--text); font-size: 1.05rem; }

/* ----------------------------------------------------------------- message */
.msg { display: flex; gap: .6rem; }
.msg .avatar {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 10px; overflow: hidden;
  display: grid; place-items: center; font-size: .78rem;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--line);
}
.msg .avatar img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.msg .bubble {
  flex: 1; min-width: 0; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 14px; padding: .75rem .95rem;
}
.msg.user .bubble { background: var(--accent-soft); border-color: #cfe0fb; }

/* -------------------------------------------------------------------- plan */
.plan {
  border: 1px dashed #bcd3ff; background: #f4f8ff; border-radius: 12px;
  padding: .6rem .8rem; margin-bottom: .6rem;
}
.plan h4 { font-size: .82rem; color: var(--accent); margin-bottom: .35rem; }
.plan ol { margin: 0; padding-inline-start: 1.2rem; }
.plan li { font-size: .84rem; }
.plan .criteria { font-size: .76rem; color: var(--muted); margin-top: .35rem; }
.plan .tool-tag {
  font-size: .7rem; padding: 0 .35rem; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent); margin-inline-start: .35rem;
}

/* ------------------------------------------------------------------- steps */
.steps { display: flex; flex-direction: column; gap: .45rem; margin-bottom: .6rem; }
.step {
  border: 1px solid var(--line); border-radius: 10px; padding: .45rem .6rem;
  background: #fff; font-size: .82rem;
}
.step-head { display: flex; align-items: center; gap: .45rem; }
.step .lat { margin-inline-start: auto; color: var(--muted); font-size: .72rem; }
.step .args { color: var(--muted); font-size: .74rem; margin-top: .2rem; word-break: break-all; }
.step .summary { color: #3d4c63; font-size: .76rem; margin-top: .2rem; }
.dot-mark {
  width: 9px; height: 9px; border-radius: 50%; background: var(--warn);
  box-shadow: 0 0 0 3px rgba(178, 106, 0, .15);
}
.step.ok .dot-mark { background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 133, 90, .15); }
.step.fail .dot-mark { background: var(--danger); box-shadow: 0 0 0 3px rgba(201, 42, 42, .15); }
.step.running .dot-mark { animation: pulse 1s infinite; }

/* ---------------------------------------------------------------- markdown */
.md { font-size: .93rem; }
.md h2 { font-size: 1rem; margin: .8rem 0 .3rem; color: #123a6b; }
.md h3 { font-size: .95rem; margin: .7rem 0 .3rem; color: #123a6b; }
.md p { margin: .35rem 0; }
.md ul, .md ol { margin: .3rem 0; padding-inline-start: 1.3rem; }
.md code {
  background: #f1f4f9; border: 1px solid var(--line); border-radius: 6px;
  padding: 0 .3rem; font-family: Consolas, monospace; font-size: .82em;
  direction: ltr; display: inline-block;
}
.md table { width: 100%; border-collapse: collapse; margin: .6rem 0; font-size: .85rem; }
.md th, .md td { border: 1px solid var(--line); padding: .35rem .5rem; text-align: right; }
.md th { background: #f2f6fd; font-weight: 600; }
.md strong { color: #0f2540; }

/* --------------------------------------------------------------- artifacts */
.artifacts { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.artifact {
  display: inline-flex; align-items: center; gap: .4rem; text-decoration: none;
  background: var(--ok-soft); border: 1px solid #bfe8d3; color: #0d6b48;
  border-radius: 10px; padding: .35rem .7rem; font-size: .82rem;
}
.artifact:hover { filter: brightness(.98); }

.meta { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.meta span {
  font-size: .73rem; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; padding: .15rem .55rem;
}

/* ------------------------------------------------------------------ outbox */
.outbox-item {
  border: 1px solid #f2d9a8; background: #fdf7ea; border-radius: 10px;
  padding: .55rem .65rem; margin-top: .5rem; font-size: .82rem;
}
.outbox-item .target { color: var(--muted); font-size: .74rem; }
.outbox-item .text { margin: .3rem 0; white-space: pre-wrap; }
.outbox-actions { display: flex; gap: .4rem; }
.btn-sm {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: .2rem .6rem; font-size: .76rem; cursor: pointer;
  font-family: inherit;
}
.btn-sm.primary { background: var(--ok-soft); border-color: #bfe8d3; color: #0d6b48; }

/* ---------------------------------------------------------------- composer */
.chips { display: flex; gap: .45rem; flex-wrap: wrap; padding: .5rem .9rem 0; }
.chip {
  border: 1px solid var(--line); background: var(--panel-2); color: #2b3b54;
  border-radius: 999px; padding: .3rem .75rem; font-size: .78rem; cursor: pointer;
  font-family: inherit;
}
.chip:hover { border-color: #bcd3ff; color: var(--accent); background: var(--accent-soft); }

.composer {
  display: flex; gap: .5rem; padding: .7rem .9rem .9rem;
  border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 46px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: .6rem .8rem; font-family: inherit; font-size: .9rem; line-height: 1.7;
}
.composer textarea:focus { outline: none; border-color: #bcd3ff; background: #fff; }
.composer button {
  border: none; border-radius: 12px; padding: 0 1.3rem; cursor: pointer;
  background: var(--accent); color: #fff; font-family: inherit;
  font-size: .9rem; font-weight: 600;
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }

/* -------------------------------------------------------------------- side */
.side { display: flex; flex-direction: column; gap: .8rem; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem .95rem; box-shadow: var(--shadow);
}
.card h2 { font-size: .86rem; color: #123a6b; }
.card ul { margin: .3rem 0 0; padding-inline-start: 1.1rem; }
.card li { font-size: .82rem; color: #2b3b54; }
.card.muted { background: var(--panel-2); }
.kv { margin-top: .4rem; font-size: .78rem; color: var(--muted); }
.kv div { display: flex; justify-content: space-between; gap: .5rem; padding: .12rem 0; }
.kv b { color: var(--text); }

.error-card, .blocked-card {
  border-radius: 10px; padding: .6rem .8rem; font-size: .83rem;
  border: 1px solid #f3c2c2; background: var(--danger-soft); color: #8f1d1d;
}
.typing { display: inline-flex; gap: .25rem; align-items: center; color: var(--muted);
  font-size: .8rem; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* --- کاربر واردشده / خروج --- */
.user-badge {
  font-size: .76rem; color: #33465f; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px; padding: .1rem .55rem;
}
.logout-btn {
  font-family: inherit; font-size: .76rem; cursor: pointer; color: var(--muted);
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  padding: .15rem .55rem;
}
.logout-btn:hover { color: var(--danger); border-color: #f3c2c2; background: var(--danger-soft); }
