/* ===== CSS Reset & Variables ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #16a34a;
  --danger-color: #dc2626;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-color: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Language Toggle ===== */
.lang-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 1000;
  background: var(--card-bg);
  padding: 4px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.lang-toggle button {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 16px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.lang-toggle button:hover {
  background: var(--bg-color);
}

.lang-toggle button.active {
  background: var(--primary-color);
  color: white;
}

/* ===== Container ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  flex: 1;
}

/* ===== Header ===== */
header {
  text-align: center;
  margin-bottom: 40px;
}

header h1 {
  font-size: 2.5rem;
  color: var(--text-color);
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* ===== SEO Content ===== */
.seo-content {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--border-radius);
  margin-bottom: 32px;
  box-shadow: var(--shadow);
  line-height: 1.8;
}

.seo-content p {
  margin-bottom: 12px;
}

.seo-content strong {
  color: var(--primary-color);
}

/* ===== Privacy Notice ===== */
.privacy-notice {
  background: #dbeafe;
  color: #1e40af;
  padding: 12px 20px;
  border-radius: var(--border-radius);
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.privacy-badge {
  background: #1e40af;
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  padding: 24px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.card h2,
.card h3 {
  margin-bottom: 16px;
  color: var(--text-color);
}

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

.preview-info {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Input Groups ===== */
.input-group {
  margin-bottom: 16px;
}

input[type="file"] {
  display: none;
}

.file-label {
  display: inline-block;
  padding: 12px 24px;
  background: var(--primary-color);
  color: white;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: background 0.2s;
  font-weight: 500;
}

.file-label:hover {
  background: var(--primary-hover);
}

textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  resize: vertical;
  transition: border-color 0.2s;
}

textarea:focus {
  outline: none;
  border-color: var(--primary-color);
}

.divider {
  text-align: center;
  color: var(--text-muted);
  margin: 20px 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border-color);
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

/* ===== Buttons ===== */
button {
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

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

.btn-secondary:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: #15803d;
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

/* ===== Template Buttons ===== */
.template-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Settings Grid ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.setting-item label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-color);
}

.setting-item select,
.setting-item input[type="text"] {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

.setting-item select:focus,
.setting-item input[type="text"]:focus {
  outline: none;
  border-color: var(--primary-color);
}

.setting-item input[type="checkbox"] {
  margin-right: 8px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ===== Alerts ===== */
.alert {
  padding: 16px 20px;
  border-radius: var(--border-radius);
  margin-bottom: 20px;
  border-left: 4px solid;
}

.alert strong {
  display: block;
  margin-bottom: 8px;
}

.alert ul {
  margin-left: 20px;
}

.alert li {
  margin-bottom: 4px;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border-color: var(--error-color);
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border-color: var(--warning-color);
}

/* ===== Format Detection ===== */
.format-info {
  background: #dcfce7;
  color: #166534;
  padding: 12px 16px;
  border-radius: var(--border-radius);
  margin-top: 16px;
  font-weight: 500;
}

#detectedFormat {
  font-weight: 700;
  text-transform: uppercase;
}

/* ===== Preview Table ===== */
.table-wrapper {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  background: var(--bg-color);
  position: sticky;
  top: 0;
}

th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-color);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
  background: var(--bg-color);
}

.preview-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  margin-top: 12px;
}

/* ===== Field Mapping ===== */
#mappingFields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.mapping-row {
  display: grid;
  grid-template-columns: 40px 1fr 150px 40px;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--bg-color);
  border-radius: var(--border-radius);
  transition: opacity 0.2s;
}

.field-index {
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
}

.field-name,
.field-type {
  padding: 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.9rem;
}

.field-name:focus,
.field-type:focus {
  outline: none;
  border-color: var(--primary-color);
}

.btn-remove {
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--danger-color);
  color: white;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-remove:hover {
  background: #b91c1c;
}

/* ===== Export Section ===== */
.export-options {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.export-options label {
  font-weight: 500;
}

.export-options select {
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: 0.95rem;
}

.export-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.export-info {
  background: #dcfce7;
  color: #166534;
  padding: 16px;
  border-radius: var(--border-radius);
  margin-top: 20px;
}

.export-info strong {
  display: block;
  margin-bottom: 12px;
}

#exportDetails div {
  margin-bottom: 6px;
}

