/* ============================================================
   Jira AI Helper — полированный тёмный UI
   Вдохновение: Claude.ai, Linear, Vercel
   ============================================================ */

:root {
  /* Базовые цвета */
  --bg:           #0a0c0f;
  --surface-0:    #0f1215;
  --surface-1:    #141820;
  --surface-2:    #1c2230;
  --surface-3:    #222b3a;
  --border:       rgba(255,255,255,0.07);
  --border-focus: rgba(79,140,255,0.5);

  /* Текст */
  --text-primary:   #f0f2f5;
  --text-secondary: #8c95a6;
  --text-muted:     #505a6a;

  /* Акцент */
  --accent:         #4f8cff;
  --accent-dark:    #3b77f0;
  --accent-glow:    rgba(79,140,255,0.15);

  /* Семантические */
  --error:     #f06060;
  --error-bg:  rgba(240,96,96,0.1);
  --warning:   #f5a623;
  --warning-bg:rgba(245,166,35,0.08);
  --success:   #5dcfa0;

  /* Сообщения */
  --msg-user:      rgba(79,140,255,0.08);
  --msg-assistant: transparent;
  --code-bg:       rgba(0,0,0,0.35);

  /* Sidebar */
  --sidebar-w: 248px;

  /* Переходы */
  --t-fast: 120ms ease;
  --t-med:  200ms ease;

  /* Радиус */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Ensure the HTML `hidden` attribute always hides elements, even when CSS sets display */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--t-fast);
}
a:hover { color: #79aeff; }

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

/* ============================================================
   ЭКРАН ЛОГИНА
   ============================================================ */
.screen { display: flex; height: 100vh; }

#login-screen {
  justify-content: center;
  align-items: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(79,140,255,0.07) 0%, transparent 70%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 36px 40px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.03),
              0 24px 48px rgba(0,0,0,0.5),
              0 4px 8px rgba(0,0,0,0.3);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4f8cff 0%, #7c5cfc 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.login-logo h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.5;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#login-form .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#login-form .field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

#login-form input,
#login-form select {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font-size: 14px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  outline: none;
  width: 100%;
}

#login-form input::placeholder { color: var(--text-muted); }

#login-form input:hover,
#login-form select:hover {
  border-color: rgba(255,255,255,0.12);
  background: var(--surface-3);
}

#login-form input:focus,
#login-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface-2);
}

#login-form .field-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

#login-form .field-hint a { color: var(--text-secondary); }
#login-form .field-hint a:hover { color: var(--accent); }

#login-btn {
  margin-top: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  letter-spacing: -0.01em;
}

#login-btn:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: 0 4px 12px rgba(79,140,255,0.3);
}

#login-btn:active:not(:disabled) { transform: scale(0.98); }
#login-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.login-error {
  padding: 10px 13px;
  background: var(--error-bg);
  border: 1px solid rgba(240,96,96,0.25);
  border-radius: var(--r-sm);
  color: var(--error);
  font-size: 13px;
}

.login-footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.6;
  text-align: center;
}

/* ============================================================
   CHAT LAYOUT
   ============================================================ */
#chat-screen {
  flex-direction: row;
  background: var(--bg);
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-0);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-new-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
  text-align: left;
}

.sidebar-new-btn:hover {
  background: var(--surface-3);
  border-color: rgba(255,255,255,0.12);
}

.sidebar-new-btn svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* Chat list */
.chat-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px;
}

.chat-list::-webkit-scrollbar { width: 4px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

.chat-list-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
  margin-bottom: 1px;
}

.chat-item:hover { background: var(--surface-2); }
.chat-item.active {
  background: var(--accent-glow);
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.chat-item-body {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.chat-item-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.chat-item.active .chat-item-title { font-weight: 500; color: #fff; }

.chat-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-del {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast), color var(--t-fast);
}

.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: var(--error); background: var(--error-bg); }

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.sidebar-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f8cff 0%, #7c5cfc 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.01em;
}

