/* --- MODERN UI OVERHAUL --- */

/* --- CSS VARIABLES & GLOBAL STYLES --- */
:root {
  --primary-color: #0d2137; /* Deeper, more professional blue */
  --accent-color: #10b981;  /* Vibrant, modern green for accents */
  --bg-color: #f4f7f9;      /* Light, clean background */
  --surface-color: #ffffff; /* For cards, editors, etc. */
  --text-color: #2d3748;    /* Softer, high-contrast dark gray */
  --light-text-color: #f0f4f8;
  --border-color: #e2e8f0;
  --shadow-color: rgba(45, 55, 72, 0.1);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
  --border-radius: 8px;
  --transition-speed: 0.2s ease-in-out;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--bg-color);
  font-size: clamp(15px, 1.5vw, 16px);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- ACCESSIBILITY & HEADER --- */
.skip-link {
  position: absolute; top: -50px; left: 0;
  background: var(--primary-color); color: var(--light-text-color);
  padding: 10px 15px; z-index: 1000; transition: top var(--transition-speed);
  border-bottom-right-radius: var(--border-radius);
}
.skip-link:focus { top: 0; }

header {
  position: sticky; top: 0; width: 100%;
  background-color: var(--surface-color);
  padding: 1rem 2rem; z-index: 999;
  box-shadow: 0 2px 4px var(--shadow-color);
  border-bottom: 1px solid var(--border-color);
}
.nav-container {
  display: flex; justify-content: space-between; align-items: center;
  max-width: 1400px; margin: 0 auto;
}
.logo {
  font-size: 1.25rem; font-weight: 700; color: var(--primary-color);
  text-decoration: none; display: flex; align-items: center; gap: 0.75rem;
}
.logo i { color: var(--accent-color); }
nav ul { display: flex; list-style: none; gap: 0.5rem; }
nav li { margin: 0; }
nav a {
  color: var(--text-color); text-decoration: none;
  font-weight: 600; padding: 0.5rem 1rem;
  border-radius: var(--border-radius); transition: all var(--transition-speed);
  position: relative;
}
nav a:hover, nav a:focus { background-color: #eef2f6; color: var(--primary-color); outline: none; }
.menu-toggle { display: none; background: none; border: none; color: var(--primary-color); font-size: 1.5rem; cursor: pointer; }

/* --- MAIN CONTENT & LAYOUT --- */
main {
  padding: 2rem; max-width: 1400px; margin: 2.5rem auto;
  display: flex; flex-direction: column; gap: 2rem; width: 100%;
}
h1 {
  text-align: center; color: var(--primary-color); font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 800; margin-bottom: 1rem; letter-spacing: -1px;
}

/* --- ACTION BUTTONS & STATUS --- */
.button-group {
  display: flex; flex-wrap: wrap; gap: 1rem;
  justify-content: center; margin-bottom: 1.5rem;
}
button {
  padding: 12px 24px; font-size: 1rem; font-weight: 600;
  background-color: var(--primary-color);
  color: var(--light-text-color); border: 2px solid var(--primary-color);
  border-radius: var(--border-radius); cursor: pointer;
  box-shadow: 0 4px 6px -1px var(--shadow-color), 0 2px 4px -1px rgba(0,0,0,0.06);
  transition: all var(--transition-speed);
  display: flex; align-items: center; gap: 0.5rem;
}
button:hover {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px var(--shadow-color), 0 4px 6px -2px rgba(0,0,0,0.05);
}
button:focus-visible {
  outline: 3px solid var(--accent-color);
  outline-offset: 2px;
}
#clearBtn { background-color: #a0aec0; border-color: #a0aec0; }
#clearBtn:hover { background-color: #e53e3e; border-color: #e53e3e; }

#statusMessage {
  text-align: center; font-weight: 600; min-height: 1.5rem;
  padding: 0.75rem; border-radius: var(--border-radius);
  transition: all var(--transition-speed);
}
.status-success { background-color: #e6fffa; color: #2c7a7b; border: 1px solid #b2f5ea; }
.status-error { background-color: #fed7d7; color: #c53030; border: 1px solid #feb2b2; }
.status-info { background-color: #bee3f8; color: #2b6cb0; border: 1px solid #90cdf4; }

/* --- FOUR-SECTION CARD LAYOUT --- */
.converter-container {
  display: flex; flex-wrap: wrap; gap: 2rem; align-items: flex-start;
}
.converter-section {
  flex: 1 1 calc(50% - 1rem); min-width: 320px;
  background: var(--surface-color);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 12px var(--shadow-color);
  padding: 1.5rem;
  display: flex; flex-direction: column; gap: 1.5rem;
  transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}
.converter-section:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 10px 20px var(--shadow-color);
}

/* --- EDITOR STYLES --- */
.editor {
  border: 1px solid var(--border-color); background: var(--surface-color); min-height: 220px;
  padding: 1rem; border-radius: var(--border-radius); font-size: 1rem;
  line-height: 1.7; overflow-y: auto; position: relative; outline: none;
  transition: all var(--transition-speed);
}
.editor:focus, .editor.active {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}
.editor:empty::before {
  content: attr(data-placeholder);
  position: absolute; top: 1rem; left: 1rem;
  color: #a0aec0; pointer-events: none; font-style: italic;
}
.char-counter {
  text-align: right; font-size: 0.85rem;
  color: #718096; margin-top: 0.5rem;
}

/* --- OUTPUT & TABS STYLES --- */
.output-section { display: none; }
.output-section.visible { display: block; }
h2 {
  font-size: 1.2rem; color: var(--primary-color); font-weight: 700;
  border-bottom: 2px solid var(--border-color); padding-bottom: 0.5rem; margin-bottom: 1rem;
}
.output-tabs {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}
.tab-button {
  padding: 0.75rem 1rem; background: transparent; border: none;
  color: #718096; cursor: pointer; font-weight: 600;
  transition: all var(--transition-speed);
  border-bottom: 3px solid transparent; position: relative; top: 1px;
}
.tab-button:hover { color: var(--primary-color); background-color: #edf2f7; }
.tab-button.active {
  color: var(--primary-color);
  border-bottom-color: var(--accent-color);
}
.tab-content { display: none; margin-top: 1rem; }
.tab-content.active { display: block; }

pre {
  background-color: #2d3748; color: var(--light-text-color);
  border: 1px solid #4a5568; padding: 1.25rem;
  border-radius: var(--border-radius); white-space: pre-wrap; word-wrap: break-word;
  cursor: pointer; font-family: var(--font-mono); font-size: 0.9rem;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); transition: all var(--transition-speed);
  max-height: 300px; overflow-y: auto;
}
pre:hover { border-color: var(--accent-color); }

/* --- MODAL & TOOLTIP --- */
.preview-modal {
  display: none; position: fixed; top: 0; left: 0;
  width: 100%; height: 100%; background-color: rgba(13, 33, 55, 0.8);
  z-index: 2000; justify-content: center; align-items: center; padding: 2rem;
  backdrop-filter: blur(5px);
}
.preview-modal-content {
  background-color: var(--surface-color); border-radius: var(--border-radius);
  padding: 2.5rem; max-width: 800px; width: 100%; max-height: 80vh;
  overflow-y: auto; position: relative;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.close-preview {
  position: absolute; top: 1rem; right: 1rem; background: none;
  border: none; font-size: 1.75rem; cursor: pointer; color: #a0aec0;
  transition: all var(--transition-speed);
}
.close-preview:hover { color: var(--primary-color); transform: rotate(90deg); }
.tooltip { position: relative; display: inline-block; }
.tooltip .tooltiptext {
  visibility: hidden; width: 120px; background-color: var(--primary-color);
  color: var(--light-text-color); text-align: center;
  border-radius: var(--border-radius); padding: 0.5rem; position: absolute;
  z-index: 1; bottom: 125%; left: 50%; margin-left: -60px;
  opacity: 0; transition: opacity var(--transition-speed); font-size: 0.8rem;
}
.tooltip:hover .tooltiptext { visibility: visible; opacity: 1; }

/* --- RESPONSIVE STYLES --- */
@media (max-width: 992px) {
  .converter-section {
     flex-basis: 100%;
  }
}
@media (max-width: 768px) {
  main { padding: 1.5rem 1rem; }
  h1 { font-size: 2rem; }
  .menu-toggle { display: block; }
  nav ul {
    display: none; flex-direction: column; position: absolute;
    top: 100%; left: 0; width: 100%; background-color: var(--surface-color);
    padding: 1rem; box-shadow: 0 4px 12px var(--shadow-color);
    border-top: 1px solid var(--border-color);
  }
  nav ul.active { display: flex; }
  nav li { margin: 0; width: 100%; }
  nav a { display: block; text-align: center; color: var(--text-color); }
}


/* --- DARK MODE & THEME TOGGLE STYLES --- */

.theme-toggle {
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--border-radius);
  transition: all var(--transition-speed);
  margin-left: auto; /* Pushes it to the right */
  margin-right: 1rem; /* Space before menu button */
}
.theme-toggle:hover {
  background-color: #eef2f6;
  color: var(--accent-color);
  transform: scale(1.1) rotate(15deg);
}

@media (max-width: 768px) {
  .theme-toggle {
    margin-right: 0.5rem; /* Adjust spacing on mobile */
  }
}

/* === DARK THEME STYLES === */
body.dark-mode {
  /* Redefine variables for dark mode */
  --primary-color: #63b3ed;     /* Lighter blue for text/accents */
  --bg-color: #1a202c;         /* Very dark slate background */
  --surface-color: #2d3748;    /* Darker slate for cards/editors */
  --text-color: #f7fafc;       /* Off-white text */
  --border-color: #4a5568;
  --shadow-color: rgba(0, 0, 0, 0.2);
}

/* Override specific elements for dark mode */
body.dark-mode header,
body.dark-mode .converter-section,
body.dark-mode .preview-modal-content {
  background-color: var(--surface-color);
  color: var(--text-color);
  border-color: var(--border-color);
}
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode .logo,
body.dark-mode .theme-toggle,
body.dark-mode .menu-toggle {
  color: var(--text-color);
}
body.dark-mode .logo i {
  color: var(--accent-color);
}
body.dark-mode nav ul {
  background-color: var(--surface-color);
}
body.dark-mode nav a {
  color: var(--text-color);
}
body.dark-mode nav a:hover, 
body.dark-mode nav a:focus {
  background-color: #4a5568;
}
body.dark-mode button {
  background-color: var(--surface-color);
  color: var(--text-color);
  border-color: var(--border-color);
}
body.dark-mode button:hover {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
  color: #1a202c;
}
body.dark-mode #clearBtn {
  background-color: #718096;
  border-color: #718096;
}
body.dark-mode #clearBtn:hover {
  background-color: #e53e3e;
  border-color: #e53e3e;
}
body.dark-mode .editor {
  background-color: #1a202c; /* Slightly darker than card */
  color: var(--text-color);
  border-color: var(--border-color);
}
body.dark-mode .editor:focus, 
body.dark-mode .editor.active {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}
body.dark-mode .editor:empty::before {
  color: #718096;
}
body.dark-mode pre {
  background-color: #1a202c;
  color: #d1d5db;
  border-color: #4a5568;
}
body.dark-mode pre:hover {
  border-color: var(--accent-color);
}
body.dark-mode .tab-button {
  color: #a0aec0;
}
body.dark-mode .tab-button.active,
body.dark-mode .tab-button:hover {
  color: var(--text-color);
}
body.dark-mode .status-success { background-color: #2f4948; color: #9ae6b4; border-color: #48bb78; }
body.dark-mode .status-error { background-color: #522a2a; color: #feb2b2; border-color: #c53030; }
body.dark-mode .status-info { background-color: #2c4962; color: #90cdf4; border-color: #4299e1; }

/* --- MODAL, TOOLTIP & FOOTER --- */
/* ... (existing modal and tooltip styles) ... */

footer {
  background-color: var(--primary-color);
  color: #a0aec0; /* Muted text color */
  text-align: center;
  padding: 2rem 1.5rem;
  margin-top: 3rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  transition: background-color var(--transition-speed);
}
.copyright p {
  margin: 0;
  font-size: 0.9rem;
}

/* Add this to the existing dark mode styles at the bottom of your CSS file */
body.dark-mode footer {
  background-color: #1a202c; /* Matches dark mode background */
  border-top: 1px solid var(--border-color);
}
