/* OpenRouter Chat — dark theme */
:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --surface: #1e1e2e;
  --surface2: #2a2a3e;
  --border: #333355;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --code-bg: #0d1117;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --header-h: 52px;
  --panel-w: 480px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Vazirmatn", "Tahoma", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
a { color: #a78bfa; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.hint { color: var(--text-muted); font-size: 12px; margin: 4px 0 0; }
.hidden { display: none !important; }

/* ---------- Buttons & inputs ---------- */
button, .btn-link {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background .15s, border-color .15s;
  font-family: inherit;
}
button:hover:not(:disabled), .btn-link:hover { background: #34344d; border-color: #44446a; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary-btn { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.danger-btn { background: transparent; border-color: var(--danger); color: #fca5a5; }
.danger-btn:hover:not(:disabled) { background: rgba(239,68,68,.15); }
.icon-btn { padding: 3px 7px; font-size: 12px; background: transparent; border-color: transparent; color: var(--text-muted); }
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--surface2); border-color: var(--border); }
.full { width: 100%; justify-content: center; }

input[type=text], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }

.alert { padding: 9px 12px; border-radius: var(--radius); margin: 10px 0; font-size: 13px; }
.alert-error { background: #3b1220; border: 1px solid var(--danger); color: #fecaca; }
.alert-info { background: #13233f; border: 1px solid #3b82f6; color: #bfdbfe; }
.alert-success { background: #0f2e1d; border: 1px solid var(--success); color: #bbf7d0; }

/* ---------- Auth page ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background: radial-gradient(circle at 30% 20%, #2a1c55 0%, var(--bg) 55%); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px 28px; box-shadow: 0 10px 40px rgba(0,0,0,.5); text-align: center; }
.auth-card h1 { margin: 6px 0 2px; font-size: 22px; }
.auth-card form { text-align: left; margin-top: 18px; }
.auth-card label { display: block; margin: 12px 0 4px; color: #bbb; font-size: 13px; }
.auth-card .primary-btn { margin-top: 20px; padding: 10px; font-size: 15px; }
.auth-logo { font-size: 40px; }

/* ---------- Layout ---------- */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
#main-header {
  height: var(--header-h); flex: 0 0 var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: var(--bg2); border-bottom: 1px solid var(--border); gap: 10px;
}
.header-left, .header-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
#site-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#username-display { color: var(--text-muted); font-size: 13px; padding: 0 6px; }
#sidebar-toggle { display: none; }

#main-layout { flex: 1; display: flex; min-height: 0; }
#sidebar {
  width: 270px; flex: 0 0 270px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; transition: margin-left .2s;
}
#sidebar.collapsed { margin-left: -270px; }
#sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 12px; gap: 8px; }
#sidebar-header h3 { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
#conv-search { margin: 0 12px 8px; width: calc(100% - 24px); padding: 6px 10px; font-size: 13px; }
#conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.conv-item {
  padding: 8px 10px; border-radius: var(--radius); cursor: pointer; margin-bottom: 3px; border: 1px solid transparent;
  position: relative;
}
.conv-item:hover { background: var(--surface2); }
.conv-item.open { border-color: var(--accent); background: rgba(124,58,237,.12); }
.conv-item-title { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 22px; }
.conv-item-meta { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; gap: 6px; }
.conv-item-model { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.conv-item-preview { font-size: 12px; color: #9a9ab0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item-delete { position: absolute; top: 6px; right: 6px; display: none; padding: 1px 6px; font-size: 11px; }
.conv-item:hover .conv-item-delete { display: inline-flex; }
.conv-empty { color: var(--text-muted); font-size: 13px; padding: 12px; text-align: center; }

#chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------- Initial composer ---------- */
#composer-area { flex: 0 0 auto; padding: 12px 14px 0; }
#initial-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); max-width: 1100px; margin: 0 auto 12px; }
#initial-panel.collapsed { display: none; }
#initial-panel-toggle { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
#model-selector-area label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 6px; }
#model-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.model-chip {
  padding: 4px 10px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--border);
  font-size: 12px; cursor: pointer; user-select: none; font-family: ui-monospace, monospace;
}
.model-chip.selected { background: rgba(124,58,237,.25); border-color: var(--accent); color: #ddd6fe; }
.model-chip.selected::before { content: "✓ "; }
.model-chip-tools { display: inline-flex; gap: 4px; }
#composer-box textarea { min-height: 80px; max-height: 40vh; }
#composer-actions, .panel-composer-actions { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
#composer-actions select { width: auto; padding: 5px 8px; font-size: 12px; }
.spacer { flex: 1; }
#web-search-label, .ws-label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; color: #ccc; }

/* ---------- Attachment chips ---------- */
#attachment-chips, .attachment-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
#attachment-chips:empty, .attachment-chips:empty { display: none; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 4px 3px 8px; font-size: 12px; max-width: 260px;
}
.att-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.att-chip .att-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip .att-size { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.att-chip .att-remove { padding: 0 6px; font-size: 12px; background: transparent; border: 0; color: var(--text-muted); }
.att-chip .att-remove:hover { color: var(--danger); }
.att-chip.uploading { opacity: .6; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.msg-attachments img.att-preview { max-width: 220px; max-height: 180px; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.msg-attachments a.att-file { display: inline-flex; gap: 6px; align-items: center; padding: 4px 9px; background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; color: var(--text); text-decoration: none; }
.msg-attachments a.att-file:hover { border-color: var(--accent); }

/* ---------- Conversation panels ---------- */
#conversations-container {
  flex: 1; min-height: 0; display: flex; gap: 12px; padding: 0 14px 14px;
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity;
}
#conversations-container:empty::before {
  content: "Select models above and send a prompt, or open a conversation from the sidebar.";
  color: var(--text-muted); margin: 40px auto; font-size: 14px; text-align: center;
}
.conv-panel {
  flex: 1 0 var(--panel-w); max-width: 100%; min-width: min(var(--panel-w), 100%); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; min-height: 0;
  box-shadow: var(--shadow); scroll-snap-align: start; overflow: hidden;
}
#conversations-container.single .conv-panel { flex-basis: 100%; }
.conv-header { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.model-label {
  font-family: ui-monospace, monospace; font-size: 11px; background: rgba(124,58,237,.2); color: #ddd6fe;
  border: 1px solid rgba(124,58,237,.5); padding: 2px 8px; border-radius: 999px; white-space: nowrap; max-width: 45%;
  overflow: hidden; text-overflow: ellipsis;
}
.conv-title-input { flex: 1; min-width: 60px; background: transparent; border: 1px solid transparent; font-weight: 600; padding: 3px 6px; font-size: 13px; }
.conv-title-input:hover { border-color: var(--border); }
.conv-settings { padding: 10px; border-bottom: 1px solid var(--border); background: #191928; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.conv-settings label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.conv-settings input, .conv-settings select, .conv-settings textarea { font-size: 12px; padding: 5px 7px; }
.conv-settings .full-row { grid-column: 1 / -1; }
.conv-settings .settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; }
.conv-settings-bar { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--border); font-size: 12px; flex-wrap: wrap; }
.conv-settings-bar select, .conv-settings-bar input[type=number] { width: auto; padding: 3px 6px; font-size: 12px; }
.conv-settings-bar input[type=number] { width: 72px; }
.conv-settings-bar label { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); }

