/* عینک — چشمِ قابل‌اعتمادِ شهر — vanilla CSS, RTL, no framework.
 * Chat-first shell (like ChatGPT): the chat IS the main view; entity
 * browsers live in the burger-menu drawer. */

:root {
  --bg: #212121;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --ink: #ececec;
  --muted: #9b9b9b;
  --primary: #10a37f;
  --primary-ink: #ffffff;
  --accent: #b45309;
  --border: #424242;
  --danger: #f87171;
  --radius: 12px;
  --user-bubble: #10a37f;
  --agent-bubble: #2f2f2f;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Vazirmatn, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.8;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Header --- */

.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.burger {
  background: transparent;
  border: none;
  color: var(--ink);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
}

.burger:hover {
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-size: 1.3rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--primary);
}

.view-title {
  color: var(--muted);
  font-size: 0.9rem;
  margin-right: auto;
  margin-left: 1rem;
}

/* --- Drawer (burger menu) --- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 85vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-title {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0.5rem 1rem;
  font-weight: 500;
}

.drawer-section {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 1rem 0.5rem 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.drawer-item {
  display: block;
  width: 100%;
  text-align: right;
  background: transparent;
  border: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.drawer-item:hover {
  background: var(--surface-2);
}

.drawer-item.active {
  background: var(--surface-2);
  color: var(--primary);
  font-weight: 600;
}

.drawer-footer {
  margin-top: auto;
  padding: 1rem 0.5rem 0;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* --- Views --- */

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* GUARD: the `hidden` attribute must actually hide — the flex display
   above overrides the UA's [hidden] { display: none }, which rendered
   the entity toolbar BELOW the chat and split the viewport 50/50
   (wire-proven 2026-11-07, owner screenshot). */
.view[hidden] {
  display: none !important;
}

.view-entity {
  overflow-y: auto;
  padding: 1.25rem;
}

/* --- Chat (ChatGPT-like) --- */

.view-chat {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem 0.75rem;
  /* Thin, subtle scrollbar — the default RTL scrollbar floated a heavy
     gray bar mid-screen (owner screenshot 2026-11-07). */
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 999px;
}

.chat-msg {
  display: flex;
}

.chat-user {
  justify-content: flex-end;
}

.chat-agent {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.7rem 1.1rem;
  border-radius: 18px;
  font-size: 0.95rem;
  white-space: normal;
  word-break: break-word;
}

.chat-user .chat-bubble {
  background: var(--user-bubble);
  color: var(--primary-ink);
  border-bottom-left-radius: 6px;
}

.chat-agent .chat-bubble {
  background: var(--agent-bubble);
  border: 1px solid var(--border);
  border-bottom-right-radius: 6px;
}

.chat-note {
  color: var(--danger);
  font-size: 0.85rem;
}

.chat-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 0.9rem 1.2rem;
}

.chat-typing .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}

.chat-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.chat-step {
  align-self: flex-start;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.85rem;
  margin-right: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chat-step.pending {
  color: var(--ink);
  border-style: solid;
  border-color: var(--primary);
}

.chat-step.done {
  color: var(--muted);
}

.chat-step .spin {
  width: 10px;
  height: 10px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  display: inline-block;
  animation: rotate 0.8s linear infinite;
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

/* Markdown inside the agent bubble */
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 {
  margin: 0.6rem 0 0.3rem;
  line-height: 1.5;
}

.chat-bubble h1 { font-size: 1.1rem; }
.chat-bubble h2 { font-size: 1.05rem; }
.chat-bubble h3 { font-size: 1rem; }

.chat-bubble p {
  margin: 0.35rem 0;
}

.chat-bubble ul, .chat-bubble ol {
  margin: 0.35rem 0;
  padding-right: 1.4rem;
}

.chat-bubble table {
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.85rem;
  width: 100%;
}

.chat-bubble th, .chat-bubble td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  text-align: right;
}

.chat-bubble th {
  background: var(--surface-2);
}

.chat-bubble code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.85em;
  direction: ltr;
  display: inline-block;
}

.chat-bubble pre {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}

.chat-bubble pre code {
  background: transparent;
  padding: 0;
}

.chat-bubble blockquote {
  border-right: 3px solid var(--primary);
  margin: 0.5rem 0;
  padding-right: 0.8rem;
  color: var(--muted);
}

.chat-bubble a {
  color: var(--primary);
}

/* --- Chat form --- */

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0 1rem;
  flex-shrink: 0;
}

.chat-form input {
  flex: 1;
  padding: 0.8rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}

.chat-form input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.chat-form input:disabled {
  opacity: 0.6;
}

/* --- Buttons --- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.5rem 1.1rem;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.15s ease;
}

.btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}

.btn-primary:hover {
  color: var(--primary-ink);
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

/* --- Entity browser --- */

.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 12rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}

.toolbar input[type="search"]:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.count-info {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.card {
  text-align: right;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  font: inherit;
  color: inherit;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.meta-item {
  color: var(--muted);
  font-size: 0.8rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.badge-active {
  background: rgba(16, 163, 127, 0.15);
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.3);
}

.badge-archived {
  background: rgba(248, 113, 113, 0.12);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
}

.badge-good {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border-color: rgba(96, 165, 250, 0.3);
}

.badge-service {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
}

.empty,
.loading {
  color: var(--muted);
  text-align: center;
  padding: 2rem;
  grid-column: 1 / -1;
}

/* --- Modals --- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow, 0 4px 16px rgba(0, 0, 0, 0.4));
  padding: 1.5rem;
  max-width: 560px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal h2 {
  margin: 0 0 1rem;
  color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-start;
  padding: 0;
  margin: 1rem 0 0;
}

.detail-list {
  margin: 0;
}

.detail-list dt {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.detail-list dd {
  margin: 0.1rem 0 0;
  white-space: pre-wrap;
}

#create-form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#create-form input,
#create-form select,
#create-form textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  background: var(--bg);
}

#create-form input:focus,
#create-form select:focus,
#create-form textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* --- Errors --- */

.error {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