.sidebar-username {
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.sidebar-select {
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color var(--t-fast);
  width: 100%;
  outline: none;
}
.sidebar-select:hover { border-color: rgba(255,255,255,0.12); }
.sidebar-select:focus { border-color: var(--accent); }

.sidebar-logout {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
  width: 100%;
  text-align: center;
}
.sidebar-logout:hover {
  border-color: var(--error);
  color: var(--error);
  background: var(--error-bg);
}

/* ---- Main panel ---- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  background: var(--bg);
}

/* Topbar */
.topbar {
  flex-shrink: 0;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,12,15,0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.topbar-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  max-width: 520px;
  margin: auto;
  text-align: center;
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 20px;
}

.empty-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.suggestion-chip {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  display: flex;
  align-items: center;
  gap: 8px;
}

.suggestion-chip::before {
  content: "→";
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
  transition: color var(--t-fast);
}

.suggestion-chip:hover {
  background: var(--surface-2);
  border-color: rgba(255,255,255,0.12);
  color: var(--text-primary);
}
.suggestion-chip:hover::before { color: var(--accent); }

/* Message rows */
.msg-row {
  padding: 4px 0;
  display: flex;
  flex-direction: column;
}

.msg-row.user { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }

.msg-wrap {
  max-width: min(680px, 85%);
  padding: 0 32px;
  width: 100%;
}

.msg-row.user .msg-wrap { padding-left: 80px; }
.msg-row.assistant .msg-wrap { padding-right: 80px; }

.msg-bubble {
  display: inline-block;
  padding: 11px 15px;
  border-radius: var(--r-md);
  max-width: 100%;
  word-break: break-word;
  line-height: 1.65;
  font-size: 14px;
}

.msg-row.user .msg-bubble {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.07);
  color: var(--text-primary);
  border-bottom-right-radius: 3px;
}

.msg-row.assistant .msg-bubble {
  background: transparent;
  border: none;
  padding: 6px 0;
  width: 100%;
  display: block;
}

.msg-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 5px;
  padding: 0 2px;
}

/* Tool blocks */
.tool-row {
  display: flex;
  justify-content: center;
  padding: 3px 32px;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--warning-bg);
  border: 1px solid rgba(245,166,35,0.2);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--warning);
}

.tool-chip-ok {
  background: rgba(93,207,160,0.07);
  border-color: rgba(93,207,160,0.2);
  color: var(--success);
}

.tool-chip .tool-icon { font-size: 13px; }

/* Error chips */
.error-row {
  display: flex;
  justify-content: center;
  padding: 3px 32px;
}

.error-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--error-bg);
  border: 1px solid rgba(240,96,96,0.2);
  border-radius: 6px;
  padding: 7px 13px;
  font-size: 13px;
  color: var(--error);
  max-width: 560px;
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 8px 2px;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---- Markdown in assistant messages ---- */
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 16px 0 6px;
  font-weight: 600;
  line-height: 1.4;
  color: #fff;
}
.md h1 { font-size: 17px; }
.md h2 { font-size: 15.5px; }
.md h3 { font-size: 14.5px; }
.md h4 { font-size: 14px; }

.md ul, .md ol {
  padding-left: 22px;
  margin: 4px 0 10px;
}
.md li { margin-bottom: 3px; }

.md code {
  background: var(--code-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12.5px;
  font-family: "SF Mono", "Fira Code", Consolas, monospace;
  color: #e2c8ff;
}

.md pre {
  background: var(--code-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 8px 0 12px;
}

.md pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 12.5px;
  color: #d4f1c0;
}

.md a { color: var(--accent); }
.md a:hover { text-decoration: underline; }

.md blockquote {
  border-left: 3px solid rgba(255,255,255,0.15);
  margin: 8px 0;
  padding: 4px 14px;
  color: var(--text-secondary);
  font-style: italic;
}

.md table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 13px;
}

.md th {
  background: var(--surface-2);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 7px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.md td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  vertical-align: top;
}

.md tr:hover td { background: rgba(255,255,255,0.02); }

.md strong { font-weight: 600; color: var(--text-primary); }
.md em { color: var(--text-secondary); font-style: italic; }

/* ---- Composer ---- */
.composer {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px 4px 4px 16px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.composer-inner:focus-within {
  border-color: rgba(79,140,255,0.4);
  box-shadow: 0 0 0 3px rgba(79,140,255,0.08);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  padding: 8px 0;
  max-height: 180px;
  min-height: 38px;
}

#chat-input::placeholder { color: var(--text-muted); }

#send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), transform var(--t-fast);
  margin: 3px;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-dark);
}

#send-btn:active:not(:disabled) { transform: scale(0.93); }

#send-btn:disabled {
  background: var(--surface-3);
  cursor: not-allowed;
}

.send-icon {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.composer-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 680px) {
  .sidebar {
    width: 200px;
  }
}

@media (max-width: 540px) {
  #chat-screen {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-list {
    max-height: 18vh;
  }

  .main { height: auto; flex: 1; }
  .messages { padding: 16px 0; }
  .msg-row.user .msg-wrap { padding-left: 24px; }
  .msg-row.assistant .msg-wrap { padding-right: 24px; }
  .composer { padding: 12px 16px 16px; }
}
