/* ==========================================
   CHATBOT AGENCE IPTV - Styles
   ========================================== */

:root {
  /* Colors */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #64748b;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;

  /* Background */
  --bg-dark: #0f172a;
  --bg-darker: #020617;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-input: #1e293b;

  /* Text */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Border */
  --border-color: #334155;

  /* Sizing */
  --sidebar-width: 260px;
  --header-height: 70px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-darker);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Safe area for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  .chat-input-container {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .sidebar-footer {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* Prevent text size adjustment on orientation change */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Improve touch targets */
button, a, input, select, textarea {
  touch-action: manipulation;
}

/* Smooth scrolling */
.chat-messages,
.conversations-list,
.modal-body {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* App Container */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================
   SIDEBAR
   ========================================== */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-dark);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 32px;
}

.logo-text h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.logo-text span {
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

.nav-icon {
  font-size: 18px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--secondary);
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* ==========================================
   MAIN CONTENT
   ========================================== */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-content {
  display: none;
  flex-direction: column;
  height: 100%;
}

.tab-content.active {
  display: flex;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-dark);
}

.content-header h2 {
  font-size: 20px;
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

/* ==========================================
   CHAT INTERFACE
   ========================================== */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  margin-left: auto;
  flex-direction: row-reverse;
}

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

.message.user .message-avatar {
  background: var(--primary);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-text {
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.message.user .message-text {
  background: var(--primary);
  color: white;
  border-radius: 16px 16px 4px 16px;
}

.message.bot .message-text {
  border-radius: 16px 16px 16px 4px;
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 8px;
}

.message.user .message-time {
  text-align: right;
}

/* Tool calls info */
.tool-info {
  background: var(--bg-darker);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.tool-info strong {
  color: var(--primary-light);
}

/* Chat Input */
.chat-input-container {
  padding: 16px 24px 24px;
  background: var(--bg-dark);
  border-top: 1px solid var(--border-color);
}

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

.chat-input-wrapper:focus-within {
  border-color: var(--primary);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  padding: 8px 0;
}

#chat-input:focus {
  outline: none;
}

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

#send-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 8px;
  flex-shrink: 0;
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding: 0 4px;
}

.chat-stats {
  font-size: 12px;
  color: var(--text-muted);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.typing-indicator.hidden {
  display: none;
}

.typing-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: typing 1.4s infinite;
}

.typing-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==========================================
   CONVERSATIONS LIST
   ========================================== */

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

.conversation-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: 12px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.conversation-item:hover {
  background: var(--bg-card-hover);
}

.conversation-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.conversation-info {
  flex: 1;
  min-width: 0;
}

.conversation-info h4 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.conversation-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

/* ==========================================
   STATS
   ========================================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 24px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.info-box {
  margin: 0 24px 24px;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
}

.info-box h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

.info-box ul {
  list-style: none;
}

.info-box li {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
}

.info-box li:last-child {
  border-bottom: none;
}

.info-box strong {
  color: var(--text-primary);
}

/* ==========================================
   MODAL
   ========================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-content {
  position: relative;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  background: var(--bg-dark);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ==========================================
   UTILITIES
   ========================================== */

.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--bg-card-hover);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--secondary);
}

/* ==========================================
   RESPONSIVE
   ========================================== */

/* Tablet */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .app-container {
    flex-direction: column;
  }

  /* Mobile Sidebar - Hidden by default, shown as overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s ease;
  }

  .sidebar.open {
    left: 0;
  }

  /* Sidebar Overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .sidebar-overlay.active {
    display: block;
  }

  /* Mobile Header */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
  }

  .mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    padding: 8px;
    cursor: pointer;
    border-radius: 8px;
  }

  .mobile-menu-btn:hover {
    background: var(--bg-card);
  }

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

  .mobile-header .logo-icon {
    font-size: 24px;
  }

  .mobile-header .logo-text h1 {
    font-size: 16px;
  }

  .mobile-header .logo-text span {
    display: none;
  }

  /* Main Content */
  .main-content {
    width: 100%;
    min-height: calc(100vh - 56px);
  }

  .content-header {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    align-items: stretch;
  }

  .content-header h2 {
    font-size: 18px;
  }

  .header-actions {
    display: flex;
    justify-content: flex-end;
  }

  /* Chat */
  .chat-messages {
    padding: 16px;
  }

  .message {
    max-width: 90%;
  }

  .message-text {
    padding: 10px 14px;
    font-size: 14px;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  /* Chat Input */
  .chat-input-container {
    padding: 12px 16px 16px;
  }

  .chat-input-wrapper {
    padding: 6px 10px;
  }

  #chat-input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 6px 0;
  }

  #send-btn {
    width: 44px;
    height: 44px;
  }

  .chat-info {
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
  }

  .chat-stats {
    font-size: 11px;
  }

  /* Stats */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .stat-value {
    font-size: 20px;
  }

  .info-box {
    margin: 0 16px 16px;
  }

  /* Conversations List */
  .conversations-list {
    padding: 12px 16px;
  }

  .conversation-item {
    padding: 12px;
  }

  .conversation-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  /* Modal */
  .modal-content {
    width: 95%;
    max-height: 90vh;
    margin: 16px;
  }

  .modal-header {
    padding: 12px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  /* Buttons */
  .btn {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 44px; /* Touch target */
  }

  .nav-item {
    padding: 14px 16px;
    min-height: 48px;
  }
}

/* Small Mobile */
@media (max-width: 375px) {
  .message {
    max-width: 95%;
  }

  .message-text {
    padding: 8px 12px;
    font-size: 13px;
  }

  .content-header h2 {
    font-size: 16px;
  }

  .stat-card {
    padding: 12px;
    gap: 12px;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .stat-value {
    font-size: 18px;
  }

  .stat-label {
    font-size: 12px;
  }
}
