/* Design System & Tokens - Linear Style (Dark Mode) */
:root {
  /* Colors - Linear Dark Theme */
  --color-bg-base: #000000;
  --color-bg-surface: #0a0a0a;
  --color-bg-panel: rgba(20, 20, 20, 0.7);
  --color-text-main: #ededed;
  --color-text-muted: #888888;
  
  /* Accent Colors - Cyan/Purple Neon */
  --color-primary: #00e5ff;
  --color-primary-hover: #00b8cc;
  --color-secondary: #9d4edd;
  
  --color-chat-user: #00e5ff;
  --color-chat-ai: #1a1a1a;
  --color-chat-text-user: #000000;
  --color-chat-text-ai: #ededed;
  
  --color-border: #222222;
  --color-border-hover: #333333;

  /* Typography */
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --font-size-base: 14px;
  --font-size-sm: 12px;
  --line-height-base: 1.5;

  /* Layout & Spacing */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.8);
  --accent-glow: 0 0 10px rgba(0, 229, 255, 0.15);
}

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

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text-main);
  background-color: var(--color-bg-base);
  -webkit-font-smoothing: antialiased;
  margin: 0;
}

/* Chat page centering (only when #app exists) */
body:has(#app) {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

#app {
  width: 100%;
  max-width: 440px;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

@media (min-width: 480px) {
  #app {
    height: 85vh;
    max-height: 800px;
  }
}

/* Chat Container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--color-bg-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

/* Header */
.chat-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-surface);
  flex-shrink: 0;
}

.header-info {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.avatar-wrapper {
  position: relative;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.status-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background-color: hsl(145, 65%, 45%);
  border: 2px solid var(--color-bg-surface);
  border-radius: 50%;
}

.header-text h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.header-text p {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin: 0;
}

/* Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-lg) var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  background-color: var(--color-bg-surface);
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

.message.user-message {
  align-self: flex-end;
}

.message.ai-message {
  align-self: flex-start;
}

.message-content {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.user-message .message-content {
  background-color: var(--color-chat-user);
  color: var(--color-chat-text-user);
  border-bottom-right-radius: var(--radius-sm);
}

.ai-message .message-content {
  background-color: var(--color-chat-ai);
  color: var(--color-chat-text-ai);
  border-bottom-left-radius: var(--radius-sm);
}

/* System messages (like tool executed) */
.message.system-message {
  align-self: center;
  max-width: 90%;
}

.system-message .message-content {
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  text-align: center;
  padding: var(--spacing-xs) var(--spacing-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

/* Loading dots */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 4px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: var(--color-text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Input Area */
.chat-input-area {
  padding: var(--spacing-md);
  background: var(--color-bg-surface);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

#chat-form {
  display: flex;
  gap: var(--spacing-sm);
  position: relative;
}

#message-input {
  flex: 1;
  padding: 14px 48px 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  font-family: inherit;
  font-size: inherit;
  color: var(--color-text-main);
  background-color: var(--color-bg-base);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

#message-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px hsla(215, 90%, 55%, 0.15);
}

#send-button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

#send-button:hover {
  background-color: var(--color-primary-hover);
}

#send-button:active {
  transform: translateY(-50%) scale(0.95);
}

#send-button:disabled {
  background-color: var(--color-text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

/* =========================================
   KANBAN DASHBOARD
   ========================================= */

.dashboard-body {
  min-height: 100vh;
  width: 100vw;
  margin: 0;
  background-color: var(--color-bg-base);
}

/* Layout Holy Grail */
.layout-app {
  display: flex;
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  width: 250px;
  min-width: 250px;
  background-color: var(--color-bg-surface);
  color: var(--color-text-main);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  border-right: 1px solid var(--color-border);
}

.sidebar-funnel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
  min-height: 0;
}

.sidebar-funnel-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

#sidebar-funnelChart {
  flex: 1;
  min-height: 180px;
}

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

