:root {
  --bg-base: #1C1917;
  --bg-panel: #262220;
  --bg-input: #302B28;
  --border-color: #4A423D;
  
  --text-main: #F4EADE;
  --text-muted: #A89F95;
  
  --accent-primary: #D4A574; /* Champagne gold */
  --accent-secondary: #C17817; /* Deep amber */
  
  --success: #7A9E8E;
  --warning: #D4A574;
  --error: #B85C4A;
  
  --font-sans: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

/* Focus States for Accessibility */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--accent-primary); }

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

.cortex-app {
  display: flex; flex-direction: column; height: 100vh; max-width: 1600px; margin: 0 auto;
}

/* Header */
.cortex-header {
  display: flex; justify-content: space-between; align-items: center; padding: 0 32px;
  height: 70px; border-bottom: 1px solid var(--border-color); background: rgba(28, 25, 23, 0.8);
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-pulse {
  width: 12px; height: 12px; background-color: var(--accent-primary);
  border-radius: 50%; box-shadow: 0 0 15px var(--accent-primary); animation: pulse 2s infinite alternate;
}
.brand h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: 2px; }
.brand span { font-weight: 400; color: var(--text-muted); font-size: 1rem; }
.status { font-family: var(--font-mono); font-size: 0.85rem; display: flex; align-items: center; }
.status-indicator { width: 8px; height: 8px; border-radius: 50%; background: var(--success); margin-right: 8px; box-shadow: 0 0 8px var(--success); }

@keyframes pulse { 0% { box-shadow: 0 0 5px var(--accent-primary); } 100% { box-shadow: 0 0 15px var(--accent-primary), 0 0 5px var(--accent-primary) inset; } }

/* Main Layout */
.cortex-main { display: flex; flex: 1; overflow: hidden; }

/* Left Panel */
.queue-panel {
  width: 450px; border-right: 1px solid var(--border-color); background-color: var(--bg-panel);
  display: flex; flex-direction: column; padding: 24px;
}
.panel-header h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 8px; }
.panel-header p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 24px; line-height: 1.5; }

.ticket-list {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 24px; padding-right: 8px;
}

.ticket-item {
  padding: 16px; background-color: var(--bg-base); border: 1px solid var(--border-color);
  border-radius: 8px; cursor: pointer; transition: all 0.2s;
}
.ticket-item:hover { border-color: var(--accent-secondary); transform: translateY(-2px); }
.ticket-item.active { border-color: var(--accent-primary); background-color: rgba(212, 165, 116, 0.05); }

