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

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #1e2231;
  --bg-hover: #252a3a;
  --border: rgba(255, 255, 255, 0.08);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-muted: rgba(255, 255, 255, 0.4);
  --accent: #4fc3f7;
  --accent-glow: rgba(79, 195, 247, 0.15);
  --success: #66bb6a;
  --warning: #ffa726;
  --danger: #ef5350;
  --info: #42a5f5;
  --sidebar-width: 240px;
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #4fc3f7, #2196f3);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.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: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

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

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #7c4dff, #536dfe);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.15s;
}

.btn-logout:hover {
  color: var(--danger);
  background: rgba(239, 83, 80, 0.1);
}

.btn-logout svg {
  width: 18px;
  height: 18px;
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  max-width: calc(100vw - var(--sidebar-width));
}

.section {
  display: none;
}

.section.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

/* Page Header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.last-sync {
  color: var(--text-muted);
  font-size: 12px;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 20px;
}

/* Channel Grid */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}

.channel-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

.channel-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.channel-financials::before { background: linear-gradient(90deg, #66bb6a, #4caf50); }
.channel-amazon::before { background: linear-gradient(90deg, #ff9800, #f57c00); }
.channel-walmart::before { background: linear-gradient(90deg, #42a5f5, #1976d2); }
.channel-grocery::before { background: linear-gradient(90deg, #ab47bc, #8e24aa); }

.channel-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 12px;
}

.channel-financials .channel-icon { background: rgba(102, 187, 106, 0.15); color: #66bb6a; }
.channel-amazon .channel-icon { background: rgba(255, 152, 0, 0.15); color: #ff9800; }
.channel-walmart .channel-icon { background: rgba(66, 165, 245, 0.15); color: #42a5f5; }
.channel-grocery .channel-icon { background: rgba(171, 71, 188, 0.15); color: #ab47bc; }

.channel-info h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.channel-status {
  font-size: 12px;
  font-weight: 500;
}

.channel-status.connected { color: var(--success); }
.channel-status.pending { color: var(--text-muted); }

.channel-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 16px;
}

.channel-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

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

.metric-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
}

.badge-success { background: rgba(102, 187, 106, 0.15); color: var(--success); }
.badge-warning { background: rgba(255, 167, 38, 0.15); color: var(--warning); }
.badge-danger { background: rgba(239, 83, 80, 0.15); color: var(--danger); }
.badge-neutral { background: rgba(255, 255, 255, 0.08); color: var(--text-secondary); }

.metric-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.metric-change {
  font-size: 12px;
  margin-top: 6px;
  font-weight: 500;
}

.metric-change.positive { color: var(--success); }
.metric-change.negative { color: var(--danger); }
.metric-change.neutral { color: var(--warning); }

/* Chart Row */
.chart-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.chart-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.chart-panel h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
}

/* Insights Card */
.insights-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.insights-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.insights-badge {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}

.insight-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.insight-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.insight-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.insight-warning .insight-dot { background: var(--warning); }
.insight-info .insight-dot { background: var(--info); }
.insight-danger .insight-dot { background: var(--danger); }

.insight-item p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.insight-item strong {
  color: var(--text-primary);
}

/* Financial Ratios Row */
.ratios-row {
  display: flex;
  gap: 16px;
  margin-bottom: 28px;
}

.ratio-item {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.ratio-item .ratio-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.ratio-item .ratio-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

/* Balance Sheet Grid */
.bs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.bs-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.bs-panel h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

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

.bs-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.bs-table td {
  padding: 10px 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.bs-table tr:last-child td {
  border-bottom: none;
}

.bs-table .total-row td {
  font-weight: 700;
  color: var(--text-primary);
  border-top: 2px solid var(--border);
}

.bs-table .positive { color: var(--success); }
.bs-table .negative { color: var(--danger); }
.bs-table .neutral { color: var(--warning); }

@media (max-width: 768px) {
  .bs-grid { grid-template-columns: 1fr; }
  .ratios-row { flex-direction: column; }
}

/* Buttons */
.btn-primary {
  padding: 10px 20px;
  background: linear-gradient(135deg, #4fc3f7, #2196f3);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(33, 150, 243, 0.3);
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 12px;
}

/* Setup Card */
.setup-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

.setup-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  margin: 0 auto 20px;
  background: rgba(79, 195, 247, 0.1);
  color: var(--accent);
}

.setup-card h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.setup-card > p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.setup-steps {
  text-align: left;
  max-width: 450px;
  margin: 0 auto 28px;
}

.setup-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.step-num {
  width: 24px;
  height: 24px;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Financials Embed */
.embed-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.financial-iframe {
  width: 100%;
  height: calc(100vh - 180px);
  border: none;
  background: var(--bg-card);
}

.embed-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  gap: 12px;
}

.fallback-icon {
  width: 64px;
  height: 64px;
  background: rgba(102, 187, 106, 0.15);
  color: var(--success);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
}

.embed-fallback h3 {
  font-size: 18px;
}

.embed-fallback p {
  color: var(--text-secondary);
  font-size: 13px;
}

.embed-fallback code {
  background: var(--bg-primary);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--accent);
}

.fallback-note {
  max-width: 400px;
  text-align: center;
  margin-top: 8px;
}

/* Chat */
.chat-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: calc(100vh - 200px);
  display: flex;
  flex-direction: column;
}

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

.chat-message {
  display: flex;
  gap: 12px;
  max-width: 80%;
}

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

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.ai-message .message-avatar {
  background: var(--accent-glow);
  color: var(--accent);
}

.user-message .message-avatar {
  background: rgba(124, 77, 255, 0.15);
  color: #b388ff;
}

.message-content {
  background: var(--bg-hover);
  border-radius: 12px;
  padding: 12px 16px;
}

.message-content p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.message-content p + p {
  margin-top: 8px;
}

.message-hint {
  font-style: italic;
  color: var(--text-muted) !important;
  font-size: 12px !important;
}

.user-message .message-content {
  background: rgba(79, 195, 247, 0.1);
}

.chat-input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

.chat-input-area input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input-area input:focus {
  border-color: var(--accent);
}

.btn-send {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #4fc3f7, #2196f3);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

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

.btn-send svg {
  width: 18px;
  height: 18px;
}

/* Settings */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.settings-panel h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.connection-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.connection-item:last-child {
  border-bottom: none;
}

.conn-status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.conn-status.connected { background: var(--success); }
.conn-status.pending { background: var(--text-muted); }

.conn-info {
  flex: 1;
}

.conn-info strong {
  display: block;
  font-size: 14px;
}

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

.conn-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
}

.schedule-info p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

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

.account-info p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 500px;
  max-width: 90vw;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

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

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.upload-zone:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Responsive */
@media (max-width: 1200px) {
  .channel-grid { grid-template-columns: repeat(2, 1fr); }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    --sidebar-width: 60px;
  }
  .sidebar-title,
  .nav-item span,
  .user-name { display: none; }
  .sidebar-header { justify-content: center; padding: 16px; }
  .nav-item { justify-content: center; padding: 12px; }
  .main-content { padding: 20px; }
  .channel-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr; }
  .chart-row { grid-template-columns: 1fr; }
}