/* ===== How to Use Section ===== */
.how-to-use {
  background: var(--card-bg);
  padding: 32px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  margin-top: 40px;
}

.how-to-use h2 {
  color: var(--text-color);
  margin-bottom: 24px;
  font-size: 1.8rem;
  border-bottom: 3px solid var(--primary-color);
  padding-bottom: 12px;
}

.step {
  margin-bottom: 32px;
  padding: 20px;
  background: var(--bg-color);
  border-radius: var(--border-radius);
  border-left: 4px solid var(--primary-color);
}

.step h3 {
  color: var(--primary-color);
  margin-bottom: 12px;
  font-size: 1.3rem;
}

.step p {
  margin-bottom: 12px;
  color: var(--text-color);
}

.step ul {
  margin-left: 20px;
  color: var(--text-color);
}

.step li {
  margin-bottom: 10px;
  line-height: 1.6;
}

.step code {
  background: var(--card-bg);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  color: var(--primary-color);
  border: 1px solid var(--border-color);
}

.step strong {
  color: var(--text-color);
}

/* ===== Footer ===== */
footer {
  background: var(--card-bg);
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  margin-top: auto;
}

footer a {
  color: var(--primary-color);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ===== Utility Classes ===== */
.hidden {
  display: none !important;
}

/* ===== Google AdSense Containers ===== */
.ad-container {
  width: 100%;
  margin: 24px auto;
  text-align: center;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-color);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.ad-top {
  margin-top: 20px;
  margin-bottom: 20px;
}

.ad-middle {
  margin: 30px auto;
}

.ad-before-howto {
  margin: 30px auto;
}

.ad-container ins {
  display: block;
  width: 100%;
}

/* ===== Responsive Design ===== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
  .container {
    max-width: 100%;
    padding: 30px 20px;
  }

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

  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 8px;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .container {
    padding: 20px 16px;
  }

  header h1 {
    font-size: 1.8rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .lang-toggle {
    top: 10px;
    right: 10px;
  }

  .seo-content {
    padding: 16px;
  }

  .seo-content h2 {
    font-size: 1.1rem !important;
  }

  .seo-content p {
    font-size: 0.9rem;
  }

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

  .mapping-row {
    grid-template-columns: 30px 1fr;
    gap: 8px;
  }

  .field-type,
  .btn-remove {
    grid-column: 2;
  }

  .export-actions {
    flex-direction: column;
  }

  /* AdSense responsive adjustments for mobile */
  .ad-container {
    margin: 16px auto;
    min-height: 60px;
  }

  .ad-top {
    margin-top: 16px;
    margin-bottom: 16px;
  }

  .ad-middle,
  .ad-before-howto {
    margin: 20px auto;
  }

  .export-actions button {
    width: 100%;
  }

  .template-buttons {
    flex-direction: column;
  }

  .template-buttons button {
    width: 100%;
  }

  /* Better table scrolling on mobile */
  .table-wrapper {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 0.8rem;
    min-width: 500px;
  }

  th, td {
    padding: 6px 8px;
  }

  .preview-info {
    font-size: 0.85rem;
  }

  .card {
    padding: 16px;
  }

  .privacy-notice {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  /* How to Use responsive */
  .how-to-use {
    padding: 20px;
  }

  .how-to-use h2 {
    font-size: 1.5rem;
  }

  .step {
    padding: 16px;
  }

  .step h3 {
    font-size: 1.1rem;
  }

  .step ul {
    margin-left: 16px;
  }
}

/* Small mobile (< 480px) */
@media (max-width: 480px) {
  header h1 {
    font-size: 1.5rem;
  }

  .lang-toggle button {
    padding: 6px 12px;
    font-size: 0.9rem;
  }

  .file-label {
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  button {
    padding: 8px 16px;
    font-size: 0.9rem;
  }

  .card h2, .card h3 {
    font-size: 1.1rem;
  }

  textarea {
    font-size: 0.85rem;
  }
}

/* ===== Loading Animation ===== */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ===== Print Styles ===== */
@media print {
  .lang-toggle,
  .card:not(#previewPanel),
  footer {
    display: none;
  }

  .container {
    max-width: 100%;
  }
}
