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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-input: #1e2a4a;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --accent: #4fc3f7;
  --accent-hover: #29b6f6;
  --accent-dim: rgba(79, 195, 247, 0.15);
  --border: #2a2a4a;
  --msg-user: #1e3a5f;
  --msg-assistant: #252540;
  --danger: #ef5350;
  --success: #66bb6a;
  --radius: 8px;
  --sidebar-width: 280px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ─── Login ─────────────────────────────── */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-box {
  background: var(--bg-secondary);
  padding: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  text-align: center;
  width: 360px;
}

.login-box h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--accent);
}

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

.login-box input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  margin-bottom: 16px;
  outline: none;
}

.login-box input:focus {
  border-color: var(--accent);
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.login-box button:hover {
  background: var(--accent-hover);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}

/* ─── App Layout ────────────────────────── */

#app {
  display: none;
  height: 100vh;
}

#app.active {
  display: flex;
}

/* ─── Sidebar ───────────────────────────── */

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

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

.brand-selector {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

.brand-selector:focus {
  border-color: var(--accent);
}

.product-selector {
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border);
}

.product-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

.product-select:focus {
  border-color: var(--accent);
}

.skill-list {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.skill-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  transition: all 0.15s;
}

.skill-item:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.skill-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.skill-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.session-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.session-header h3 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.new-session-btn {
  padding: 4px 12px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.new-session-btn:hover {
  background: var(--accent-hover);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 2px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-item:hover {
  background: var(--accent-dim);
}

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

.session-item .session-delete {
  display: none;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

.session-item:hover .session-delete {
  display: flex;
}

.session-item .session-delete:hover {
  background: var(--danger);
  color: #fff;
}

.session-item.active {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
}

.session-item .session-name {
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item .session-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.session-rename-input {
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 6px;
  width: 100%;
  outline: none;
}

/* ─── Main Chat Area ────────────────────── */

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

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .header-brand {
  color: var(--text-muted);
  font-size: 13px;
}

.chat-header .header-product {
  color: var(--text-secondary);
  font-size: 14px;
}

.chat-header .header-skill {
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}

.chat-header .header-session {
  color: var(--text-secondary);
  font-size: 14px;
}

.chat-header .header-sep {
  color: var(--text-muted);
}

/* ─── Messages ──────────────────────────── */

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

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 15px;
  text-align: center;
  line-height: 1.6;
}

.message {
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  max-width: 100%;
}

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

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

.message.user .message-avatar {
  background: var(--accent);
  color: #000;
}

.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  color: var(--accent);
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  max-width: 85%;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--msg-user);
  border-top-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--msg-assistant);
  border-top-left-radius: 4px;
}

.message-timestamp {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 6px;
  text-align: right;
}

.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { margin-left: 20px; margin-bottom: 8px; }
.message-bubble code { background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.message-bubble pre { background: rgba(0,0,0,0.3); padding: 12px; border-radius: var(--radius); overflow-x: auto; margin-bottom: 8px; }
.message-bubble pre code { background: none; padding: 0; }
.message-bubble strong { color: var(--accent); }
.message-bubble h1, .message-bubble h2, .message-bubble h3 { margin: 12px 0 6px; color: var(--accent); }
.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 15px; }
.message-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.message-bubble table { border-collapse: collapse; width: 100%; margin-bottom: 8px; }
.message-bubble th, .message-bubble td { border: 1px solid var(--border); padding: 6px 10px; font-size: 13px; text-align: left; }
.message-bubble th { background: rgba(255,255,255,0.05); }

.message-bubble img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 8px 0;
}

.message-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.message-images img {
  max-width: 200px;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
  cursor: pointer;
}

/* PDF tags in messages */
.message-pdfs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pdf-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-secondary);
}

.pdf-tag-icon {
  background: #e74c3c;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
}

/* PDF preview in upload area */
.pdf-preview-icon {
  width: 80px;
  height: 60px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #e74c3c;
}

.pdf-preview-name {
  display: block;
  font-size: 10px;
  color: var(--text-secondary);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* Streaming cursor */
.streaming .message-bubble::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 16px;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: middle;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Tool status indicator */
.tool-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(0, 200, 255, 0.08);
  border: 1px solid rgba(0, 200, 255, 0.2);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.85em;
}

.tool-status .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 200, 255, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Input Area ────────────────────────── */

.input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

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

.input-wrapper textarea {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  min-height: 44px;
  line-height: 1.4;
}

.input-wrapper textarea:focus {
  border-color: var(--accent);
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.input-buttons {
  display: flex;
  gap: 6px;
}

.btn-upload, .btn-send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.15s;
}

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

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

.btn-send {
  background: var(--accent);
  color: #000;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Product Photos Bar */
.product-photos-bar {
  display: none;
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 20px 0;
}

.product-photos-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

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

.product-photos-add {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
  color: var(--text-muted);
  transition: all 0.2s;
}

.product-photos-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.product-photos-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.product-photo-thumb {
  position: relative;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s;
}

.product-photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-photo-thumb:hover {
  border-color: var(--text-muted);
}

.product-photo-thumb.selected {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(79, 195, 247, 0.3);
}

.product-photo-remove {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 16px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  padding: 0;
}

.product-photo-thumb:hover .product-photo-remove {
  opacity: 1;
}

/* Image previews in input */
.upload-previews {
  display: flex;
  gap: 8px;
  padding: 8px 0 0;
  flex-wrap: wrap;
  max-width: 900px;
  margin: 0 auto;
}

.upload-preview {
  position: relative;
  width: 80px;
  height: 80px;
}

.upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.upload-preview .remove-upload {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── New Session Modal ─────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 400px;
}

.modal h2 {
  margin-bottom: 16px;
  font-size: 18px;
}

.modal label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal input, .modal select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  margin-bottom: 16px;
}

.modal input:focus, .modal select:focus {
  border-color: var(--accent);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-buttons button {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.btn-cancel {
  background: var(--bg-input);
  color: var(--text-secondary);
}

.btn-create {
  background: var(--accent);
  color: #000;
}

/* ─── Mode Selector ────────────────────── */

#continue-from-group {
  margin-bottom: 16px;
}

#mode-selector {
  margin-bottom: 16px;
}

#mode-selector label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-option {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.mode-option:hover {
  border-color: var(--accent);
}

.mode-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.mode-option .mode-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.mode-option .mode-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Action Buttons ───────────────────── */

.action-bar {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.action-btn {
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-btn:hover {
  background: var(--accent);
  color: #000;
}

.action-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.action-btn.success {
  border-color: var(--success);
  color: var(--success);
  cursor: default;
}

.action-btn.error {
  border-color: var(--danger);
  color: var(--danger);
}

.action-icon {
  font-size: 14px;
}

.generated-image {
  margin-top: 12px;
  border-radius: var(--radius);
  overflow: hidden;
}

.generated-image img {
  max-width: 400px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.2s;
}

.generated-image img:hover {
  transform: scale(1.02);
}

.generated-image .download-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.8rem;
  transition: opacity 0.2s;
}

.generated-image .download-btn:hover {
  opacity: 0.85;
}

.generated-image .image-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.generated-image .download-btn.success {
  background: var(--success, #22c55e);
}

.generated-image .download-btn.error {
  background: var(--danger);
}

.generated-image .approve-btn {
  background: #6366f1;
}

.generated-image .approve-btn.success {
  background: var(--success, #22c55e);
}

.generated-image button.download-btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* ─── Scrollbar ─────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Responsive ────────────────────────── */

@media (max-width: 768px) {
  .sidebar { width: 240px; }
  .message-bubble { max-width: 90%; }
}