.sidebar-brand h2 { margin: 0; color: var(--color-text-main); font-weight: 600; font-size: 1.2rem; }
.sidebar-brand p { font-size: 0.8rem; color: var(--color-primary); margin: 0; text-transform: uppercase; letter-spacing: 1px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-nav a {
  padding: 12px 20px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover, .sidebar-nav a.active {
  background-color: var(--color-bg-panel);
  color: var(--color-primary);
  border-left: 3px solid var(--color-primary);
  text-shadow: var(--accent-glow);
}

.main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 60px;
  background-color: rgba(10, 10, 10, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.topbar-search input {
  width: 400px;
  padding: 10px 15px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background-color: var(--color-bg-base);
  color: var(--color-text-main);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.topbar-search input:focus {
  border-color: var(--color-primary);
  box-shadow: var(--accent-glow);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.user-name { font-weight: 600; font-size: 0.95rem; }
.user-role { font-size: 0.8rem; color: #64748b; }
.user-avatar {
  width: 40px; height: 40px;
  background: var(--primary-color);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Analytics panel: hide when searching */
.analytics-panel.hidden {
  display: none;
}

/* Analytics Panel */
.analytics-panel {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.kpi-cards {
  display: flex;
  gap: 20px;
}

.kpi-card {
  flex: 1;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  border-left: 4px solid var(--primary-color);
}

.kpi-card h3 { font-size: 0.9rem; color: #64748b; margin-bottom: 10px; }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: bold; color: #1e293b; }

.charts-container {
  display: flex;
  gap: 20px;
}

.chart-box {
  background: white;
  border-radius: 10px;
  padding: 15px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  width: 100%;
  height: 350px;
}

.dashboard-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--spacing-lg);
  max-width: 1400px;
  margin: 0 auto;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
}

.dashboard-header h1 {
  font-size: 1.5rem;
  color: var(--color-text-main);
}

.dashboard-header p {
  color: var(--color-text-muted);
}

.btn-back {
  padding: 8px 16px;
  background-color: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-main);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-back:hover {
  background-color: var(--color-border);
}

.kanban-board {
  display: flex;
  gap: var(--spacing-lg);
  flex: 1;
  overflow-x: auto;
  padding-bottom: var(--spacing-md);
  min-height: 500px;
}

.kanban-column {
  flex: 1;
  min-width: 320px;
  background-color: var(--color-bg-panel);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s, border-color 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.kanban-column.drag-over {
  background-color: rgba(0, 229, 255, 0.05);
  border-color: var(--color-primary);
  border-style: dashed;
}

.column-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.4);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
}

.column-header h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.count {
  background-color: var(--color-border);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.column-body {
  padding: var(--spacing-md);
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.kanban-card {
  background-color: var(--color-bg-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  cursor: grab;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), var(--accent-glow);
  border-color: var(--color-primary);
}

.kanban-card:hover .card-actions-hover {
  opacity: 1;
  transform: translateY(0);
}

.kanban-card:active {
  cursor: grabbing;
}

.kanban-card.dragging {
  opacity: 0.5;
  transform: scale(0.95);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.card-header-premium {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
  text-transform: uppercase;
}

.card-title-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-title-group strong {
  font-size: 0.95rem;
  color: var(--color-text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-title-group span {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 2px;
}

.card-body p {
  font-size: 0.8rem;
  color: #475569;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-footer {
  padding-top: 10px;
  border-top: 1px dashed var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.score {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* Hover Action Bar */
.card-actions-hover {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  background: white;
  padding: 4px;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border: 1px solid #e2e8f0;
  opacity: 0;
  transform: translateY(-5px);
  transition: all 0.2s ease-in-out;
}

.action-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: #64748b;
  text-decoration: none;
  transition: all 0.15s;
}

.action-btn:hover {
  background: #f1f5f9;
  color: var(--color-primary);
}

/* Tooltips */
.tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--color-border);
  color: var(--color-text-muted);
  font-size: 10px;
  font-weight: bold;
  margin-left: 6px;
}

.tooltip-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--color-text-main);
  color: white;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 10;
  box-shadow: var(--shadow-md);
}

.tooltip-icon::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px;
  border-style: solid;
  border-color: var(--color-text-main) transparent transparent transparent;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
}

.tooltip-icon:hover::after,
.tooltip-icon:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Modal 360 Overlay */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: flex-end;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: white;
  width: 100%;
  max-width: 450px;
  height: 100%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
}

.modal-overlay:not(.hidden) .modal-content {
  transform: translateX(0);
}

/* =========================================
   PWA & MOBILE RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
  .layout-app {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: 70px;
    min-width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 2000;
    flex-direction: row;
    padding: 0;
    border-top: 1px solid #334155;
    background-color: #1e293b;
  }
  
  .sidebar-brand, .sidebar-funnel {
    display: none;
  }
  
  .sidebar-nav {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    padding: 0;
  }
  
  .sidebar-nav a {
    padding: 10px 5px;
    font-size: 0.75rem;
    text-align: center;
    border-left: none !important;
    border-top: 3px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }
  
  .sidebar-nav a:hover, .sidebar-nav a.active {
    border-left: none !important;
    border-top: 3px solid var(--color-primary);
    background-color: transparent;
  }
  
  .main-wrapper {
    margin-bottom: 70px; /* Space for bottom nav */
    height: calc(100vh - 70px);
    overflow-y: auto;
  }
  
  .topbar {
    padding: 0 15px;
  }
  
  .topbar-search input {
    width: 100%;
    max-width: 200px;
  }
  
  .kpi-cards {
    flex-direction: column;
  }
  
  .charts-container {
    flex-direction: column;
  }
  
  .kanban-board {
    flex-direction: column;
    padding-bottom: 90px;
  }
  
  .kanban-column {
    min-height: 400px;
    margin-bottom: 15px;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  position: sticky;
  top: 0;
  background: white;
  z-index: 100;
}

.modal-header h2 { font-size: 1.5rem; }

.btn-close {
  background: none; border: none; font-size: 2rem; cursor: pointer; color: #666;
}

.modal-body { display: flex; flex-direction: column; gap: 1.5rem; }
.modal-section { background: #fdfdfd; border: 1px solid #eee; border-radius: 8px; padding: 1rem; }
.modal-section h3 { font-size: 1.1rem; color: var(--color-primary); margin-bottom: 0.8rem; border-bottom: 1px dashed #ccc; padding-bottom: 0.3rem; }
.timeline { list-style: none; padding-left: 10px; border-left: 3px solid var(--color-primary); }
.timeline li { margin-bottom: 1rem; padding-left: 15px; position: relative; font-size: 0.9rem; }
.timeline li::before { content: ""; position: absolute; left: -22px; top: 0; width: 12px; height: 12px; background: white; border: 3px solid var(--color-primary); border-radius: 50%; }
.chat-history-box { background: #f4f6f8; padding: 1rem; border-radius: 8px; max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.8rem; }
.chat-msg { padding: 0.8rem; border-radius: 8px; font-size: 0.9rem; line-height: 1.4; max-width: 85%; }
.chat-msg-user { background: white; align-self: flex-start; border: 1px solid #ddd; }
.chat-msg-ai { background: var(--color-primary); color: white; align-self: flex-end; }
