/*
Author: Trịnh Thiên Quang
SatiBot AWS Agent Console - Codex-inspired sleek dark theme.
*/

:root {
  --bg-main: #212121;
  --bg-sidebar: #171717;
  --bg-composer: #2f2f2f;
  --bg-hover: #262626;
  --bg-active: #2f2f2f;
  --bg-card: #262626;
  --bg-code: #141414;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-btn: #383838;

  --text-main: #ececec;
  --text-soft: #d1d5db;
  --text-muted: #8e8e8e;
  --text-faint: #636363;

  --accent-blue: #38bdf8;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", SFMono-Regular, Consolas, Menlo, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Custom sleek dark scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.35);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

html, body {
  height: 100%;
  background: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

/* App Layout: 2 Columns (Sidebar Left, Chat Main Right) */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: var(--bg-main);
}

/* ====================================================
   LEFT SIDEBAR 
   ==================================================== */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 12px 10px 14px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
  user-select: none;
  transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1), padding 0.22s ease, border-color 0.22s ease;
  overflow: hidden;
  white-space: nowrap;
}

/* Sidebar Collapsed into Slim 56px Rail */
.sidebar.collapsed {
  width: 56px !important;
  padding: 12px 8px 14px !important;
}

.sidebar.collapsed .brand-title,
.sidebar.collapsed #sidebarToggleBtn,
.sidebar.collapsed .btn-text,
.sidebar.collapsed .recent-section,
.sidebar.collapsed .user-info {
  display: none !important;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 2px 0 14px;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
}

.sidebar.collapsed .new-chat-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.sidebar.collapsed .sidebar-user {
  justify-content: center;
  padding: 10px 0 4px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.brand-logo-btn,
.brand-lightning-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #ffffff;
  border: 0;
  font-weight: 800;
  font-family: var(--font-sans);
  display: grid;
  place-items: center;
  font-size: 15px;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.brand-logo-btn:hover,
.brand-lightning-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.45);
}

.sidebar.collapsed .brand-logo-btn,
.sidebar.collapsed .brand-lightning-btn {
  width: 36px;
  height: 36px;
  font-size: 17px;
}

.icon-action-btn {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.mobile-only {
  display: none;
}

/* New Chat Button */
.new-chat-btn {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-btn);
  border-radius: 10px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 16px;
  transition: all 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--bg-hover);
  border-color: #4a4a4a;
}

/* Recent Sessions Section */
.recent-section {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}

.recent-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 10px 8px;
  letter-spacing: 0.05em;
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.empty-recent {
  font-size: 12.5px;
  color: var(--text-faint);
  padding: 8px 10px;
}

.recent-item {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  background: transparent;
  border: 0;
  text-align: left;
  transition: all 0.12s ease;
  position: relative;
  padding-right: 24px;
}

.recent-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.recent-item.active {
  background: rgba(255, 255, 255, 0.075);
  color: var(--text-main);
  font-weight: 500;
}

.recent-item.active::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8b8b8b;
  transform: translateY(-50%);
}

.restored-url-link {
  display: block;
  width: fit-content;
  max-width: 100%;
  color: var(--accent-blue);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar User Footer (Symbolic AWS Profile) */
.sidebar-user {
  margin-top: auto;
  padding: 10px 8px 4px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border-radius: 8px;
}

.sidebar-user:hover {
  background: var(--bg-hover);
}

.user-avatar-symbolic {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #2a2a2a;
  border: 1px solid var(--border-subtle);
  color: #38bdf8;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-plan {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ====================================================
   RIGHT MAIN CHAT VIEW
   ==================================================== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  position: relative;
  background: var(--bg-main);
}

/* Top Minimal Header */
.chat-header {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  padding: 4px 6px;
  user-select: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.pill-badge.green {
  color: var(--accent-green);
  border-color: rgba(16, 185, 129, 0.25);
  background: rgba(16, 185, 129, 0.08);
}

/* Scroll Area for Messages */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding-bottom: 20px;
}

/* Empty State (Center Icon + Title) */
.empty-view {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  user-select: none;
}

.mascot-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  color: var(--accent-blue);
  opacity: 0.9;
}

.empty-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.empty-subtext {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-muted);
  max-width: 580px;
  line-height: 1.6;
}

