/* ===== CSS Variables ===== */
:root {
  /* Light Theme */
  --bg-primary: rgba(255, 255, 255, 0.85);
  --bg-secondary: rgba(255, 255, 255, 0.6);
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #a0aec0;
  --border-color: rgba(255, 255, 255, 0.3);
  --shadow-color: rgba(0, 0, 0, 0.1);
  --glass-bg: rgba(255, 255, 255, 0.15);
  --glass-border: rgba(255, 255, 255, 0.2);
  --gradient-start: #667eea;
  --gradient-end: #764ba2;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #fc8181;
  --safe: #48bb78;
  --low: #68d391;
  --medium: #ed8936;
  --high: #ed8936;
  --critical: #fc8181;
}

[data-theme="dark"] {
  --bg-primary: rgba(26, 32, 44, 0.92);
  --bg-secondary: rgba(45, 55, 72, 0.8);
  --text-primary: #e2e8f0;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --border-color: rgba(255, 255, 255, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.3);
  --glass-bg: rgba(0, 0, 0, 0.3);
  --glass-border: rgba(255, 255, 255, 0.05);
  --gradient-start: #2d3748;
  --gradient-end: #1a202c;
}

/* ===== Base Styles ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  position: relative;
  overflow-x: hidden;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ===== Animated Background ===== */
.bg-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  animation: orbFloat 20s ease-in-out infinite;
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: rgba(102, 126, 234, 0.3);
  top: -10%;
  left: -10%;
  animation-delay: 0s;
}

.orb-2 {
  width: 500px;
  height: 500px;
  background: rgba(118, 75, 162, 0.3);
  bottom: -20%;
  right: -10%;
  animation-delay: -7s;
}

.orb-3 {
  width: 300px;
  height: 300px;
  background: rgba(240, 147, 251, 0.2);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(50px, -50px) scale(1.1); }
  50% { transform: translate(-30px, 30px) scale(0.9); }
  75% { transform: translate(40px, 20px) scale(1.05); }
}

/* ===== Glassmorphism ===== */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* ===== Main Card ===== */
.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1000px;
}

.main-card {
  border-radius: 32px;
  padding: 40px;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideUp 0.8s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  flex-wrap: wrap;
  gap: 15px;
}

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

.logo-icon {
  font-size: 2.5rem;
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 400;
  -webkit-text-fill-color: var(--text-secondary);
}

