/* --- Root Variables & Global Styles --- */
:root{
  --bg: #f6f8fb;
  --card: #fff;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --border-color: #e6e9ef;
  --success-color: #10b981; /* Green for success feedback */
}
*{box-sizing: border-box;}
body{
  font-family: 'Inter', system-ui, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: #0f172a;
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.app{
  width: 100%;
  max-width: 1080px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(2,6,23,0.08);
  padding: 24px;
  position: relative;
}

/* --- Dark Mode --- */
body.dark-mode {
  --bg: #121212;
  --card: #1e1e1e;
  --muted: #9e9e9e;
  --border-color: #333;
  color: #e0e0e0;
}
body.dark-mode .app { box-shadow: 0 8px 30px rgba(255,255,255,0.05); }
body.dark-mode button { background: #333; color: #fff; border-color: #444; }
body.dark-mode .primary { background: var(--accent); }
body.dark-mode .primary:hover {
  background: var(--accent-dark);
}
body.dark-mode .actions button:hover { background: #2a2a2a; }
body.dark-mode .actions button.success {
  background: var(--success-color);
}
body.dark-mode .history-panel { box-shadow: -4px 0 15px rgba(255,255,255,0.05); }
body.dark-mode .download-option {
  background: #2a2a2a;
  border-color: #444;
}

/* --- Header & Main Layout --- */
header { text-align: center; margin-bottom: 24px; position: relative; }
/* Typing Header Effect Styles */
header h1 {
  margin: 0;
  font-size: 1.5rem;
  min-height: 1.5rem;
}
@keyframes blink-caret {
  from,
  to {
    border-color: transparent;
  }
  50% {
    border-color: var(--accent);
  }
}
header p { margin: 6px 0 18px; color: var(--muted); }
.header-buttons { position: absolute; top: 20px; right: 20px; display: flex; gap: 8px; }
main { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.primary { background: var(--accent); color: #fff; border: none; padding: 10px 16px; border-radius: 8px; cursor: pointer; transition: background-color 0.2s; font-weight: 500; }
.primary:hover { background: #4338ca; }

/* Typing effect cursor */
#typing-header::after {
  content: "|";
  display: inline;
  animation: blink 0.7s infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* --- Left Panel: Uploader --- */
.uploader { padding: 20px; border-radius: 8px; border: 1px solid var(--border-color); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.input-options { display: flex; gap: 10px; margin-bottom: 20px; }
#previewWrap { color: var(--muted); }
#previewWrap img { width: 80px; margin-top: 15px; opacity: 0.5; }

/* --- Right Panel: Results --- */
.result-container { display: flex; flex-direction: column; gap: 18px; }
.result { display: flex; flex-direction: column; flex-grow: 1; }
/* Enforce max-height and scrolling */
.editable-div {
  flex-grow: 1;
  min-height: 250px;
  max-height: 400px; /* Fixed height for scrolling */
  padding: 12px;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--border-color);
  resize: none; /* Disable manual resize */
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
}
.editable-div:focus { outline: 2px solid var(--accent); border-color: transparent; }
.editable-div[placeholder]:empty:before { content: attr(placeholder); color: var(--muted); cursor: text; }
.editable-div a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.textarea-footer { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; background: var(--bg); border: 1px solid var(--border-color); border-top: none; border-radius: 0 0 8px 8px; }
.char-count { font-size: 0.8rem; color: var(--muted); }
.actions { display: flex; gap: 4px; }
.actions button {
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.2s ease;
  position: relative;
}
.actions button:hover { background: #e0e0e0; color: var(--accent); }
.actions button svg {
  fill: currentColor;
  width: 20px;
  height: 20px;
}

/* Button Feedback Styling */
.actions button.success {
  background: var(--success-color);
  color: white;
  border-radius: 8px;
  width: auto;
  padding: 0 10px;
}
.actions button.success span {
  margin-left: 5px;
  font-size: 0.85rem;
  font-weight: 600;
}
.actions button.success svg {
  width: 16px;
  height: 16px;
}

/* --- Translation Section --- */
.translation-section .full-width { width: 100%; }
.translation-output {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  margin-top: 8px;
  min-height: 80px;
  font-family: "Inter", Arial, sans-serif;
  font-size: 1em;
  white-space: pre-wrap;
}
.translation-output[placeholder]:empty:before { content: attr(placeholder); color: var(--muted); }

/* --- Modals, Loader, Toasts, History (as before, with minor tweaks) --- */
/* .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1500; display: none; align-items: center; justify-content: center; backdrop-filter: blur(5px); }
.modal-overlay.show { display: flex; }
.modal-content { background: var(--card); border-radius: 12px; padding: 20px; max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; }
.modal-content.small-modal {
  max-width: 400px;
} /* New: for download modal */
/* .modal-content h2 { margin: 0 0 15px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.cropper-container { max-width: 80vw; max-height: 70vh; }
#imageToCrop { display: block; max-width: 100%; }
#cameraFeed { border-radius: 8px; max-width: 100%; max-height: 65vh; } */ */

/* --- Download Modal Specifics --- */
.modal-content.download-content {
  max-width: 450px;
}

/* Download Modal Specific Styles */
.download-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 10px;
}
.download-option {
  background: var(--bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s, border-color 0.2s;
}
.download-option:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--card);
}
/* .download-option .icon {
  font-size: 2.5rem;
  margin-bottom: 5px;
}
body.dark-mode .download-option {
  background: #2a2a2a;
  border-color: #444;
}
body.dark-mode .download-option:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #1e1e1e;
} */

.download-option svg {
  width: 30px;
  height: 30px;
  margin-bottom: 5px;
  color: var(--accent);
}
.download-option .format-name {
  font-weight: 600;
  display: block;
}
.download-option .format-type {
  font-size: 0.75rem;
  color: var(--muted);
  display: block;
}


/* --- Modals, Loader, Toasts, History --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1500;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}
.modal-overlay.show {
  display: flex;
}
.modal-content {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-content h2 {
  margin: 0 0 15px 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.cropper-container {
  max-width: 80vw;
  max-height: 70vh;
}
#imageToCrop {
  display: block;
  max-width: 100%;
}
#cameraFeed {
  border-radius: 8px;
  max-width: 100%;
  max-height: 65vh;
}

.loader-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; display: none; align-items: center; justify-content: center; flex-direction: column; color: white; }
.loader-overlay.show { display: flex; }
.spinner { border: 4px solid #f3f3f3; border-top: 4px solid var(--accent); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin-bottom: 10px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; align-items: center; }
.toast { background-color: #2c3e50; color: white; padding: 12px 20px; border-radius: 8px; margin-top: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); opacity: 0; transform: translateY(20px); transition: all 0.3s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.history-panel { position: fixed; top: 0; right: -350px; width: 350px; height: 100%; background: var(--card); box-shadow: -4px 0 15px rgba(0,0,0,0.1); z-index: 1000; transition: right 0.3s ease-in-out; display: flex; flex-direction: column; }
.history-panel.show { right: 0; }
.history-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--border-color); }
#historyList { list-style: none; padding: 0; margin: 0; overflow-y: auto; flex-grow: 1; }
#historyList li { padding: 15px 20px; border-bottom: 1px solid var(--border-color); cursor: pointer; transition: background-color 0.2s; }
#historyList li:hover { background-color: var(--bg); }
#historyList .original-text, #historyList .translated-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#historyList .original-text { font-weight: 500; margin-bottom: 8px; color: var(--muted); }

/* --- Responsive Design --- */
@media(max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .app { padding: 15px; }
  .header-buttons { position: static; justify-content: center; margin-bottom: 15px; }
  .actions button {
    width: 36px;
    height: 36px;
  }
  .editable-div {
    max-height: 300px;
  }
}
