/*============================================
  Image Converter App – Refactored CSS
  Notes:
  - Fixed invalid properties & typos
  - Removed conflicting/duplicate rules
  - Consolidated breakpoints
  - Added CSS variables for theming
  - Improved dark-mode contrast
  - Resolved z-index overlaps
  - Mobile-first friendly
=============================================*/

/*------------------------
  0. Theme Variables
------------------------*/
:root {
  --bg: #f5f7fa;
  --text: #222;
  --primary: #007bff;
  --primary-600: #0056b3;
  --surface: #ffffff;
  --muted: #666;
  --border: #ccc;

  /* Dark */
  --dark-bg: #121212;
  --dark-text: #e0e0e0;
  --dark-surface: #1e1e1e;
  --dark-border: #444;
  --danger: #d00;
}

/*------------------------
  1. Base / Reset
------------------------*/
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  line-height: 1.6;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/*------------------------
  2. Accessibility
------------------------*/
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.focusable:focus {
  position: static;
  width: auto;
  height: auto;
  clip: auto;
  white-space: normal;
  outline: 2px solid var(--primary);
}

/*------------------------
  3. Header
------------------------*/
header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2rem;
  color: var(--primary);
  font-weight: 700;
}
.header-banner {
  text-align: center;
  width: 100%;
  max-width: 100%;
  margin-bottom: 1.5rem;
  padding: 0;
}

/* Responsive banner image */
.responsive-banner {
  width: 100%;       /* fills container */
  max-width: 1000px; /* original image width */
  height: auto;      /* maintains aspect ratio */
  display: block;
  margin: 0 auto;
}
/*------------------------
  4. Dark Mode Toggle
------------------------*/
#dark-mode-toggle-container {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 1rem;
}

#themeToggle { margin-right: 0.5rem; }

/*------------------------
  5. Drop Area
------------------------*/
#drop-area {
  width: 50%;
  margin: 0 auto 1rem;
  border: 2px dashed var(--primary);
  border-radius: 12px;
  background-color: #e6f0ff;
  text-align: center;
  padding: 2rem;
  transition: background-color 0.3s ease;
  cursor: pointer;
/* Show desktop text by default, hide mobile */
.mobile-text { display: none; }
.desktop-text { display: inline; }
}

#drop-area:hover,
#drop-area:focus,
#drop-area.dragover {
  background-color: #d0e6ff;
  outline: none;
}

#drop-area p {
  margin-bottom: 1rem;
  font-weight: bold;
  font-size: 1rem;
}

/* Hidden File Input */
input.hidden { display: none; }

/* Upload Spinner and Error */
#upload-spinner { font-size: 0.9rem; color: var(--muted); }
#error-message { color: var(--danger); margin-top: 0.5rem; }

/*------------------------
  6. Format Options
------------------------*/
fieldset {
  display: flex;
  justify-content: center;
  margin-left: auto;
  margin-right: auto;
  flex-wrap: wrap;
  gap: 1rem;
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  min-inline-size: min-content;
  max-width: 600px;
}

legend {
  font-weight: bold;
  color: #333;
  padding: 0 0.5rem;
}

fieldset label {
  margin-right: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

/* Improve checkbox consistency */
input[type="checkbox"] { accent-color: var(--primary); }

/*------------------------
  7. Buttons
------------------------*/
#convert-clear-container {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

button.action {
  background-color: var(--primary);
  color: #fff;
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

button.action:hover { background-color: var(--primary-600); }
button.action:active { transform: scale(0.98); }

/*------------------------
  8. File List
------------------------*/
#fileListTitle {
  display: block;
  text-align: center;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 1.1rem;
}

#file-list { margin-bottom: 0; }

#file-items {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start; /* single, consistent alignment */
}

#file-items > div {
  max-width: 100%;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background-color: #f9f9f9;
  border-radius: 4px;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  white-space: nowrap;
  flex: 1;
  padding-right: 1rem;
  vertical-align: middle;
}

/* Tooltip version */
.file-name.with-tooltip { position: relative; display: inline-block; cursor: help; }
.file-name.with-tooltip::after {
  content: attr(data-fullname);
  position: absolute;
  left: 0;
  bottom: 125%;
  background: #333;
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}
.file-name.with-tooltip:hover::after { opacity: 1; }

.delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  margin-left: 1rem;
}

/*------------------------
  9. Preview Section
------------------------*/
#preview { display: flex; flex-wrap: wrap; gap: 1rem; }

#preview img {
  flex: 1 1 50%; /* FIX: added semicolon, removed invalid flex-direction */
  max-width: 100%;
  max-height: 230px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 8px;
}

