/* Aither Portal Styles — CB-WEBUI-01 */
:root {
  --bg: #0a0a0f;
  --bg-card: #13131a;
  --bg-card-hover: #1a1a24;
  --bg-input: #0d0d14;
  --border: #1f1f2e;
  --border-focus: #4f46e5;
  --text: #e4e4ec;
  --text-muted: #8888a0;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; line-height: 1.5;
}

/* Navigation */
.nav {
  display: flex; align-items: center;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 0 16px; height: 48px; position: sticky; top: 0; z-index: 100;
  gap: 8px;
}
.nav-brand { font-size: 18px; font-weight: 700; color: var(--primary); flex-shrink: 0; }
.nav-links {
  display: flex; gap: 2px; overflow-x: auto; flex: 1;
  scrollbar-width: none; -ms-overflow-style: none;
}
.nav-links::-webkit-scrollbar { display: none; }
.nav-link {
  color: var(--text-muted); text-decoration: none; padding: 6px 10px;
  border-radius: var(--radius); font-size: 12px; font-weight: 500;
  transition: all 0.15s; white-space: nowrap; flex-shrink: 0;
}
.nav-link:hover { color: var(--text); background: var(--bg-card-hover); }
.nav-link.active { color: #fff; background: var(--primary); }
.nav-user { display: flex; align-items: center; gap: 10px; }
.nav-username { font-weight: 500; font-size: 13px; }
.nav-role-badge {
  font-size: 10px; padding: 3px 8px; border-radius: 20px;
  background: rgba(99,102,241,0.15); color: var(--primary);
  font-weight: 600; text-transform: uppercase;
}
.zone-badge {
  font-size: 10px; padding: 3px 10px; border-radius: 20px;
  font-weight: 600; text-transform: uppercase;
}
.zone-internet { background: rgba(34,197,94,0.15); color: var(--success); }
.zone-test { background: rgba(245,158,11,0.15); color: var(--warning); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius); border: none;
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.15s; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 500; color: var(--text-muted); }
.form-input, textarea, select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text); font-size: 13px; font-family: inherit;
  transition: border 0.15s;
}
.form-input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--border-focus);
}
textarea { resize: vertical; min-height: 60px; }

/* Pages */
.page { display: none; padding: 24px; }
.page.active { display: block; }
.container { max-width: 960px; margin: 0 auto; }

