/* ==========================================
   BASE & RESET
   ========================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #f2f2f2;
  color: #1a1a1a;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}
input, textarea, select, button { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* ==========================================
   HEADER
   ========================================== */
#app-header {
  background: #000;
  color: #fff;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo { height: 28px; width: auto; object-fit: contain; }
.header-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1.5px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.progress-text {
  font-size: 13px;
  color: #999;
  white-space: nowrap;
}
.progress-dots {
  display: flex;
  gap: 6px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #444;
  transition: background 0.3s;
}
.dot.active { background: #fff; }

/* ==========================================
   MAIN CONTAINER
   ========================================== */
#app-main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ==========================================
   CHAT VIEW
   ========================================== */
#chat-view {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 20px;
  scroll-behavior: smooth;
}
#chat-messages {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
}

/* Messages */
.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  animation: msgIn 0.25s ease-out;
  word-wrap: break-word;
  line-height: 1.5;
}
.msg-bot {
  align-self: flex-start;
  background: #fff;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.msg-user {
  align-self: flex-end;
  background: #1a1a1a;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-user .msg-file-preview {
  color: rgba(255,255,255,0.8);
}
.msg-system {
  align-self: center;
  background: transparent;
  color: #777;
  font-size: 13px;
  text-align: center;
  padding: 8px 0;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
  align-self: flex-start;
  background: #fff;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bbb;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================
   INPUT AREA (FOOTER)
   ========================================== */
#input-area {
  background: #fff;
  border-top: 1px solid #e5e5e5;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  z-index: 50;
}
#input-container {
  max-width: 680px;
  margin: 0 auto;
}
#input-content {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#text-input {
  flex: 1;
  border: 1.5px solid #e5e5e5;
  border-radius: 12px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.4;
  transition: border-color 0.2s;
  background: #fafafa;
}
#text-input:focus { border-color: #1a1a1a; background: #fff; }
#text-input::placeholder { color: #aaa; }
.btn-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #1a1a1a;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, opacity 0.2s;
}
.btn-send:disabled { opacity: 0.3; cursor: default; }
.btn-send:not(:disabled):hover { background: #333; }

/* ==========================================
   INPUT WIDGETS
   ========================================== */
#input-widgets {
  margin-top: 10px;
}

