:root {
  --bg: #0f1420; --panel: #171e2e; --panel2: #1e2740; --border: #2a3550;
  --text: #e8ecf5; --muted: #8b95ab; --accent: #4f7cff; --accent2: #3b5fd9;
  --green: #2ecc71; --danger: #e74c3c;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: Vazirmatn, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg); color: var(--text); direction: rtl;
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
code { background: var(--panel2); padding: 2px 6px; border-radius: 4px; }

/* login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px; width: 380px; text-align: center; display: flex; flex-direction: column; gap: 16px;
}
.login-card h1 { font-size: 1.2rem; }
.login-card input { padding: 12px; }

/* buttons & inputs */
.btn {
  border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  padding: 9px 18px; border-radius: 10px; cursor: pointer; font-family: inherit; font-size: 0.95rem;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 5px 12px; font-size: 0.82rem; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: wait; }
.input {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 14px; font-family: inherit; font-size: 0.95rem; width: 100%;
}
.input:focus, .btn:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; }

/* layout */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 12px 24px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab {
  border: none; background: transparent; color: var(--muted); padding: 8px 18px;
  border-radius: 10px; cursor: pointer; font-family: inherit; font-size: .95rem;
}
.tab.active { background: var(--panel2); color: var(--text); }
.tab-panel { display: none; padding: 24px; max-width: 1200px; margin: 0 auto; }
.tab-panel.active { display: block; }

/* chat */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100vh - 130px); }
.chat-side {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto;
}
.side-label { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.session-list { display: flex; flex-direction: column; gap: 4px; }
.session-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.session-item:hover { background: var(--panel2); }
.session-item.active { background: var(--panel2); border-color: var(--border); }
.session-title { font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-main {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-active-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--panel2);
}
.active-bar-left { display: flex; align-items: center; gap: 8px; }
.small-select { padding: 5px 10px; font-size: 0.8rem; max-width: 260px; }
.profile-panel {
  padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--panel2);
  max-height: 200px; overflow-y: auto;
}
.profile-panel h3 { font-size: .95rem; margin-bottom: 8px; }
.profile-field { font-size: 0.85rem; margin-bottom: 5px; line-height: 1.7; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.bubble {
  max-width: 75%; padding: 10px 16px; border-radius: 14px; line-height: 1.9;
  white-space: pre-wrap; word-break: break-word;
}
.bubble.user { align-self: flex-start; background: var(--accent2); border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-end; background: var(--panel2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.info { align-self: center; color: var(--muted); font-size: .85rem; background: none; }
.model-tag { margin-top: 6px; opacity: .7; }
.chat-input-row { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.chat-input-row .input { resize: none; }
#chat-status { padding: 0 16px 10px; }

/* products */
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.inline-form { display: flex; gap: 10px; align-items: center; }
.inline-form .input { width: 200px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.product-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px;
  display: flex; flex-direction: column; gap: 8px;
}
.product-card h3 { font-size: 1rem; }
.card-actions { display: flex; gap: 8px; margin-top: 8px; }

/* settings */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 12px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; }
.provider-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 8px;
  flex-wrap: wrap;
}
.provider-item.active { border-color: var(--green); }
.prov-info { display: flex; flex-direction: column; gap: 3px; }
.prov-actions { display: flex; gap: 6px; align-items: center; }
.badge {
  font-size: .75rem; padding: 2px 10px; border-radius: 20px;
  background: var(--panel2); color: var(--muted); width: fit-content;
}
.badge.green { background: rgba(46, 204, 113, .15); color: var(--green); }
.model-list { width: 100%; padding: 8px 4px 0; border-top: 1px dashed var(--border); }
.model-row { padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.model-row:hover { background: var(--panel2); }
.model-row.active { background: var(--panel2); }

@media (max-width: 800px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-main { height: 70vh; }
  .topbar { flex-wrap: wrap; }
}
