/* Cubik AI Generator - Brand Styles */

:root {
  /* Cubik.one brand colors */
  --brand-green: #0A6F3C;
  --brand-green-light: #0d8a4a;
  --brand-beige: #E1B589;
  --brand-grey: #7D7F7D;
  
  /* UI colors */
  --bg-light: #f8f9fa;
  --bg-white: #ffffff;
  --bg-chat: #f0f2f5;
  --text-dark: #1a1a1a;
  --text-muted: #6c757d;
  --text-light: #ffffff;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-light);
  color: var(--text-dark);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html {
  height: -webkit-fill-available;
}

/* Header */
#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  height: 64px;
  box-shadow: var(--shadow);
}

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

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--brand-green);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  font-weight: bold;
}

.logo-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dark);
}

.logo-text span {
  color: var(--brand-green);
}

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

.header-status {
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 16px;
  background: var(--bg-light);
  border-radius: 20px;
}

.header-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.2s;
}

.header-btn:hover {
  border-color: var(--brand-green);
  color: var(--brand-green);
}

.header-btn:active {
  transform: scale(0.95);
}

.header-btn.primary {
  background: var(--brand-green);
  border-color: var(--brand-green);
  color: white;
}

.header-btn.primary:hover {
  background: var(--brand-green-light);
}

/* Main layout */
#main {
  display: flex;
  height: calc(100vh - 64px);
}

/* 3D Viewer */
#viewer {
  flex: 1;
  position: relative;
  background: linear-gradient(180deg, #e8eaec 0%, #d0d4d8 100%);
}

#canvas3d {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* Better touch handling for 3D controls */
}

/* Mobile mode toggle - hidden on desktop */
.mobile-mode-toggle {
  display: none;
}

#viewerHint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  font-size: 12px;
  color: var(--text-muted);
  box-shadow: var(--shadow);
}

#viewerHint span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Chat Panel */
#controls {
  width: 400px;
  background: var(--bg-white);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.05);
}

/* Chat Header */
.chat-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.chat-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

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

/* Mode Toggle */
.mode-toggle {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  background: var(--bg-light);
  border-radius: 12px;
}

.mode-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-muted);
}

.mode-btn:hover {
  color: var(--text-dark);
}

.mode-btn.active {
  background: var(--bg-white);
  color: var(--brand-green);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mode-btn.active[data-mode="creative"] {
  color: #9b59b6;
}

/* Chat Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-chat);
}

.message {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

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

.message.assistant {
  align-items: flex-start;
}

.message-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  white-space: pre-line;
}

.message.user .message-bubble {
  background: var(--brand-green);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--bg-white);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 8px;
}

/* Welcome message */
.welcome-message {
  text-align: center;
  padding: 40px 20px;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--brand-green) 0%, var(--brand-green-light) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 36px;
  color: white;
  box-shadow: 0 8px 24px rgba(10, 111, 60, 0.3);
}

.welcome-message h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-dark);
}

.welcome-message p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Stats badge */
.stats-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-white);
  border-radius: 20px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.stats-badge .count {
  font-size: 18px;
  font-weight: 700;
  color: var(--brand-green);
}

.stats-badge .label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Chat Input Area */
.chat-input-area {
  padding: 16px 20px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
}

.input-container {
  display: flex;
  gap: 12px;
  align-items: center;
}

.text-input-wrapper {
  flex: 1;
  position: relative;
}

.text-input-wrapper textarea {
  width: 100%;
  padding: 14px 16px;
  padding-right: 44px;
  border: 2px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  min-height: 48px;
  max-height: 120px;
}

.text-input-wrapper textarea:focus {
  border-color: var(--brand-green);
}

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

/* Info button for AI thinking */
.info-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: none;
  background: var(--bg-light);
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.info-btn:hover {
  background: var(--brand-green);
  color: white;
}

.info-btn.visible {
  display: flex;
}

/* Tooltip */
.tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: 280px;
  padding: 12px 16px;
  background: var(--text-dark);
  color: white;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 16px;
  width: 12px;
  height: 12px;
  background: var(--text-dark);
  transform: rotate(45deg);
}

.info-btn:hover .tooltip {
  opacity: 1;
  visibility: visible;
}

/* Input buttons */
.send-btn,
.mic-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn svg,
.mic-btn svg {
  width: 22px;
  height: 22px;
  fill: white;
}

/* Send button - beige */
.send-btn {
  background: var(--brand-beige);
}

.send-btn svg {
  transform: translateX(1px);
}

.send-btn:hover {
  filter: brightness(0.95);
}

.send-btn:active {
  transform: scale(0.95);
}

/* Mic button - green */
.mic-btn {
  background: var(--brand-green);
}

.mic-btn:hover {
  background: var(--brand-green-light);
}

.mic-btn:active {
  transform: scale(0.95);
}

.mic-btn.recording {
  background: #e74c3c;
  animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
}


/* Settings collapse */
.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  margin-top: 8px;
  background: var(--bg-light);
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
}

.settings-toggle:hover {
  background: #e8eaec;
}

.settings-content {
  display: none;
  padding: 12px 0;
}

.settings-content.open {
  display: block;
}

.settings-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.settings-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}