#list-preview-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 50%;
  margin: 0 auto 2rem auto;
  gap: 2rem;
  flex-wrap: wrap;
}

/*  summary */
.summary-container {
  max-width: 700px;
  margin: 1em auto;
  text-align: center;
  color: #121212; /* readable on light */
}

.summary-container details {
  background: #f7f7f7;
  border-radius: 0;
  padding: 1em;
  padding-bottom: 0; /* FIX: was paddingdown */
  transition: all 0.3s ease;
}

.summary-container summary {
  cursor: pointer;
  font-size: 1.15em;
  font-weight: 500;
  color: #121212;
  padding: 0.2em 0;
  list-style: none;
}

.summary-container summary::marker,
.summary-container summary::-webkit-details-marker { display: none; }

.summary-container p {
  margin-top: 0.75em;
  font-size: 0.95em;
  line-height: 1.6;
  color: #121212;
}

/*------------------------
  10. Footer
------------------------*/
footer#footerYear {
  display: flex;
  justify-content: center;
  padding: 0;
  font-size: 0.85rem;
  background: transparent;
  border-top: none;
}
.site-footer {
  background: #f9f9f9;
  border-top: 1px solid #ddd;
  padding: 1em 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 14px;
  color: #333;
}

.footer-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1em;
  flex-wrap: wrap;
}

.home-link {
  text-decoration: none;
  color: #1976D2;
  font-weight: 500;
}

.footer-links {
  list-style: none;
  display: flex;
  gap: 1em;
  padding: 0;
  margin: 0;
}

.footer-links a,
.footer-contact {
  text-decoration: none;
  color: #1976D2;
  font-weight: 500;
}

.footer-contact {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: #1976D2;
}

.footer-contact:hover,
.footer-links a:hover,
.home-link:hover {
  text-decoration: underline;
}

/* Keyboard focus */
.footer-links a:focus,
.footer-contact:focus,
.home-link:focus {
  outline: 2px solid #1976D2;
  outline-offset: 2px;
}

/* --- Responsive Layout for Small Screens (≤740px) --- */
@media (max-width: 740px) {
  .footer-container {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    gap: 1em;
  }

  .home-link {
    align-self: flex-start; /* keep Home left */
  }

  .footer-links {
    justify-content: center;
    flex-wrap: wrap;
  }

  .footer-container > span:last-child {
    text-align: center;
    margin-top: 1em;
    align-self: center;
  }
}
 
.home-link:hover { text-decoration: underline; }

/* === Contact Popup Styling === */
.contact-popup {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 320px;
  background: #f2f3f5;
  border-radius: 1rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  padding: 16px 18px;
  z-index: 9999; /* top-most */
  font-family: sans-serif;
}

.contact-popup.hidden { display: none; }

/* === Form === */
#contact-form { display: flex; flex-direction: column; gap: 12px; }

#contact-form label {
  font-size: 0.9rem;
  margin-bottom: 4px;
  font-weight: 600;
}

#contact-form input,
#contact-form textarea {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-size: 0.95rem;
  width: 100%;
  box-sizing: border-box;
}

#contact-form textarea {
  border-radius: 1rem;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}

/* === Email Row: Email + Button Side-by-Side === */
#contact-email,
#contact-send { margin-top: 6px; }

.email-row { display: flex; gap: 8px; align-items: stretch; }
.email-row input { flex: 1; }

#contact-send {
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background-color: var(--primary);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

#contact-send:hover { background-color: var(--primary-600); }

