/* Rich Vibrant Design System for ExcelAI with Light/Dark System Theme Sync */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', sans-serif;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --accent-amber: #f59e0b;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme Mode */
[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-table-header: #f1f5f9;
  --bg-table-row-alt: #f8fafc;
  --bg-bubble-user: #2563eb;
  --bg-bubble-ai: #ffffff;
  --bg-hover: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-on-primary: #ffffff;

  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
  --brand-gradient: linear-gradient(135deg, #2563eb, #4f46e5);

  --theme-btn-active-bg: #0f172a;
  --theme-btn-active-text: #ffffff;
}

/* Dark Theme Mode */
[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-main: #0b1329;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --bg-table-header: #0f172a;
  --bg-table-row-alt: rgba(255, 255, 255, 0.02);
  --bg-bubble-user: #2563eb;
  --bg-bubble-ai: #1e293b;
  --bg-hover: rgba(255, 255, 255, 0.05);

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-on-primary: #ffffff;

  --border-color: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  --brand-gradient: linear-gradient(90deg, #60a5fa, #a78bfa);

  --theme-btn-active-bg: #f8fafc;
  --theme-btn-active-text: #0f172a;
}

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

html, body {
  font-family: var(--font-body);
  background: var(--bg-app);
  color: var(--text-primary);
  height: 100%;
  width: 100vw;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* Hide raw file input completely */
#file-input, #mobile-file-input, input[type="file"].hidden-file-input {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  position: absolute !important;
  left: -9999px !important;
}

/* Mobile Header */
.mobile-header {
  display: none;
  height: 56px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 40;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 17px;
  color: var(--text-primary);
}

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

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

/* Monochrome Theme Icon Segmented Control */
.theme-icon-group {
  display: inline-flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.theme-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-btn:hover {
  color: var(--text-primary);
}

.theme-btn.active {
  background: var(--theme-btn-active-bg);
  color: var(--theme-btn-active-text);
  box-shadow: var(--shadow-sm);
}

/* Sidebar Drawer */
.sidebar {
  width: 320px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 50;
  transition: transform var(--transition);
}

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

.brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-subtitle {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.8px;
  margin-top: 4px;
}

.mobile-close-btn {
  display: none;
}

/* Vibrant File Upload Button */
.upload-box {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%);
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
  user-select: none;
}

.upload-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

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

/* Data Catalog */
.catalog-section {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.catalog-section::-webkit-scrollbar {
  width: 5px;
}
.catalog-section::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.catalog-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.dataset-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.dataset-header {
  padding: 10px 14px;
  background: var(--bg-hover);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dataset-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
}

.btn-delete {
  color: var(--accent-red);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: var(--transition);
}

.btn-delete:hover {
  background: rgba(239, 68, 68, 0.15);
}

.sheet-item {
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
}

.sheet-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.sheet-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin: 2px 0 6px;
}

.chips-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  font-size: 10px;
  background: var(--bg-hover);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.chip.canonical {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-amber);
  border-color: rgba(245, 158, 11, 0.3);
}

/* Status Indicator */
.status-bar {
  padding: 12px 20px;
  font-size: 12px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

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

.status-dot.active {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

/* Main Area */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-main);
}

/* Top Desktop Header */
.desktop-header {
  height: 52px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-sidebar);
}

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

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

.header-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

/* Chat Workspace */
.chat-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 30px 10%;
  scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar {
  width: 6px;
}
.chat-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

/* Welcome Card */
.welcome-card {
  max-width: 760px;
  margin: 40px auto;
  text-align: center;
}

.welcome-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  margin-bottom: 18px;
}

.welcome-card h2 {
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-card p {
  color: var(--text-muted);
  font-size: 14px;
}

.example-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
  text-align: left;
}

.example-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.example-item:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--primary);
  background: rgba(37, 99, 235, 0.05);
}

/* Chat Messages */
.msg-row {
  max-width: 900px;
  margin: 0 auto 24px;
}

.msg-row.user {
  display: flex;
  justify-content: flex-end;
}

.msg-row.user .bubble {
  background: var(--primary);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
  padding: 12px 18px;
  max-width: 80%;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.msg-row.ai .bubble {
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border-color);
  border-radius: 16px 16px 16px 4px;
  padding: 20px 22px;
  box-shadow: var(--shadow-md);
}

.answer-header {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.source-tag {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.badge-engine {
  font-size: 10px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid rgba(37, 99, 235, 0.2);
}

/* Table Wrapper */
.table-wrapper {
  max-height: 400px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-top: 12px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th {
  background: var(--bg-table-header);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

tr:nth-child(even) td {
  background: var(--bg-table-row-alt);
}

.export-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn-export {
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-export:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.chart-container-box {
  margin-top: 16px;
  background: var(--bg-card);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  max-width: 855px;
  box-shadow: var(--shadow-sm);
}

/* Input Bar */
.input-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  padding: 16px 10%;
  background: var(--bg-sidebar);
}

/* Mobile Quick Upload Bar (Above Input Box on Mobile) */
.mobile-input-upload {
  display: none;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 900px;
  margin: 0 auto;
}

.input-row textarea {
  flex: 1;
  resize: none;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.35;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  min-height: 46px;
  max-height: 120px;
  box-sizing: border-box;
  overflow-y: auto;
}

.input-row textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-send {
  height: 46px;
  background: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 0 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 45;
  opacity: 0;
  transition: opacity var(--transition);
}

/* Responsive Media Queries for Mobile & Tablet */
@media (max-width: 768px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  .app-container {
    flex-direction: column;
    height: calc(100vh - 56px);
    width: 100vw;
    overflow: hidden;
  }

  .mobile-header {
    display: flex;
    position: sticky;
    top: 0;
    width: 100vw;
    box-shadow: var(--shadow-sm);
  }

  .desktop-header {
    display: none;
  }

  .mobile-close-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 290px;
    max-width: 85vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 100;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
  }

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

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

  .chat-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 12px;
  }

  /* Quick Mobile Upload Pill Bar (Above Input Box on Mobile) */
  .mobile-input-upload {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    max-width: 900px;
    margin: 0 auto 8px;
    padding: 0 2px;
  }

  .mobile-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, var(--primary) 0%, #3b82f6 100%);
    color: #ffffff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.25);
    user-select: none;
    transition: var(--transition);
  }

  .mobile-upload-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.4);
  }

  .mobile-upload-btn i {
    width: 14px;
    height: 14px;
  }

  .welcome-card {
    margin: 16px auto;
    padding: 0 6px;
  }

  .welcome-card h2 {
    font-size: 20px;
  }

  .welcome-card p {
    font-size: 13px;
  }

  .example-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 16px;
  }

  .example-item {
    padding: 12px 14px;
    font-size: 13px;
  }

  .input-bar {
    padding: 10px 12px 14px;
    background: var(--bg-sidebar);
  }

  .input-row {
    gap: 8px;
    align-items: flex-end;
  }

  .input-row textarea {
    padding: 9px 12px;
    font-size: 13px;
    line-height: 1.35;
    min-height: 44px;
    border-radius: 12px;
  }

  .btn-send {
    height: 44px;
    padding: 0 18px;
    font-size: 13px;
    border-radius: 12px;
  }

  .msg-row.user .bubble {
    max-width: 90%;
    padding: 10px 14px;
    font-size: 13.5px;
  }

  .msg-row.ai .bubble {
    padding: 14px 16px;
  }

  .table-wrapper {
    max-height: 300px;
  }

  table {
    font-size: 12px;
  }

  th, td {
    padding: 7px 10px;
  }
}