.ticket-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.8rem; color: var(--text-muted); }
.ticket-item-subject { font-weight: 600; color: var(--text-main); font-size: 0.95rem; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-item-preview { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.custom-ticket-area {
  border-top: 1px solid var(--border-color); padding-top: 24px;
}
.custom-ticket-area h3 { font-size: 1rem; margin-bottom: 12px; font-weight: 500; }
textarea {
  width: 100%; height: 100px; background-color: var(--bg-input); border: 1px solid var(--border-color);
  border-radius: 8px; padding: 12px; color: var(--text-main); font-family: var(--font-sans);
  font-size: 0.9rem; line-height: 1.5; resize: none; margin-bottom: 12px; transition: border-color 0.2s;
}
textarea:focus { outline: none; border-color: var(--accent-primary); }

.btn {
  padding: 12px 24px; border-radius: 6px; font-weight: 500; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
  font-family: inherit; font-size: 0.9rem; border: none; width: 100%;
}
.btn-primary { background-color: var(--accent-primary); color: white; }
.btn-primary:hover { background-color: #C17817; }
.btn-secondary { background-color: transparent; border: 1px solid var(--border-color); color: var(--text-main); width: auto; padding: 8px 16px;}
.btn-secondary:hover { background-color: var(--bg-input); }

/* Right Panel */
.analysis-panel {
  flex: 1; background: radial-gradient(circle at center, rgba(212, 165, 116, 0.03) 0%, transparent 70%);
  position: relative; overflow-y: auto;
}

.results-overlay {
  position: absolute; inset: 0; background-color: var(--bg-base);
  display: flex; align-items: center; justify-content: center; z-index: 10; transition: opacity 0.3s;
}
.results-overlay.hidden { opacity: 0; pointer-events: none; }
.empty-state { text-align: center; color: var(--text-muted); }
.empty-state svg { margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { color: var(--text-main); margin-bottom: 8px; font-weight: 500; }

.results-content { padding: 40px; max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px;}

.priority-badge {
  padding: 6px 16px; border-radius: 20px; font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px;
}
.priority-Critical { background-color: rgba(239, 68, 68, 0.1); color: var(--error); border: 1px solid rgba(239, 68, 68, 0.3); }
.priority-High { background-color: rgba(245, 158, 11, 0.1); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.3); }
.priority-Normal { background-color: rgba(193, 120, 23, 0.1); color: var(--accent-secondary); border: 1px solid rgba(193, 120, 23, 0.3); }

.ticket-view { background-color: var(--bg-input); padding: 24px; border-radius: 8px; border: 1px solid var(--border-color); }
.ticket-body { font-size: 1.05rem; line-height: 1.6; color: var(--text-main); }

.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; }
.metric-card { background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 8px; padding: 20px; }
.metric-title { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; }
.metric-value { font-size: 1.5rem; font-weight: 600; margin-bottom: 4px; font-family: var(--font-sans); }
.metric-sub { font-size: 0.85rem; color: var(--text-muted); }

.sentiment-val.pos { color: var(--success); }
.sentiment-val.neg { color: var(--error); }
.sentiment-val.neu { color: var(--text-muted); }

.sentiment-bar { height: 6px; background-color: var(--bg-input); border-radius: 3px; margin-top: 12px; overflow: hidden; position: relative; }
.sentiment-fill { position: absolute; top: 0; left: 50%; height: 100%; width: 0; transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.sentiment-fill.pos { background-color: var(--success); }
.sentiment-fill.neg { background-color: var(--error); right: 50%; left: auto; }

.routing-card {
  background-color: rgba(212, 165, 116, 0.05); border: 1px solid rgba(212, 165, 116, 0.3);
  border-radius: 8px; padding: 20px; display: flex; align-items: center; gap: 20px;
}
.routing-icon {
  width: 48px; height: 48px; background-color: var(--accent-primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: white; flex-shrink: 0;
}
.routing-destination { font-size: 1.5rem; font-weight: 600; color: white; }

.draft-section { border-top: 1px solid var(--border-color); padding-top: 24px; }
.draft-body {
  background-color: var(--bg-panel); border: 1px dashed var(--border-color); border-radius: 8px;
  padding: 24px; font-size: 0.95rem; line-height: 1.6; color: var(--text-muted); white-space: pre-wrap;
}

.badge { display: inline-block; padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.badge-primary { background-color: var(--accent-glow); color: var(--accent-primary); }

/* Mobile Tab Bar - hidden on desktop */
.mobile-tabs {
  display: none;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
}

.mobile-tab {
  flex: 1;
  padding: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.mobile-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

/* ======================== */
/* Responsive: Tablet       */
/* ======================== */
@media (max-width: 1024px) {
  .queue-panel { width: 360px; }
  .results-content { padding: 24px; }
  .routing-destination { font-size: 1.2rem; }
}

/* ======================== */
/* Responsive: Mobile       */
/* ======================== */
@media (max-width: 768px) {
  body { overflow: auto; height: auto; }
  .cortex-app { height: auto; min-height: 100vh; }

  /* Header */
  .cortex-header { padding: 0 16px; height: 56px; }
  .brand h1 { font-size: 1rem; letter-spacing: 1px; }
  .brand span { display: none; }
  .status { font-size: 0.75rem; }

  /* Show mobile tabs */
  .mobile-tabs { display: flex; }

  /* Stack panels vertically */
  .cortex-main { flex-direction: column; overflow: visible; }

  .queue-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 16px;
  }

  .analysis-panel {
    min-height: calc(100vh - 106px);
    position: relative;
    overflow-y: auto;
  }

  /* Hide panel toggling */
  .queue-panel.mobile-hidden,
  .analysis-panel.mobile-hidden { display: none; }

  /* Panel header */
  .panel-header h2 { font-size: 1.1rem; }
  .panel-header p { font-size: 0.85rem; margin-bottom: 16px; }

  /* Ticket list */
  .ticket-list { margin-bottom: 16px; padding-right: 0; max-height: none; }
  .ticket-item { padding: 12px; }
  .ticket-item-header { font-size: 0.75rem; }
  .ticket-item-subject { font-size: 0.9rem; }

  /* Custom ticket */
  .custom-ticket-area { padding-top: 16px; }
  textarea { height: 80px; font-size: 16px; /* prevents iOS zoom */ }

  /* Buttons */
  .btn { padding: 14px 20px; font-size: 1rem; }

  /* Results content */
  .results-content { padding: 20px 16px; gap: 20px; }

  .results-overlay {
    position: relative;
    height: calc(100vh - 106px);
    min-height: auto;
  }
  .results-overlay.hidden { display: none; }

  /* Metrics */
  .metrics-grid { grid-template-columns: 1fr; gap: 16px; }
  .metric-card { padding: 16px; }
  .metric-value { font-size: 1.25rem; }

  /* Routing */
  .routing-card { padding: 16px; gap: 16px; flex-wrap: wrap; }
  .routing-icon { width: 40px; height: 40px; }
  .routing-destination { font-size: 1.1rem; }

  /* Ticket view */
  .ticket-view { padding: 16px; }
  .ticket-body { font-size: 0.95rem; }

  /* Draft */
  .draft-body { padding: 16px; font-size: 0.9rem; }
  .draft-section div[style] { flex-direction: column; }
  .draft-section .btn-secondary { width: 100%; justify-content: center; }
  .draft-section .btn-primary { width: 100%; }

  /* Priority badge */
  .priority-badge { font-size: 0.75rem; padding: 4px 12px; }
}

/* ======================== */
/* Responsive: Small Phone  */
/* ======================== */
@media (max-width: 380px) {
  .cortex-header { height: 48px; }
  .brand h1 { font-size: 0.9rem; }
  .brand-pulse { width: 8px; height: 8px; }
  .status { display: none; }
  .results-content { padding: 16px 12px; }
}

/* ======================== */
/* Reduced Motion           */
/* ======================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
