/* super-agent-ui.css — Stage 40-1c UI Polish & Desktop Layout */
/* Mobile-first, dark theme, no horizontal overflow */

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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2128;
  --bg-drawer: #161b22;
  --bg-input: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  --accent-purple: #bc8cff;
  --badge-ok-bg: #1a3a2a;
  --badge-ok-text: #3fb950;
  --badge-disabled-bg: #2a1a1a;
  --badge-disabled-text: #f85149;
  --badge-manual-bg: #2a2a1a;
  --badge-manual-text: #d29922;
  --badge-info-bg: #1a2a3a;
  --badge-info-text: #58a6ff;
  --header-height: 56px;
  --banner-height: 36px;
  --drawer-width: 280px;
  --content-max-width: 880px;
  --radius: 10px;
  --radius-sm: 6px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  overflow-x: hidden;
  min-height: 100dvh;
  line-height: 1.5;
}

/* ── Drawer Overlay ──────────────────────────────────────────────────── */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
}
.drawer-overlay.open {
  display: block;
}

/* ── Side Drawer ─────────────────────────────────────────────────────── */
.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--drawer-width);
  height: 100dvh;
  background: var(--bg-drawer);
  border-right: 1px solid var(--border);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.side-drawer.open {
  transform: translateX(0);
  box-shadow: 4px 0 24px rgba(0,0,0,0.5);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.drawer-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}
.drawer-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.drawer-nav {
  list-style: none;
  padding: 8px 0;
  flex: 1;
}
.drawer-nav li {
  padding: 2px 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}
.nav-item.active {
  background: rgba(88,166,255,0.12);
  color: var(--accent);
  font-weight: 500;
}

/* External nav link (Главное меню) */
a.nav-item.nav-external {
  text-decoration: none;
  color: var(--text-secondary);
}
a.nav-item.nav-external:hover {
  background: var(--bg-card);
  color: var(--accent);
}
.nav-icon {
  font-size: 1.1rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.drawer-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-footer-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-top: 6px;
}

.drawer-footer-main-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(88,166,255,0.08);
  border: 1px solid rgba(88,166,255,0.2);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  margin-bottom: 8px;
}
.drawer-footer-main-link:hover {
  background: rgba(88,166,255,0.15);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ── App Shell ───────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ── App Header ──────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background 0.15s;
}
.hamburger-btn:hover {
  background: var(--bg-card);
}
.hamburger-btn span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
}

.header-title-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Safety Banner ───────────────────────────────────────────────────── */
.safety-banner {
  background: #1a1200;
  border-bottom: 1px solid #3a2800;
  color: #d29922;
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  padding: 0 16px;
  height: var(--banner-height);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Sections ────────────────────────────────────────────────────────── */
.app-section {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}
.app-section.active {
  display: flex;
}

/* ── Chat Shell ──────────────────────────────────────────────────────── */
.chat-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Messages ────────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 100%;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 10px 14px;
  max-width: calc(100% - 50px);
  word-break: break-word;
}

.system-message .message-bubble {
  background: #1a1200;
  border-color: #3a2800;
}

.message-sender {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.message-text {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.55;
}

/* ── Chat Input Area ─────────────────────────────────────────────────── */
.chat-input-area {
  padding: 10px 16px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-shell {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-family: inherit;
  min-width: 0;
}
.chat-input::placeholder {
  color: var(--text-muted);
}
.chat-input:disabled {
  cursor: not-allowed;
}

.chat-send-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: not-allowed;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

.chat-input-note {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
}

/* ── Back-to-Chat Bar ───────────────────────────────────────────────── */
.section-back-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-to-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 14px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.back-to-chat-btn:hover {
  background: rgba(88,166,255,0.1);
  border-color: var(--accent);
  color: var(--text-primary);
}
.back-to-chat-btn:active {
  background: rgba(88,166,255,0.2);
}

/* ── Section Content (non-chat) ──────────────────────────────────────── */
.section-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 24px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── Status List ─────────────────────────────────────────────────────── */
.status-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  gap: 8px;
  margin-bottom: 2px;
}

.status-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
}

.status-value {
  font-size: 0.82rem;
  color: var(--text-primary);
  font-weight: 500;
  text-align: right;
  max-width: 55%;
  word-break: break-word;
}

/* ── Badges ──────────────────────────────────────────────────────────── */
.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-ok { background: var(--badge-ok-bg); color: var(--badge-ok-text); }
.badge-disabled { background: var(--badge-disabled-bg); color: var(--badge-disabled-text); }
.badge-manual { background: var(--badge-manual-bg); color: var(--badge-manual-text); }
.badge-info { background: var(--badge-info-bg); color: var(--badge-info-text); }

/* ── Budget Section ──────────────────────────────────────────────────── */
.budget-source-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--badge-manual-bg);
  color: var(--badge-manual-text);
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}
.budget-note {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-orange);
}

/* ── Action Buttons ──────────────────────────────────────────────────── */
.action-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  text-align: center;
}
.disabled-btn {
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ── Future Features ─────────────────────────────────────────────────── */
.future-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.future-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
}
.future-icon {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}
.future-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.future-name {
  font-size: 0.88rem;
  color: var(--text-primary);
  font-weight: 500;
}
.future-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  display: inline-block;
  width: fit-content;
}
.future-soon { background: #1a3a2a; color: #3fb950; }
.future-approval { background: #1a2a3a; color: #58a6ff; }
.future-later { background: #2a2a2a; color: #8b949e; }
.future-stage { background: #2a1a2a; color: #bc8cff; }
.future-url { background: #1a1a2a; color: #58a6ff; font-size: 0.65rem; }
.future-url a { color: inherit; text-decoration: none; }
.future-url a:hover { text-decoration: underline; }

/* ── Technical Details ───────────────────────────────────────────────── */
.tech-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tech-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.tech-row:last-child { border-bottom: none; }
.tech-key {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 155px;
  flex-shrink: 0;
  padding-top: 1px;
}
.tech-val {
  font-size: 0.75rem;
  color: var(--text-primary);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  word-break: break-all;
}
.tech-false { color: var(--accent-red); }
.tech-val a { color: var(--accent); text-decoration: none; }
.tech-val a:hover { text-decoration: underline; }

/* ── Scrollbar ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Desktop Layout ──────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .header-title { font-size: 1.05rem; }
  .message-bubble { max-width: 70%; }

  /* Center message list on desktop */
  .message-list {
    align-items: center;
  }
  .message-list > .message {
    width: 100%;
    max-width: var(--content-max-width);
  }

  /* Chat input constrained to content width */
  .chat-input-area {
    padding: 10px 0 12px;
  }
  .chat-input-area > .chat-input-shell,
  .chat-input-area > .chat-input-note {
    max-width: var(--content-max-width);
    margin-left: auto;
    margin-right: auto;
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Section content constrained */
  .section-content {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 24px 20px 32px;
    width: 100%;
  }

  /* Back bar constrained */
  .section-back-bar {
    padding: 10px 0;
  }
  .section-back-bar > .back-to-chat-btn {
    margin-left: calc(50% - var(--content-max-width) / 2);
  }

  .tech-key { min-width: 220px; }
}

@media (min-width: 1024px) {
  .side-drawer { width: 300px; }
  :root { --content-max-width: 960px; }
}