/* Chips */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  padding: 8px 16px;
  border: 1.5px solid #e5e5e5;
  border-radius: 20px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  user-select: none;
}
.chip:hover { border-color: #999; background: #f7f7f7; }
.chip.selected {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

/* Tags */
.tags-container { display: flex; flex-direction: column; gap: 8px; }
.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}
.tag {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: #1a1a1a;
  color: #fff;
  border-radius: 16px;
  font-size: 13px;
  animation: msgIn 0.2s ease-out;
}
.tag-remove {
  cursor: pointer;
  opacity: 0.6;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.tag-remove:hover { opacity: 1; }
.tags-input-row { display: flex; gap: 8px; }
.tags-input-row input {
  flex: 1;
  border: 1.5px solid #e5e5e5;
  border-radius: 12px;
  padding: 8px 12px;
  outline: none;
  background: #fafafa;
}
.tags-input-row input:focus { border-color: #1a1a1a; background: #fff; }
.tags-confirm {
  padding: 8px 20px;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.tags-confirm:hover { background: #333; }

/* Upload */
.upload-zone {
  border: 2px dashed #ddd;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafafa;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: #1a1a1a;
  background: #f0f0f0;
}
.upload-zone svg { margin-bottom: 8px; }
.upload-zone p { color: #555; font-size: 14px; }
.upload-zone span { color: #999; font-size: 12px; }
.upload-zone input[type="file"] { display: none; }
.upload-preview {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.upload-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
}
.upload-preview .upload-name {
  font-size: 13px;
  color: #555;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-progress {
  height: 3px;
  background: #e5e5e5;
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: #1a1a1a;
  width: 0%;
  transition: width 0.3s;
}

/* Color picker */
.color-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.color-input-row input[type="color"] {
  width: 48px;
  height: 48px;
  border: 2px solid #e5e5e5;
  border-radius: 10px;
  cursor: pointer;
  padding: 2px;
  background: #fff;
}
.color-input-row input[type="text"] {
  flex: 1;
  border: 1.5px solid #e5e5e5;
  border-radius: 12px;
  padding: 10px 14px;
  outline: none;
  font-family: 'Inter', monospace;
  background: #fafafa;
}
.color-input-row input[type="text"]:focus { border-color: #1a1a1a; background: #fff; }
.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #e5e5e5;
  flex-shrink: 0;
}

/* Skip */
#skip-container {
  margin-top: 8px;
  text-align: right;
}

/* ==========================================
   BUTTONS
   ========================================== */
.btn-primary {
  padding: 10px 24px;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.2s;
}
.btn-primary:hover { background: #333; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-lg { padding: 12px 32px; font-size: 15px; }
.btn-ghost {
  padding: 8px 16px;
  background: transparent;
  color: #555;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: color 0.2s;
}
.btn-ghost:hover { color: #000; }
.btn-sm { font-size: 13px; padding: 6px 12px; }
.btn-danger-ghost {
  padding: 8px 16px;
  background: transparent;
  color: #d44;
  border: none;
  cursor: pointer;
  font-size: 14px;
}
.btn-danger-ghost:hover { color: #a00; }
.required { color: #d44; }

/* ==========================================
   PORTFOLIO VIEW
   ========================================== */
#portfolio-view {
  height: 100%;
  overflow-y: auto;
  padding: 20px 16px;
}
#portfolio-grid-view, #portfolio-detail {
  max-width: 900px;
  margin: 0 auto;
}
.portfolio-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.portfolio-header h2 {
  font-size: 20px;
  font-weight: 600;
}
#projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.project-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  border: 1.5px solid #e5e5e5;
  position: relative;
}
.project-card:hover {
  border-color: #bbb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.project-card.card-new {
  border-style: dashed;
  color: #999;
}
.project-card.card-new:hover { color: #555; border-color: #999; }
.project-card-icon {
  font-size: 36px;
  margin-bottom: 8px;
  display: block;
}
.project-card-thumb {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  margin: 0 auto 8px;
  display: block;
}
.project-card-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-card-meta {
  font-size: 11px;
  color: #999;
  margin-top: 4px;
}
.portfolio-footer {
  text-align: center;
  padding: 16px 0;
}

/* Portfolio Detail */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e5e5;
}
#detail-title {
  font-weight: 600;
  font-size: 16px;
}
.detail-body {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.detail-photos {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
}
#photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.photo-thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-thumb .photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.photo-thumb:hover .photo-remove { opacity: 1; }
.photo-thumb.uploading { opacity: 0.5; }
.photo-thumb .photo-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.5);
}
.dropzone {
  border: 2px dashed #ddd;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: #1a1a1a;
  background: #f0f0f0;
}
.dropzone p { color: #555; font-size: 14px; margin-top: 8px; }
.dropzone span { color: #999; font-size: 12px; }

.detail-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail-form label {
  font-size: 13px;
  font-weight: 500;
  color: #555;
}
.detail-form input[type="text"],
.detail-form input[type="number"],
.detail-form select,
.detail-form textarea {
  width: 100%;
  border: 1.5px solid #e5e5e5;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
  background: #fafafa;
}
.detail-form input:focus,
.detail-form select:focus,
.detail-form textarea:focus {
  border-color: #1a1a1a;
  background: #fff;
}
.detail-form textarea { resize: vertical; }
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #1a1a1a;
}
.form-check label { font-size: 14px; color: #1a1a1a; cursor: pointer; }

/* ==========================================
   SUBMITTED VIEW
   ========================================== */
#submitted-view {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.submitted-content {
  text-align: center;
  max-width: 420px;
}
.submitted-icon {
  width: 72px;
  height: 72px;
  background: #1a1a1a;
  color: #fff;
  border-radius: 50%;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
}
.submitted-content h2 {
  font-size: 22px;
  margin-bottom: 12px;
}
.submitted-content p {
  color: #666;
  line-height: 1.6;
}
.submitted-email {
  margin-top: 16px;
  font-weight: 600;
  color: #1a1a1a !important;
}

/* ==========================================
   UTILITY / INLINE
   ========================================== */
.msg-file-preview {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.inline-loader {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0,0,0,0.15);
  border-top-color: #1a1a1a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.error-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #d44;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 200;
  animation: toastIn 0.3s ease-out;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================
   CERT / AWARD / TESTIMONIAL FORM IN CHAT
   ========================================== */
.inline-form {
  background: #fff;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 85%;
  align-self: flex-start;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  animation: msgIn 0.25s ease-out;
}
.inline-form label {
  font-size: 12px;
  font-weight: 500;
  color: #777;
}
.inline-form input,
.inline-form textarea,
.inline-form select {
  width: 100%;
  border: 1.5px solid #e5e5e5;
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  font-size: 14px;
}
.inline-form input:focus,
.inline-form textarea:focus { border-color: #1a1a1a; }
.inline-form textarea { resize: vertical; min-height: 60px; }
.inline-form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
.rating-stars {
  display: flex;
  gap: 4px;
}
.rating-star {
  font-size: 24px;
  cursor: pointer;
  color: #ddd;
  transition: color 0.15s;
  user-select: none;
}
.rating-star.active { color: #f5a623; }
.rating-star:hover { color: #f5a623; }

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
  .detail-body {
    flex-direction: column;
  }
  #projects-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
  .msg { max-width: 90%; }
  #text-input { font-size: 16px; } /* Prevent zoom on iOS */
}
@media (max-width: 480px) {
  #app-header { padding: 0 12px; height: 50px; }
  .header-title { font-size: 13px; letter-spacing: 1px; }
  .progress-text { font-size: 11px; }
  .dot { width: 6px; height: 6px; }
  #chat-view { padding: 12px; }
  #input-area { padding: 10px 12px; }
  #projects-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}