.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.message { border-radius: 10px; padding: 9px 12px; border: 1px solid var(--border); position: relative; max-width: 100%; }
.message.role-user { background: #232347; border-color: #35356a; }
.message.role-assistant { background: var(--surface2); }
.message.role-system { background: #2a2416; border-color: #5c4a1c; }
.message.stale { opacity: .55; }
.message.incomplete { border-style: dashed; border-color: var(--warning); }
.message.error-msg { background: #2c1420; border-color: var(--danger); }
.message.replacing { opacity: .3; pointer-events: none; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.msg-role { font-weight: 700; color: #c4b5fd; text-transform: uppercase; letter-spacing: .04em; }
.role-user .msg-role { color: #93c5fd; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); }
.badge.warn { color: var(--warning); border-color: var(--warning); }
.badge.stale { color: var(--text-muted); }
.badge.err { color: #fca5a5; border-color: var(--danger); }
.msg-content { word-wrap: break-word; overflow-wrap: anywhere; }
.msg-content.plain { white-space: pre-wrap; }
.message.folded .msg-content { max-height: 3.1em; overflow: hidden; position: relative; }
.message.folded .msg-content::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1.4em;
  background: linear-gradient(transparent, var(--surface2));
}
.message.role-user.folded .msg-content::after { background: linear-gradient(transparent, #232347); }
.message.folded .msg-attachments { display: none; }
.msg-footer { display: flex; align-items: center; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.msg-actions { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; opacity: .55; transition: opacity .15s; }
.message:hover .msg-actions, .message:focus-within .msg-actions { opacity: 1; }
.usage-badge { font-size: 11px; color: var(--text-muted); background: var(--bg2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 999px; font-family: ui-monospace, monospace; }
.error-text { color: #fca5a5; white-space: pre-wrap; }

/* Inline editor */
.msg-editor textarea { min-height: 90px; margin: 4px 0; }
.msg-editor .editor-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg-editor .editor-warning { color: var(--warning); font-size: 12px; }

/* Typing indicator */
.typing-indicator { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing-indicator span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite both; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.streaming-cursor::after { content: "▍"; animation: blink 1s infinite; color: var(--accent); margin-left: 1px; }

/* Sticky panel composer */
.panel-composer { position: sticky; bottom: 0; border-top: 1px solid var(--border); padding: 8px 10px; background: var(--surface); }
.panel-composer textarea { min-height: 52px; max-height: 30vh; font-size: 13px; }
.panel-composer-actions button { padding: 5px 10px; }
.stop-btn { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.stop-btn:hover:not(:disabled) { background: #dc2626 !important; }

/* ---------- Markdown ---------- */
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: .45em 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: .9em 0 .4em; line-height: 1.3; }
.markdown-body h1 { font-size: 1.4em; } .markdown-body h2 { font-size: 1.25em; } .markdown-body h3 { font-size: 1.1em; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin: .4em 0; }
.markdown-body li { margin: .15em 0; }
.markdown-body blockquote { border-left: 3px solid var(--accent); margin: .5em 0; padding: .2em .9em; color: #b8b8cc; background: rgba(124,58,237,.06); }
.markdown-body a { color: #a78bfa; }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.markdown-body table { border-collapse: collapse; margin: .6em 0; display: block; overflow-x: auto; max-width: 100%; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.markdown-body th { background: var(--bg2); }
.markdown-body img { max-width: 100%; }
.markdown-body :not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: .9em; border: 1px solid #222a36; }
.markdown-body mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

/* Code blocks */
.code-block { margin: .6em 0; border: 1px solid #232b38; border-radius: var(--radius); overflow: hidden; background: var(--code-bg); direction: ltr; text-align: left; }
.code-header { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: #161b22; border-bottom: 1px solid #232b38; font-size: 11px; }
.code-lang { color: var(--text-muted); font-family: ui-monospace, monospace; margin-right: auto; }
.code-header button { padding: 1px 8px; font-size: 11px; background: transparent; }
.code-pre { margin: 0; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; max-height: 600px; }
.code-pre code.hljs { background: transparent; padding: 0; }
.code-block.code-folded .code-pre { max-height: 4.6em; overflow: hidden; }

/* RTL support */
[dir="rtl"] { text-align: right; }
.msg-content[dir="rtl"] ul, .msg-content[dir="rtl"] ol { padding-left: 0; padding-right: 1.5em; }
.msg-content[dir="rtl"] blockquote { border-left: 0; border-right: 3px solid var(--accent); }
.msg-content[dir="rtl"] th, .msg-content[dir="rtl"] td { text-align: right; }
.msg-content[dir="rtl"] pre, .msg-content[dir="rtl"] code { direction: ltr; text-align: left; unicode-bidi: embed; }
textarea[dir="rtl"] { text-align: right; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,5,15,.7); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.modal-content.wide { max-width: 900px; }
.modal-content h2 { margin: 0 0 12px; font-size: 18px; }
.modal-content label { display: block; font-size: 13px; color: #bbb; margin: 10px 0 4px; }
.modal-content label.cb-label { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
#request-info-content { background: var(--code-bg); padding: 12px; border-radius: var(--radius); font-size: 12px; max-height: 65vh; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.image-viewer img { max-width: 92vw; max-height: 88vh; border-radius: 8px; }

/* Toasts */
#toast-container { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--surface2); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 9px 14px; border-radius: var(--radius); box-shadow: var(--shadow); font-size: 13px; max-width: 360px; animation: slidein .2s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Admin ---------- */
.admin-page { min-height: 100vh; }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.admin-section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 18px; }
.admin-section h2 { margin: 0 0 12px; font-size: 17px; }
.admin-section h3 { font-size: 14px; margin: 18px 0 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.admin-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.admin-table tr:hover td { background: rgba(255,255,255,.02); }
.admin-table .actions { display: flex; gap: 4px; flex-wrap: wrap; }
.admin-table .actions button, .admin-table .actions a { padding: 3px 8px; font-size: 12px; }
.admin-table select { width: auto; padding: 3px 6px; font-size: 12px; }
.status-pill { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.status-pill.on { background: rgba(34,197,94,.15); color: var(--success); }
.status-pill.off { background: rgba(239,68,68,.15); color: var(--danger); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 180px; }
.inline-form button { flex: 0 0 auto; }
.admin-row { display: flex; gap: 8px; margin: 10px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; margin-bottom: 10px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  :root { --panel-w: 88vw; }
  #sidebar-toggle { display: inline-flex; }
  #sidebar { position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 50; margin-left: -280px; box-shadow: 4px 0 20px rgba(0,0,0,.5); }
  #sidebar.mobile-open { margin-left: 0; }
  #sidebar.collapsed { margin-left: -280px; }
  .header-right button { padding: 5px 8px; font-size: 12px; }
  #username-display { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  #composer-area { padding: 8px 8px 0; }
  #conversations-container { padding: 0 8px 8px; }
  .header-right { gap: 4px; }
  #export-btn { display: none; }
  .msg-actions { opacity: 1; }
}

/* ==================================================================
 * v2.0 — Vazirmatn Persian typography
 * Local font files first, jsDelivr CDN as fallback.
 * ================================================================== */
@font-face {
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/Vazirmatn-Regular.woff2) format("woff2"),
       url(https://cdn.jsdelivr.net/npm/vazirmatn@33.0.3/fonts/webfonts/Vazirmatn-Regular.woff2) format("woff2");
}
@font-face {
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(fonts/Vazirmatn-Medium.woff2) format("woff2"),
       url(https://cdn.jsdelivr.net/npm/vazirmatn@33.0.3/fonts/webfonts/Vazirmatn-Medium.woff2) format("woff2");
}
@font-face {
  font-family: "Vazirmatn";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/Vazirmatn-Bold.woff2) format("woff2"),
       url(https://cdn.jsdelivr.net/npm/vazirmatn@33.0.3/fonts/webfonts/Vazirmatn-Bold.woff2) format("woff2");
}

body,
button, input, select, textarea, .btn-link {
  font-family: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, "Tahoma", sans-serif;
}

[dir="rtl"], .rtl-content, .rtl-text {
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  line-height: 1.85;
}
.rtl-content { direction: rtl; text-align: right; unicode-bidi: plaintext; }
.rtl-text { direction: rtl; unicode-bidi: isolate; }
.markdown-body[dir="rtl"] p, .markdown-body[dir="rtl"] li { line-height: 1.9; }

/* Code always stays monospace and left-to-right, even inside RTL text. */
code, pre, .code-block, pre code, kbd, samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace !important;
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: isolate;
}
[dir="rtl"] code { unicode-bidi: embed; }

/* ==================================================================
 * v2.0 — Billing / credit UI
 * ================================================================== */
.credit-display {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.credit-display:empty { display: none; }

.billing-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  border: 1px solid transparent; font-variant-numeric: tabular-nums;
}
.billing-badge.credit    { background: rgba(34,197,94,.14);  color: #4ade80; border-color: rgba(34,197,94,.35); }
.billing-badge.unlimited { background: rgba(124,58,237,.18); color: #c4b5fd; border-color: rgba(124,58,237,.45); }
.billing-badge.personal  { background: rgba(59,130,246,.16); color: #93c5fd; border-color: rgba(59,130,246,.4); }
.billing-badge.low       { background: rgba(245,158,11,.16); color: #fbbf24; border-color: rgba(245,158,11,.4); }
.billing-badge.zero      { background: rgba(239,68,68,.16);  color: #f87171; border-color: rgba(239,68,68,.4); }

.summary-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px; margin: 12px 0;
}
.summary-cards.compact { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.summary-card {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; min-width: 0;
}
.summary-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
.summary-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.summary-card.small-card .summary-value { font-size: 18px; }

.billing-tabs { display: flex; gap: 4px; margin: 10px 0 4px; border-bottom: 1px solid var(--border); }
.billing-tab {
  border: 1px solid transparent; border-bottom: none; border-radius: var(--radius) var(--radius) 0 0;
  background: transparent; padding: 6px 16px; margin-bottom: -1px; color: var(--text-muted);
}
.billing-tab:hover:not(:disabled) { background: var(--surface2); }
.billing-tab.active { background: var(--surface2); border-color: var(--border); color: var(--text); font-weight: 600; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.pagination button { padding: 4px 10px; font-size: 12px; }

.billing-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 10px; }
.billing-filters input { width: auto; flex: 1 1 160px; }
.billing-filters label { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: var(--text-muted); }
.billing-filters label input { flex: 0 1 auto; }

.billing-table td.num, .billing-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.billing-table td.wrap { white-space: normal; min-width: 180px; max-width: 360px; overflow-wrap: anywhere; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

/* Row action dropdown (works without JS via <details>). */
.row-actions { position: relative; display: inline-block; }
.row-actions > summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 3px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface2);
}
.row-actions > summary::-webkit-details-marker { display: none; }
.row-actions[open] > summary { border-color: var(--accent); }
.row-actions-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 50;
  min-width: 210px; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px;
}
.admin-table .row-actions-menu button, .admin-table .row-actions-menu a {
  text-align: left; width: 100%; padding: 6px 10px; font-size: 12px; border-color: transparent; background: transparent;
}
.admin-table .row-actions-menu button:hover:not(:disabled), .admin-table .row-actions-menu a:hover { background: var(--surface2); }
.admin-table .row-actions-menu .danger-btn { color: var(--danger); }
.row-actions-group { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 6px 10px 2px; }
.billing-table .actions { overflow: visible; }
.table-wrap:has(.row-actions[open]) { overflow: visible; }

#credit-modal .modal-content label.cb-label, #billing-mode-modal label.cb-label { align-items: flex-start; color: var(--text); }
@media (max-width: 720px) {
  .summary-value { font-size: 18px; }
  .row-actions-menu { right: auto; left: 0; }
}


/* ================================================================
   Artifacts patch — generated image download controls + artifact cards
   ================================================================ */

/* Image wrapper: keep image click-to-zoom working; buttons below */
.att-img-wrap {
  display: inline-block;
  vertical-align: top;
  margin: 4px 6px 4px 0;
}
.att-img-controls {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.att-img-controls .icon-btn {
  font-size: .78rem;
  padding: 2px 7px;
  text-decoration: none;
  background: var(--bg2, #16213e);
  border-radius: 4px;
  border: 1px solid var(--border, #333355);
  cursor: pointer;
  color: var(--text, #e0e0f0);
}
.att-img-controls .icon-btn:hover {
  border-color: var(--accent, #7c3aed);
  color: var(--text, #e0e0f0);
}

/* Artifact card */
.artifact-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin: 4px 0;
  background: var(--bg2, #16213e);
  border: 1px solid var(--border, #333355);
  border-radius: 6px;
  max-width: 420px;
}
.artifact-icon { font-size: 1.4rem; flex-shrink: 0; }
.artifact-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.artifact-name {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.artifact-size { font-size: .75rem; color: var(--muted, #888); }
.artifact-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.artifact-actions .icon-btn {
  font-size: .78rem;
  padding: 3px 8px;
  text-decoration: none;
  background: var(--bg2, #16213e);
  border-radius: 4px;
  border: 1px solid var(--border, #333355);
  cursor: pointer;
  color: var(--text, #e0e0f0);
  white-space: nowrap;
}
.artifact-actions .icon-btn:hover { border-color: var(--accent, #7c3aed); color: var(--text, #e0e0f0); }

/* Artifact mode toggle button */
.artmode-btn { font-size: 1rem; }
.artmode-btn.active {
  background: var(--accent, #4f46e5) !important;
  color: #fff !important;
  border-color: transparent !important;
}

/* Artifact viewer modal */
.artifact-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}
.artifact-modal-inner {
  background: var(--bg, #fff);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  width: min(90vw, 800px);
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.artifact-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #ddd);
  font-weight: 600;
  flex-shrink: 0;
}
.artifact-modal-body {
  overflow: auto;
  flex: 1;
  padding: 12px 16px;
}
.artifact-code {
  margin: 0;
  font-size: .82rem;
  white-space: pre-wrap;
  word-break: break-all;
  font-family: 'Courier New', Courier, monospace;
}
.artifact-filelist {
  margin: 0;
  padding-left: 1.2em;
  font-size: .9rem;
  line-height: 1.9;
}

/* ══════════════════════════════════════════════════════════════════
   Video-generation patch — additional styles
   ══════════════════════════════════════════════════════════════════ */

/* ── Generated-video player wrapper ─────────────────────────────── */
.att-video-wrap {
  display: block;
  margin: 6px 0;
  max-width: 100%;
}

.att-video-player {
  display: block;
  max-width: 100%;
  width: 640px;
  border-radius: 6px;
  border: 1px solid var(--border, #333355);
  background: #000;
}

/* Keep the controls row (shared .att-img-controls) tidy below the player */
.att-video-wrap .att-img-controls {
  margin-top: 5px;
}

/* ── Polling status line inside assistant bubble ─────────────────── */
.video-gen-status {
  font-size: .82rem;
  color: var(--muted, #888);
  margin: 4px 0 0;
}