/* === Error Messages === */
.error-msg { color: #28a745; font-size: 0.85em; margin-top: -6px; margin-bottom: 4px; display: block; }
input.invalid, textarea.invalid { border: 2px solid red; outline: none; }

/* Message wrapper */
.message-wrapper { display: flex; align-items: stretch; background: #ffffff; border-radius: 999px; overflow: hidden; }
.message-wrapper textarea { flex-grow: 1; border: none; padding: 10px; font-size: 0.9rem; resize: none; background: transparent; }
.send-btn { width: 48px; font-size: 1.8rem; background: none; border: none; color: #007aff; cursor: pointer; padding-right: 8px; }

/* cookies */
.triangle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 0; height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 10px solid white;
  cursor: pointer;
  z-index: 9998; /* below popup */
}

.cookie-banner, .cookie-details {
  position: fixed;
  bottom: 60px;
  right: 16px;
  width: 100%;
  max-width: 300px; /* responsive fix */
  background: white;
  color: #333;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 9997; /* beneath triangle and popup */
}

.cookie-buttons { margin-top: 12px; display: flex; gap: 10px; }
.cookie-buttons button,
.cookie-details button { padding: 6px 12px; border: none; border-radius: 4px; font-size: 14px; cursor: pointer; }

#accept-btn { background-color: #2ecc71; color: white; }
#customize-btn,
.cookie-details button { background-color: #e67e22; color: white; }

.visible { opacity: 1; pointer-events: auto; }
.hidden { opacity: 0; pointer-events: none; }

/* === adsense === */
.adsense-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  text-align: center;
  overflow: hidden; /* prevent overflow from iframe */
}

.adsense-container ins.adsbygoogle,
.adsense-container iframe {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important; /* optional, if you want responsive height */
}


/*------------------------
  11. Dark Mode
------------------------*/
body.dark { background-color: var(--dark-bg); color: var(--dark-text); }
body.dark header h1 { color: #66aaff; }

body.dark #drop-area { background-color: var(--dark-surface); border-color: #66aaff; color: #ccc; }
body.dark fieldset { border-color: var(--dark-border); }

body.dark button.action { background-color: #66aaff; color: #000; }
body.dark button.action:hover { background-color: #3399ff; }

body.dark #file-items > div,
body.dark #preview img { background-color: #222; border-color: var(--dark-border); }
body.dark .delete-btn { color: #ff6666; }

/* Dark mode for summary */
body.dark .summary-container { color: var(--dark-text); }
body.dark .summary-container details { background: var(--dark-surface); }
body.dark .summary-container p,
body.dark .summary-container summary { color: var(--dark-text); }

/*------------------------
  12. Responsive (Consolidated)
  Mobile-first: tighten small screens, scale up progressively
------------------------*/

/* Extra Small Phones (≤400px) */
@media (max-width: 400px) {
  body { padding: 0.5rem; }
  header h1 { font-size: 1.25rem; }

  #drop-area { width: 90%; padding: 0.8rem; font-size: 0.9rem; }
  .desktop-text { display: none; }
  .mobile-text { display: inline; }
  #convert-clear-container { flex-direction: column; gap: 0.5rem; }

  #preview img { max-width: 80px; max-height: 80px; }
  #file-items > div { font-size: 0.8rem; padding: 0.3rem 0.5rem; }

  #list-preview-wrapper {
    flex-direction: column;
    width: 100%;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 1rem;
  }

  #file-list, #preview {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 0;
  }

  footer#footerYear { flex-direction: column; text-align: center; gap: 0.8em; }

  .cookie-banner, .cookie-details { width: 90%; right: 8px; font-size: 14px; }
  .triangle { right: 8px; bottom: 8px; }
}

/* Small Phones & Small Tablets (≤600px) */
@media (max-width: 600px) {
  header h1 { font-size: 1.4rem; }
  #drop-area { width: 90%; padding: 1rem; }
  #convert-clear-container { flex-direction: column; }
  #preview img { max-width: 90px; max-height: 90px; }
  #file-items > div { font-size: 0.85rem; }
  .desktop-text { display: none; }
  .mobile-text { display: inline; }
  #list-preview-wrapper {
    flex-direction: column;
    width: 100%;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  #file-list, #preview {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}

/* Tablets Portrait (≤768px) */
@media (max-width: 768px) {
  #drop-area { width: 70%; }
  #preview img { max-width: 150px; max-height: 150px; }
  #file-items > div { font-size: 0.95rem; }
}

/* Tablets Landscape & Small Laptops (≤1024px) */
@media (max-width: 1024px) {
  #drop-area { width: 60%; }
  #preview img { max-width: 180px; max-height: 180px; }
}

/* Medium Laptops / Desktop (1025px–1199px) */
@media (min-width: 1025px) and (max-width: 1199px) {
  #drop-area { width: 50%; }
  #preview img { max-width: 220px; max-height: 220px; }
}

/* Large Desktops (≥1200px) */
@media (min-width: 1200px) {
  #drop-area { width: 40%; }
  #preview img { max-width: 250px; max-height: 250px; }
}

/* Extra Large Desktops (≥1440px) */
@media (min-width: 1440px) {
  #drop-area { width: 35%; }
  #preview img { max-width: 300px; max-height: 300px; }
}

/* Ads container – corrected breakpoint to match comment */
@media (min-width: 775px) {
  .adsense-container {
    text-align: center;
    margin: 20px auto;
    width: 775px;
    max-width: 100%;
  }
}

@media (max-width: 600px) {
  .responsive-banner {
    max-width: 100%; /* ensures no overflow on tiny screens */
  }
}