/* Conversation Feed */
.conversation-feed {
  max-width: 768px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Message Rows */
.user-row {
  display: flex;
  justify-content: flex-end;
}

.user-bubble {
  background: #2f2f2f;
  color: var(--text-main);
  padding: 10px 16px;
  border-radius: 18px;
  max-width: 80%;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.agent-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 100%;
}

.agent-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.agent-avatar {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: #ffffff;
  font-weight: 800;
  font-family: var(--font-sans);
  flex-shrink: 0;
  user-select: none;
}

/* ====================================================
   COLLAPSIBLE TOOL LOG EXECUTION STEPS
   ==================================================== */
.agent-logs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 6px 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.log-item {
  border-radius: 6px;
  transition: background 0.12s ease;
  overflow: hidden;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  cursor: pointer;
  color: #9ca3af;
  font-size: 13.5px;
  font-family: var(--font-sans);
  user-select: none;
}

.log-item:hover .log-header {
  background: rgba(255, 255, 255, 0.05);
  color: #e5e7eb;
}

.log-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.log-chevron {
  font-size: 13px;
  color: #6b7280;
  transition: transform 0.15s ease;
  display: inline-block;
}

.log-item.open .log-chevron {
  transform: rotate(90deg);
  color: #9ca3af;
}

.log-detail {
  padding: 8px 12px;
  background: var(--bg-code);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: #7dd3fc;
  overflow-x: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 0 0 6px 6px;
  white-space: pre-wrap;
}

/* Animated Working Indicator */
.log-working {
  padding: 6px 10px;
  font-size: 13.5px;
  color: #9ca3af;
  display: flex;
  align-items: center;
  gap: 8px;
}

.working-pulse {
  animation: workingPulse 1.4s infinite ease-in-out;
}

@keyframes workingPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Agent Text Content */
.agent-text {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text-soft);
  word-break: break-word;
}

.agent-text p {
  margin: 0 0 12px;
}

.agent-text p:last-child,
.agent-text ul:last-child,
.agent-text ol:last-child {
  margin-bottom: 0;
}

.agent-text ul,
.agent-text ol {
  margin: 4px 0 16px;
  padding-left: 24px;
}

.agent-text li {
  margin: 7px 0;
  padding-left: 3px;
}

.agent-text h3,
.agent-text h4,
.agent-text h5 {
  color: var(--text-main);
  margin: 18px 0 8px;
  line-height: 1.35;
}

.agent-text code {
  font-family: var(--font-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 5px;
  border-radius: 4px;
  color: #7dd3fc;
}

.agent-text a {
  color: var(--accent-blue);
  text-decoration: underline;
  font-weight: 500;
}

.agent-text strong {
  color: var(--text-main);
  font-weight: 600;
}

/* Streaming Typewriter Cursor */
.streaming-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--text-main);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 0.75s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Public Function URL Card */
.public-url-card {
  margin-top: 12px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.url-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.url-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-green);
  font-family: var(--font-mono);
}

.url-address {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: #7dd3fc;
  text-decoration: underline;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.url-btn {
  background: var(--accent-green);
  color: #07090e;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.url-btn:hover {
  background: #34d399;
  transform: translateY(-1px);
}

/* Approval Card */
.approval-card {
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.approval-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-amber);
}

.approval-msg {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.5;
}

.approval-buttons {
  display: flex;
  gap: 8px;
}

.btn-approve {
  background: var(--accent-green);
  color: #07090e;
  border: 0;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.btn-reject {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
  border: 0;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
}

/* ====================================================
   COMPOSER AT BOTTOM (Clean & Minimal Pinned Bar)
   ==================================================== */
.composer-container {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 8px 16px 20px;
  background: var(--bg-main);
  z-index: 10;
}

.composer-box {
  width: 100%;
  max-width: 768px;
  background: var(--bg-composer);
  border-radius: 20px;
  padding: 14px 16px 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s ease;
}

textarea#promptInput {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-main);
  resize: none;
  font-size: 15px;
  line-height: 1.55;
  min-height: 30px;
  max-height: 140px;
  padding: 2px 0;
}

textarea#promptInput::placeholder {
  color: var(--text-muted);
}

.composer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.controls-left, .controls-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.approval-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.15s ease;
}

.approval-toggle.active {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.35);
  color: var(--accent-amber);
}

.approval-toggle svg {
  color: currentColor;
}

/* ====================================================
   Model Picker Minimalist Dropdown
   ==================================================== */
.model-picker-container {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.model-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.model-picker-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.model-picker-btn.open {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.28);
}

.model-picker-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.model-picker-current {
  white-space: nowrap;
}

.model-picker-chevron {
  color: var(--text-muted);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.model-picker-btn.open .model-picker-chevron {
  transform: rotate(180deg);
  color: var(--text-soft);
}

/* Floating Dropdown Popover */
.model-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  background: #212121;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.15s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.15s;
  pointer-events: none;
}

.model-dropdown-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.model-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
  user-select: none;
  color: var(--text-soft);
  font-size: 13.5px;
}

.model-option:hover,
.model-option:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  outline: none;
}

.model-option.selected {
  color: #ffffff;
  font-weight: 500;
}

.model-option-name {
  white-space: nowrap;
}

.model-check-icon {
  color: #ffffff;
  flex-shrink: 0;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.15s ease;
}

.model-option.selected .model-check-icon {
  opacity: 1;
  transform: scale(1);
}

.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: #676767;
  color: #212121;
  display: grid;
  place-items: center;
  cursor: not-allowed;
  transition: all 0.15s ease;
}

.send-btn.active {
  background: #ffffff;
  color: #000000;
  cursor: pointer;
}

.send-btn.active:hover {
  transform: scale(1.05);
}

.hidden {
  display: none !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.7);
  }
  .mobile-only {
    display: grid;
  }
  .composer-container {
    padding: 0 10px 16px;
  }
  .empty-title {
    font-size: 22px;
  }
}