.header-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.icon-btn:hover {
  transform: translateY(-2px) scale(1.05);
  background: var(--gradient-start);
  color: white;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #fc8181;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* ===== Status Bar ===== */
.status-bar {
  padding: 12px 20px;
  border-radius: 12px;
  margin-bottom: 25px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  animation: pulseDot 2s ease-in-out infinite;
}

.status-dot.connected {
  background: #48bb78;
}

.status-dot.error {
  background: #fc8181;
}

.status-dot.loading {
  background: #ed8936;
  animation: pulseDot 1s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.status-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===== Analyzer Section ===== */
.analyzer-section {
  margin-bottom: 25px;
}

.input-wrapper {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 20px;
  border: 2px solid var(--border-color);
  transition: all 0.3s ease;
  margin-bottom: 15px;
}

.input-wrapper:focus-within {
  border-color: var(--gradient-start);
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

.input-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.input-label {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.char-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

textarea {
  width: 100%;
  height: 160px;
  padding: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-primary);
  resize: vertical;
  line-height: 1.6;
}

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

.input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.input-shortcut {
  font-size: 0.75rem;
  color: var(--text-muted);
}

kbd {
  padding: 2px 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
}

/* ===== Buttons ===== */
.btn {
  padding: 12px 28px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  flex: 1;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

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

.btn-secondary:hover {
  background: var(--bg-primary);
  transform: translateY(-2px);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-outline:hover {
  background: var(--bg-secondary);
  transform: translateY(-2px);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-danger {
  background: #fc8181;
  color: white;
}

.btn-danger:hover {
  background: #f56565;
  transform: translateY(-2px);
}

.button-group {
  display: flex;
  gap: 12px;
}

.button-group .btn {
  flex: 1;
}

/* ===== Results ===== */
.result-container {
  animation: slideUp 0.6s ease-out;
  margin-top: 25px;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.result-header h2 {
  font-size: 1.3rem;
  color: var(--text-primary);
  font-weight: 700;
}

.result-actions {
  display: flex;
  gap: 8px;
}

/* ===== Gauge ===== */
.gauge-container {
  display: flex;
  gap: 30px;
  align-items: center;
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 25px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.gauge-wrapper {
  position: relative;
  width: 140px;
  height: 140px;
}

.gauge {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.gauge-bg {
  fill: none;
  stroke: var(--bg-primary);
  stroke-width: 8;
}

.gauge-progress {
  fill: none;
  stroke: #48bb78;
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dasharray 1s cubic-bezier(0.4, 0, 0.2, 1), stroke 1s ease;
}

.gauge-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.gauge-score {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  display: block;
  line-height: 1;
}

.gauge-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  display: block;
  margin-top: 4px;
}

.risk-level-container {
  flex: 1;
  min-width: 200px;
}

.risk-level {
  font-size: 1.8rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 12px;
  padding: 8px 20px;
  border-radius: 12px;
  display: inline-block;
  width: 100%;
}

.risk-level.Safe { color: #48bb78; }
.risk-level.Low { color: #68d391; }
.risk-level.Medium { color: #ed8936; }
.risk-level.High { color: #ed8936; }
.risk-level.Critical { color: #fc8181; }

.risk-level-bar {
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.risk-level-fill {
  height: 100%;
  background: linear-gradient(90deg, #48bb78, #68d391, #ed8936, #ed8936, #fc8181);
  border-radius: 4px;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.risk-level-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* ===== Detail Cards ===== */
.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 20px;
}

.detail-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 18px;
  border: 1px solid var(--border-color);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.detail-icon {
  font-size: 1.2rem;
}

.detail-card h3 {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 600;
}

.detail-list {
  list-style: none;
  padding: 0;
}

.detail-list li {
  padding: 6px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
  padding-left: 20px;
  position: relative;
}

.detail-list li::before {
  position: absolute;
  left: 0;
  top: 6px;
}

.detail-card:first-child .detail-list li::before {
  content: "⚠️";
}

.detail-card:last-child .detail-list li::before {
  content: "✅";
}

/* ===== Metadata ===== */
.metadata {
  padding: 12px 18px;
  background: var(--bg-secondary);
  border-radius: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  border: 1px solid var(--border-color);
}

/* ===== Quick Stats ===== */
.quick-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.stat-item {
  text-align: center;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ===== Modals ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  border-radius: 24px;
  padding: 30px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.4s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.3rem;
  color: var(--text-primary);
}

.close-btn {
  font-size: 2rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 10px;
  transition: all 0.3s;
}

.close-btn:hover {
  color: var(--text-primary);
  transform: rotate(90deg);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

/* ===== History ===== */
.history-list {
  max-height: 400px;
  overflow-y: auto;
}

.history-item {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  transition: all 0.3s;
}

.history-item:hover {
  transform: translateX(4px);
}

.history-item .h-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-item .h-score {
  font-weight: 700;
  font-size: 1.1rem;
}

.history-item .h-message {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.empty-history {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

/* ===== Share ===== */
.share-preview {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
}

.share-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.share-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  color: white;
  font-size: 0.9rem;
}

.share-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.share-btn.email { background: #34a853; }
.share-btn.whatsapp { background: #25d366; }
.share-btn.twitter { background: #1da1f2; }
.share-btn.copy { background: #667eea; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .main-card {
    padding: 20px;
    border-radius: 20px;
  }

  .logo h1 {
    font-size: 1.4rem;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }

  .gauge-container {
    flex-direction: column;
    align-items: center;
    padding: 20px;
  }

  .button-group {
    flex-direction: column;
  }

  .button-group .btn {
    flex: none;
    width: 100%;
  }

  .quick-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .result-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .input-actions {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .modal-content {
    padding: 20px;
    width: 95%;
  }
}

@media (max-width: 480px) {
  .main-card {
    padding: 15px;
  }

  .gauge-wrapper {
    width: 120px;
    height: 120px;
  }

  .gauge-score {
    font-size: 2rem;
  }

  .risk-level {
    font-size: 1.4rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }
}

/* ===== Modal Close Button Fix ===== */
.modal-header .close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 10px;
  transition: all 0.3s ease;
  line-height: 1;
}

.modal-header .close-btn:hover {
  color: var(--text-primary);
  transform: rotate(90deg) scale(1.1);
}

/* Make sure modals are properly hidden */
.modal.hidden {
  display: none !important;
}

.modal {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  justify-content: center;
  align-items: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}
