/**
 * ============================================
 * MERCICORE - STYLESHEET
 * ============================================
 * Harmonized and categorized CSS architecture
 */

/* ========== RESET & BASE ========== */
* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  height: auto;
}

/* ========== TYPOGRAPHY ========== */
body {
  font-family: -apple-system, BlinkSystemFont, 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(to bottom, #eef2ff, #ffffff);
  margin: 0;
  padding: 40px 20px;
  text-align: center;
  color: #333;
  min-height: 100vh;
}

h1 {
  font-size: clamp(2.5rem, 5vw, 4.5rem);
  color: #4f46e5;
  margin-bottom: 20px;
}

.subtitle {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  margin-bottom: 10px;
}

.highlight {
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  color: #dc2626;
  font-weight: bold;
  margin-bottom: 60px;
}

/* ========== LAYOUT ========== */
.top-menu {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  gap: 10px;
  align-items: center;
}

.categories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 30px;
  margin-bottom: 60px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.buttons-container {
  margin: 60px 0;
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 40px;
  margin-top: 60px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

/* ========== FORM ELEMENTS ========== */
.textarea-wrapper {
  position: relative;
  width: 90%;
  max-width: 900px;
  margin: 0 auto 60px;
}

textarea {
  width: 100%;
  padding: 30px;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  border-radius: 24px;
  border: 4px solid #a5b4fc;
  box-shadow: 0 10px 30px rgba(0,0,0,0.05);
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
}

.char-counter {
  position: absolute;
  bottom: 15px;
  right: 20px;
  font-size: clamp(0.9rem, 1.4vw, 1.1rem);
  color: #6b7280;
  background: rgba(255, 255, 255, 0.9);
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
}

/* ========== BUTTONS ========== */
button {
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.category-btn {
  padding: 40px;
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  background: white;
  border-radius: 24px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.1);
  border: 4px solid #c7d2fe;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.category-btn:hover {
  transform: translateY(-10px) scale(1.05);
  box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}

.category-btn:active {
  transform: translateY(-5px) scale(1.02);
}

.produce-btn,
.history-btn,
.chat-btn,
.community-btn {
  padding: 25px 60px;
  font-size: clamp(1.4rem, 2.5vw, 2.2rem);
  color: white;
  border: none;
  border-radius: 60px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  will-change: transform;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.produce-btn {
  background: #6366f1;
  box-shadow: 0 15px 35px rgba(99,102,241,0.4);
}

.produce-btn:hover:not(:disabled) {
  background: #4f46e5;
  transform: translateY(-5px);
}

.produce-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.history-btn {
  background: #8b5cf6;
  box-shadow: 0 15px 35px rgba(139,92,246,0.4);
}

.history-btn:hover {
  background: #7c3aed;
  transform: translateY(-5px);
}

.profile-btn {
  padding: 12px 24px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  background: #6b7280;
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(107, 114, 128, 0.3);
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.profile-btn:hover {
  background: #4b5563;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(107, 114, 128, 0.4);
}

.chat-btn {
  background: #a855f7;
  box-shadow: 0 15px 35px rgba(168, 85, 247, 0.4);
}

.chat-btn:hover {
  background: #9333ea;
  transform: translateY(-5px);
}

.community-btn {
  background: #f97316;
  box-shadow: 0 15px 35px rgba(249, 115, 22, 0.4);
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.community-btn:hover {
  background: #ea580c;
  transform: translateY(-5px);
}

.tree-expand-btn {
  padding: 15px 30px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  margin-top: 20px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.tree-expand-btn:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.simulate-btn {
  padding: 15px 30px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  background: #10b981;
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  margin: 10px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.simulate-btn:hover {
  background: #059669;
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.export-btn {
  padding: 12px 24px;
  font-size: clamp(1.2rem, 1.6vw, 1.4rem);
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 20px;
  transition: all 0.2s ease;
  font-weight: 600;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.export-btn:hover {
  background: #dc2626;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.feedback-btn {
  padding: 15px 30px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  margin: 0 10px;
  border-radius: 30px;
  cursor: pointer;
  border: none;
  color: white;
  transition: transform 0.2s ease, opacity 0.2s ease;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.feedback-btn:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

.feedback-btn.a { background: #10b981; }
.feedback-btn.b { background: #f59e0b; }
.feedback-btn.c { background: #ef4444; }
.feedback-btn.none { background: #6b7280; }

.delete-history-btn {
  padding: 8px 16px;
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  flex-shrink: 0;
}

.delete-history-btn:hover {
  background: #dc2626;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.delete-history-btn:active {
  transform: translateY(0);
}

.result-save-btn {
  padding: 12px 24px;
  font-size: clamp(1.2rem, 1.6vw, 1.4rem);
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.result-save-btn:hover:not(:disabled) {
  background: #4f46e5;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.result-save-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.history-close {
  padding: 15px 40px;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  margin-top: 20px;
  transition: background 0.2s ease;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.history-close:hover {
  background: #dc2626;
}

.error-panel-close {
  padding: 5px 10px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.error-panel-close:hover {
  background: #dc2626;
}

/* ========== CARDS ========== */
.card {
  background: white;
  padding: 40px;
  border-radius: 32px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.1);
  border: 4px solid #c7d2fe;
  animation: fadeIn 0.3s ease;
  transform: translateZ(0);
  will-change: transform, opacity;
}

.card h2 {
  font-size: clamp(3rem, 6vw, 6rem);
  color: #6366f1;
  margin-bottom: 30px;
}

.card p {
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
  margin: 15px 0;
  line-height: 1.6;
}

.note {
  font-style: italic;
  color: #6b7280;
  margin-top: 30px;
  font-size: clamp(1.4rem, 2vw, 1.8rem);
}

.feedback {
  margin-top: 40px;
  grid-column: 1 / -1;
}

/* ========== HISTORY ========== */
.history {
  display: none;
  margin-top: 60px;
  background: white;
  padding: 40px;
  border-radius: 32px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.1);
  border: 4px solid #c7d2fe;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  animation: fadeIn 0.3s ease;
}

.history h3 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin-bottom: 40px;
  color: #4f46e5;
}

.history-item {
  background: #f9fafb;
  padding: 30px;
  border-radius: 16px;
  margin-bottom: 30px;
  text-align: left;
  border-left: 6px solid #6366f1;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

.history-item-header h4 {
  font-size: clamp(1.4rem, 2vw, 1.8rem);
  color: #4f46e5;
  margin: 0;
  flex: 1;
  min-width: 200px;
}

.history-item p {
  font-size: clamp(1.2rem, 1.8vw, 1.5rem);
  margin: 8px 0;
}

.history-item textarea {
  width: 95%;
  padding: 15px;
  font-size: clamp(1.2rem, 1.6vw, 1.4rem);
  border-radius: 10px;
  border: 2px solid #a5b4fc;
  margin-top: 10px;
  margin-bottom: 10px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

.result-save-container {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-top: 10px;
}

.result-save-container.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

.result-save-container.visible {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.save-status {
  font-size: clamp(1.1rem, 1.5vw, 1.3rem);
  font-weight: 600;
  transition: opacity 0.2s ease;
}

.empty-history {
  font-size: clamp(1.4rem, 2vw, 1.8rem);
  color: #6b7280;
  padding: 40px;
}

/* ========== PROFILE MODAL ========== */
.profile-modal,
.sync-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10001;
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
  padding-top: 60px;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  background: white;
  padding: 40px;
  border-radius: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  margin-top: 0;
  position: relative;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-content h3 {
  font-size: clamp(2rem, 3vw, 2.5rem);
  color: #4f46e5;
  margin-bottom: 30px;
}

.modal-content label {
  display: block;
  margin-bottom: 20px;
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
}

.modal-content input,
.modal-content select {
  width: 100%;
  padding: 15px;
  font-size: clamp(1.2rem, 1.6vw, 1.4rem);
  border-radius: 12px;
  border: 2px solid #a5b4fc;
  margin-top: 8px;
}

.profile-save-btn,
.profile-close-btn,
.sync-confirm-btn,
.sync-cancel-btn {
  padding: 15px 30px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  margin: 10px 10px 0 0;
  transition: all 0.2s ease;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.profile-save-btn,
.sync-confirm-btn {
  background: #6366f1;
  color: white;
}

.profile-save-btn:hover,
.sync-confirm-btn:hover {
  background: #4f46e5;
  transform: translateY(-2px);
}

.profile-close-btn,
.sync-cancel-btn {
  background: #6b7280;
  color: white;
}

.profile-close-btn:hover,
.sync-cancel-btn:hover {
  background: #4b5563;
}

/* ========== COMMUNITY ========== */
.community {
  display: none;
  margin-top: 60px;
  background: white;
  padding: 40px;
  border-radius: 32px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.1);
  border: 4px solid #c7d2fe;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  animation: fadeIn 0.3s ease;
}

.community h3 {
  font-size: clamp(2rem, 4vw, 3rem);
  margin-bottom: 20px;
  color: #4f46e5;
}

.community-note {
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
  color: #6b7280;
  font-style: italic;
  margin-bottom: 30px;
}

.community-stats {
  background: #f0f9ff;
  padding: 30px;
  border-radius: 16px;
  margin-bottom: 30px;
  text-align: left;
  border-left: 4px solid #3b82f6;
}

.community-stats h4 {
  font-size: clamp(1.6rem, 2.5vw, 2rem);
  color: #3b82f6;
  margin-bottom: 20px;
}

.community-stats h5 {
  font-size: clamp(1.4rem, 2vw, 1.8rem);
  color: #6366f1;
  margin-top: 20px;
  margin-bottom: 10px;
}

.community-stats p {
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
  margin: 10px 0;
  color: #4b5563;
}

.community-stats ul {
  list-style: none;
  padding: 0;
  margin: 10px 0;
}

.community-stats li {
  font-size: clamp(1.2rem, 1.8vw, 1.6rem);
  padding: 8px 0;
  color: #4b5563;
  border-bottom: 1px solid #e5e7eb;
}

.community-stats li:last-child {
  border-bottom: none;
}

.community-close {
  padding: 15px 40px;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  margin-top: 20px;
  transition: background 0.2s ease;
  display: inline-block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.community-close:hover {
  background: #dc2626;
}

/* ========== DECISION TREE ========== */
.sub-options {
  margin-top: 30px;
  padding: 20px;
  background: #f0f9ff;
  border-radius: 16px;
  border-left: 4px solid #3b82f6;
}

.sub-options h4 {
  font-size: clamp(1.4rem, 2vw, 1.8rem);
  color: #3b82f6;
  margin-bottom: 15px;
}

.sub-option {
  margin-bottom: 15px;
  padding: 15px;
  background: white;
  border-radius: 12px;
  border: 2px solid #bfdbfe;
}

.sub-option strong {
  font-size: clamp(1.2rem, 1.6vw, 1.4rem);
  color: #3b82f6;
}

.sub-option p {
  font-size: clamp(1.1rem, 1.5vw, 1.3rem);
  margin-top: 8px;
  color: #4b5563;
}

/* ========== STATUS MESSAGES ========== */
.loading {
  font-size: clamp(1.6rem, 2.5vw, 2rem);
  color: #6366f1;
  margin-top: 40px;
  animation: pulse 1.5s ease-in-out infinite;
}

.success {
  font-size: clamp(1.6rem, 2.5vw, 2rem);
  color: #10b981;
  margin-top: 40px;
  font-weight: bold;
  animation: fadeIn 0.3s ease;
}

.error {
  font-size: clamp(1.4rem, 2vw, 1.8rem);
  color: #ef4444;
  margin-top: 40px;
  padding: 20px;
  background: #fee2e2;
  border-radius: 16px;
  border: 2px solid #ef4444;
}

/* ========== ERROR PANEL ========== */
.error-panel {
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  background: #1f2937;
  color: #fff;
  padding: 15px;
  border-radius: 8px;
  font-size: clamp(12px, 2vw, 14px);
  z-index: 10000 !important;
  max-height: 300px;
  overflow-y: auto;
  font-family: monospace;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  border: 2px solid #ef4444;
}

.error-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.error-panel-title {
  font-weight: bold;
  font-size: 16px;
}

.error-panel-content {
  line-height: 1.6;
}

.error-panel::-webkit-scrollbar {
  width: 8px;
}

.error-panel::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

.error-panel::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
}

.error-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.5);
}

/* ========== ANIMATIONS ========== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .error-panel {
    top: 10px !important;
    left: 10px !important;
    right: 10px !important;
    padding: 12px !important;
    font-size: 12px !important;
    max-height: 150px !important;
  }
}

/* ========== SYNC BUTTONS ========== */
.sync-btn,
.sync-full-btn,
.sync-load-btn {
  padding: 12px 24px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  transition: all 0.2s ease;
}

.sync-btn {
  background: #3b82f6;
}

.sync-btn:hover {
  background: #2563eb;
  transform: translateY(-2px);
}

.sync-full-btn {
  background: #6366f1;
}

.sync-full-btn:hover {
  background: #4f46e5;
  transform: translateY(-2px);
}

.sync-load-btn {
  background: #10b981;
}

.sync-load-btn:hover {
  background: #059669;
  transform: translateY(-2px);
}

/* ========== PREMIUM MODAL ========== */
.premium-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10002;
  animation: fadeIn 0.3s ease;
}

.premium-modal .modal-content {
  background: white;
  padding: 40px;
  border-radius: 20px;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.premium-features {
  margin: 20px 0;
  text-align: left;
}

.premium-feature {
  padding: 10px 0;
  font-size: clamp(1.1rem, 1.6vw, 1.3rem);
  color: #4b5563;
  border-bottom: 1px solid #e5e7eb;
}

.premium-feature:last-child {
  border-bottom: none;
}

.premium-price {
  margin: 30px 0;
  text-align: center;
}

.price-amount {
  font-size: clamp(2.5rem, 4vw, 3.5rem);
  font-weight: bold;
  color: #f59e0b;
}

.price-period {
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  color: #6b7280;
  margin-left: 5px;
}

.payment-form {
  margin: 20px 0;
}

.payment-form label {
  display: block;
  margin-bottom: 15px;
}

.payment-form input {
  width: 100%;
  padding: 12px;
  font-size: clamp(1.1rem, 1.5vw, 1.3rem);
  border: 2px solid #d1d5db;
  border-radius: 8px;
  box-sizing: border-box;
}

.payment-form input:focus {
  outline: none;
  border-color: #6366f1;
}

.premium-btn {
  padding: 12px 24px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  transition: all 0.2s ease;
}

.premium-btn:hover {
  background: #4f46e5;
  transform: translateY(-2px);
}

.premium-confirm-btn,
.premium-cancel-btn {
  padding: 12px 24px;
  font-size: clamp(1.2rem, 1.8vw, 1.4rem);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.premium-confirm-btn {
  background: #f59e0b;
  color: white;
}

.premium-confirm-btn:hover {
  background: #d97706;
  transform: translateY(-2px);
}

.premium-cancel-btn {
  background: #6b7280;
  color: white;
}

.premium-cancel-btn:hover {
  background: #4b5563;
}

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