/* Auth card */
.auth-card {
  max-width: 400px; margin: 60px auto; background: var(--bg-card);
  border-radius: 12px; padding: 32px; border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.auth-header { text-align: center; margin-bottom: 24px; }
.auth-header h1 { font-size: 28px; color: var(--primary); margin-bottom: 4px; }
.auth-footer { text-align: center; margin-top: 16px; }

/* Cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-title { font-weight: 600; margin-bottom: 12px; font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.card-body p { margin-bottom: 6px; font-size: 13px; }
.card-body a { color: var(--primary); text-decoration: none; }
.card-body a:hover { text-decoration: underline; }

/* Tier cards */
.tier-card {
  cursor: pointer; transition: all 0.2s;
}
.tier-card:hover {
  border-color: var(--primary); transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(99,102,241,0.2);
}
.tier-card.active {
  border-color: var(--primary) !important;
  box-shadow: 0 0 20px rgba(99,102,241,0.35), inset 0 0 0 1px var(--primary) !important;
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(99,102,241,0.02)) !important;
  position: relative;
}
.tier-card.active::after {
  content: '✓ ТЕКУЩИЙ';
  position: absolute;
  top: 8px; right: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  letter-spacing: 0.5px;
}

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.alert-danger { background: rgba(239,68,68,0.1); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-success { background: rgba(34,197,94,0.1); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.alert-info { background: rgba(59,130,246,0.1); color: var(--info); border: 1px solid rgba(59,130,246,0.2); }
.alert-warning { background: rgba(245,158,11,0.1); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }
.data-table th { text-align: left; padding: 10px 12px; background: var(--bg-card); color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.badge-enabled { color: var(--success); font-weight: 500; }
.badge-disabled { color: var(--warning); font-weight: 500; }
.badge-revoked { color: var(--danger); font-weight: 500; }

/* Chat layout — sidebar + main */
.chat-layout {
  display: flex; height: calc(100vh - 80px);
  max-width: 1100px; margin: 0 auto; gap: 0;
}
.chat-list-panel {
  width: 230px; min-width: 200px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg-card); border-right: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
}
.chat-list {
  flex: 1; overflow-y: auto; padding: 4px;
}
.chat-list-item {
  position: relative;
  padding: 10px 12px; margin: 2px 0;
  border-radius: 6px; cursor: pointer;
  transition: background 0.15s; border: 1px solid transparent;
}
.chat-list-item:hover { background: var(--bg-card-hover); border-color: var(--border); }
.chat-list-item.active {
  background: rgba(99,102,241,0.12); border-color: var(--primary);
}
.chat-list-title {
  font-size: 12px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-right: 18px; line-height: 1.3;
}
.chat-list-item.active .chat-list-title { color: var(--primary); }
.chat-list-meta {
  font-size: 10px; color: var(--text-muted); margin-top: 3px;
}
.btn-chat-delete {
  position: absolute; top: 8px; right: 8px;
  width: 18px; height: 18px; border: none; background: transparent;
  color: var(--text-muted); font-size: 16px; cursor: pointer;
  line-height: 1; padding: 0; border-radius: 3px;
  display: none; align-items: center; justify-content: center;
}
.chat-list-item:hover .btn-chat-delete { display: flex; }
.btn-chat-delete:hover { color: var(--danger); background: rgba(239,68,68,0.15); }
.chat-list-footer {
  padding: 8px 10px; border-top: 1px solid var(--border);
  display: flex; gap: 6px; flex-wrap: wrap;
}
.chat-list-footer .token-counter {
  font-size: 10px; padding: 3px 8px; border-radius: 20px;
  background: rgba(99,102,241,0.1); color: var(--primary); font-weight: 500;
  white-space: nowrap;
}
.btn-new-chat {
  margin: 8px; width: auto;
  font-size: 12px; padding: 8px 14px;
  border-radius: 6px;
}
.chat-list-empty {
  padding: 20px 12px; text-align: center; font-size: 11px;
}

.chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; padding: 0 16px;
}
/* RAG search bar — above messages, full width */
.rag-search-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.rag-search-bar input {
  font-size: 12px; padding: 8px 12px;
  min-width: 250px;
}
.rag-search-bar button {
  flex-shrink: 0;
}
.rag-result-inline {
  width: 100%;
  font-size: 11px; padding: 6px 10px; margin: 4px 0;
  background: rgba(245,158,11,0.08); border-left: 2px solid var(--warning);
  border-radius: 4px; max-height: 100px; overflow-y: auto;
}
.chat-controls {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chat-controls select { width: auto; min-width: 180px; }
.chat-label {
  text-align: center; padding: 6px 8px; font-size: 11px;
  color: var(--text-muted); background: rgba(99,102,241,0.05);
  border-radius: 6px; margin-bottom: 4px;
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 0;
  display: flex; flex-direction: column; gap: 12px;
}
.chat-msg {
  max-width: 80%; padding: 10px 14px; border-radius: 12px;
  font-size: 13px; line-height: 1.5; white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg.system { align-self: center; background: rgba(245,158,11,0.1); color: var(--warning); font-size: 11px; padding: 6px 12px; border-radius: 20px; max-width: 90%; }
.chat-msg.error { align-self: center; background: rgba(239,68,68,0.1); color: var(--danger); font-size: 12px; }
.chat-msg .msg-meta { font-size: 10px; color: var(--text-muted); margin-bottom: 4px; }
.chat-msg .msg-actions { margin-top: 6px; display: flex; gap: 6px; }
.chat-input-area { display: flex; gap: 8px; padding: 12px 0; border-top: 1px solid var(--border); }
.chat-textarea {
  flex: 1; max-width: 600px; min-height: 44px;
}
.chat-input-area .btn { align-self: flex-end; }

/* Code blocks in chat — VS Code Dark+ theme */
.code-block {
  margin: 10px 0; border-radius: 8px; overflow: hidden;
  border: 1px solid #3c3c3c; background: #1e1e1e;
}
.code-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 12px; background: #252526;
  border-bottom: 1px solid #3c3c3c;
}
.code-lang {
  font-size: 10px; color: #808080;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.btn-copy-code {
  font-size: 10px !important; padding: 2px 8px !important;
  background: rgba(86,156,214,0.12) !important; color: #569cd6 !important;
  border: 1px solid rgba(86,156,214,0.25) !important;
  border-radius: 4px !important; cursor: pointer;
  transition: all 0.15s;
}
.btn-copy-code:hover { background: rgba(86,156,214,0.25) !important; }
.code-block pre {
  margin: 0; padding: 14px; overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px; line-height: 1.6; color: #d4d4d4;
  tab-size: 4;
}
.code-block code { background: none; padding: 0; font-size: inherit; }
/* VS Code Dark+ syntax colors */
.syn-keyword   { color: #569cd6; font-weight: 400; }  /* blue — def, class, if */
.syn-string    { color: #ce9178; }                     /* orange — "hello" */
.syn-comment   { color: #6a9955; font-style: italic; } /* green — # comment */
.syn-number    { color: #b5cea8; }                     /* light green — 42 */
.syn-builtin   { color: #dcdcaa; }                     /* yellow — print, len */
.syn-function  { color: #dcdcaa; }                     /* yellow — func() */
.syn-decorator { color: #dcdcaa; }                     /* yellow — @decorator */

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 200; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; max-width: 700px; width: 90%;
  max-height: 80vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 16px; color: var(--primary); }

/* Copy field */
.copy-field { display: flex; gap: 8px; margin: 12px 0; }
.copy-field input { flex: 1; font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* Loading */
.loading-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 300; align-items: center; justify-content: center;
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Info rows */
.info-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.info-label { color: var(--text-muted); font-size: 12px; }
.info-value { font-size: 13px; font-weight: 500; }
.status-indicator { font-weight: 600; }
.status-indicator.ok { color: var(--success); }
.status-indicator.warning { color: var(--warning); }
.status-indicator.error { color: var(--danger); }

/* Text */
.text-muted { color: var(--text-muted); font-size: 12px; }
h1 { font-size: 24px; font-weight: 700; margin-bottom: 16px; }
h2 { font-size: 20px; font-weight: 600; margin-bottom: 12px; color: var(--primary); }
code {
  background: var(--bg-input); padding: 2px 6px; border-radius: 4px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
}

/* Responsive */
@media (max-width: 768px) {
  .nav { height: auto; padding: 10px; }
  .nav-links { order: 3; width: 100%; justify-content: center; }
  .chat-msg { max-width: 95%; }
  .cards-grid { grid-template-columns: 1fr; }
  .chat-layout { flex-direction: column; }
  .chat-list-panel { width: 100%; min-width: 0; max-height: 120px; border-right: none; border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; }
  .chat-main { padding: 0; }
  .chat-textarea { max-width: 100%; }
  .rag-search-bar { flex-direction: column; }
  .rag-search-bar input { min-width: 100%; }
}

/* ── OAuth Buttons ─────────────────────────────────────────── */
.oauth-section { margin-top: 16px; }
.oauth-divider {
  display: flex; align-items: center; margin: 12px 0;
  color: var(--text-muted); font-size: 11px;
}
.oauth-divider::before, .oauth-divider::after {
  content: ''; flex: 1; border-bottom: 1px solid var(--border-color);
}
.oauth-divider span { padding: 0 12px; }
.oauth-buttons {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.btn-oauth {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border-color); background: var(--bg-input);
  color: var(--text); transition: all 0.2s;
}
.btn-oauth:hover { border-color: var(--accent); background: rgba(124, 58, 237, 0.1); }
.oauth-icon { font-weight: 700; font-size: 14px; }
.btn-oauth-github .oauth-icon { color: #f0f6fc; }
.btn-oauth-google .oauth-icon { color: #4285f4; }
.btn-oauth-yandex .oauth-icon { color: #fc3f1d; }
.btn-oauth-ldap .oauth-icon { color: #f59e0b; }

/* ── Registration ───────────────────────────────────────────── */
.code-input {
  text-align: center; font-size: 24px !important;
  letter-spacing: 12px; font-family: 'JetBrains Mono', monospace;
  padding: 12px !important;
}
.reg-timer {
  text-align: center; font-size: 14px; color: var(--warning);
  margin-bottom: 12px; font-weight: 500;
}