.settings-row input:focus {
  border-color: var(--brand-green);
}

.settings-row button {
  padding: 10px 16px;
  background: var(--brand-green);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 13px;
  cursor: pointer;
}

/* Inline loading message in chat */
.loading-message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.loading-message.hidden {
  display: none;
}

.loading-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--brand-green) 0%, var(--brand-green-light) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.loading-avatar svg {
  width: 20px;
  height: 20px;
  fill: white;
}

.loading-bubble {
  background: var(--bg-white);
  padding: 16px 20px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.loading-text {
  font-size: 14px;
  color: var(--text-dark);
  font-weight: 500;
}

.loading-dots {
  display: flex;
  gap: 4px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--brand-green);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

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

.loading-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* Spinner for 3D viewer only */
.viewer-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 32px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.viewer-loading.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.viewer-loading-text {
  font-size: 14px;
  color: var(--text-dark);
  font-weight: 500;
}

/* Hidden elements */
.hidden {
  display: none !important;
}

/* Responsive - Tablet */
@media (max-width: 1024px) {
  #controls {
    width: 340px;
  }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
  #header {
    padding: 8px 12px;
    height: 52px;
  }

  .logo-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .logo-text {
    font-size: 16px;
  }

  .header-actions {
    gap: 6px;
  }

  .header-status {
    font-size: 11px;
    padding: 6px 10px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
  }

  .header-btn svg {
    width: 16px;
    height: 16px;
  }

  #main {
    flex-direction: column;
    height: calc(100vh - 52px);
  }

  /* 3D Viewer on top */
  #viewer {
    flex: 1;
    min-height: 50vh;
  }

  #viewerHint {
    display: none;
  }

  /* Mobile mode toggle - floating pill */
  .mobile-mode-toggle {
    display: flex;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    gap: 4px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
  }

  .mode-pill {
    width: 36px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 16px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
  }

  .mode-pill:active {
    transform: scale(0.9);
  }

  .mode-pill.active {
    background: var(--brand-green);
    box-shadow: 0 2px 6px rgba(10, 111, 60, 0.3);
  }

  .mode-pill.active[data-mode="creative"] {
    background: #9b59b6;
    box-shadow: 0 2px 6px rgba(155, 89, 182, 0.3);
  }

  /* Chat panel at bottom - minimal */
  #controls {
    width: 100%;
    max-height: none;
    min-height: auto;
    border-left: none;
    border-top: none;
    display: flex;
    flex-direction: column;
    background: transparent;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    pointer-events: none;
  }

  /* Hide chat header on mobile */
  .chat-header {
    display: none;
  }

  /* Messages with fade gradient */
  .chat-messages {
    flex: 0;
    max-height: 120px;
    overflow-y: auto;
    padding: 8px 12px;
    background: linear-gradient(to bottom, transparent 0%, rgba(248, 249, 250, 0.95) 30%);
    pointer-events: auto;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 30%);
    mask-image: linear-gradient(to bottom, transparent 0%, black 30%);
  }

  .welcome-message {
    display: none;
  }

  .message {
    margin-bottom: 8px;
  }

  .message-bubble {
    max-width: 85%;
    padding: 8px 12px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
  }

  .message.user .message-bubble {
    background: var(--brand-green);
  }

  .message-time {
    display: none;
  }

  /* Input always visible at bottom */
  .chat-input-area {
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    pointer-events: auto;
  }

  .input-container {
    gap: 8px;
  }

  .text-input-wrapper textarea {
    padding: 10px 14px;
    padding-right: 36px;
    font-size: 16px;
    min-height: 42px;
    border-radius: 21px;
    background: var(--bg-light);
    border: none;
  }

  .text-input-wrapper textarea:focus {
    background: var(--bg-white);
    box-shadow: 0 0 0 2px var(--brand-green);
  }

  .info-btn {
    right: 10px;
    width: 22px;
    height: 22px;
  }

  .send-btn,
  .mic-btn {
    width: 42px;
    height: 42px;
  }

  .send-btn svg,
  .mic-btn svg {
    width: 20px;
    height: 20px;
  }

  /* Loading message minimal */
  .loading-message {
    padding: 8px;
    gap: 8px;
  }

  .loading-avatar {
    width: 28px;
    height: 28px;
  }

  .loading-bubble {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.95);
  }

  .viewer-loading {
    padding: 16px 24px;
  }
}

/* Small phones */
@media (max-width: 375px) {
  .header-status {
    display: none;
  }

  .logo-text {
    font-size: 15px;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #main {
    flex-direction: row;
  }

  #controls {
    position: relative;
    width: 280px;
    max-height: 100%;
    background: var(--bg-white);
    border-left: 1px solid var(--border);
    pointer-events: auto;
  }

  .chat-header {
    display: block;
    padding: 12px;
  }

  .chat-messages {
    max-height: none;
    flex: 1;
    background: var(--bg-chat);
    -webkit-mask-image: none;
    mask-image: none;
  }

  .welcome-message {
    display: block;
  }

  #viewer {
    flex: 1;
    min-height: 100%;
  }
}

/* iOS safe areas */
@supports (padding: max(0px)) {
  .chat-input-area {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}
