/* ── Colour tokens ── */
:root {
  --bg-page:         #f3f2ef;
  --bg-surface:      #ffffff;
  --bg-muted:        #fafafa;
  --text-primary:    #1d1d1d;
  --text-muted:      #444444;
  --text-faint:      #c0c0c0;
  --border-strong:   #dddddd;
  --border-light:    #e8e8e8;
  --label-color:     #666666;
  --hint-color:      #aaaaaa;
  --radio-border:    #cccccc;
  --radio-text:      #555555;
  --panel-h2-color:  #555555;
  --btn-clear-bg:    #f0f0f0;
  --btn-clear-fg:    #555555;
  --btn-clear-hover: #e0e0e0;
  --preview-strong:  #111111;
  --preview-em:      #888888;
  --preview-hr:      #e5e5e5;
  --preview-h3:      #888888;
  --shadow:          rgba(0,0,0,0.10);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-page:         #111111;
    --bg-surface:      #1e1e1e;
    --bg-muted:        #181818;
    --text-primary:    #e0e0e0;
    --text-muted:      #b0b0b0;
    --text-faint:      #444444;
    --border-strong:   #2e2e2e;
    --border-light:    #2e2e2e;
    --label-color:     #888888;
    --hint-color:      #555555;
    --radio-border:    #3a3a3a;
    --radio-text:      #aaaaaa;
    --panel-h2-color:  #888888;
    --btn-clear-bg:    #2a2a2a;
    --btn-clear-fg:    #aaaaaa;
    --btn-clear-hover: #333333;
    --preview-strong:  #eeeeee;
    --preview-em:      #777777;
    --preview-hr:      #2e2e2e;
    --preview-h3:      #666666;
    --shadow:          rgba(0,0,0,0.40);
  }
}

[data-theme="dark"] {
  --bg-page:         #111111;
  --bg-surface:      #1e1e1e;
  --bg-muted:        #181818;
  --text-primary:    #e0e0e0;
  --text-muted:      #b0b0b0;
  --text-faint:      #444444;
  --border-strong:   #2e2e2e;
  --border-light:    #2e2e2e;
  --label-color:     #888888;
  --hint-color:      #555555;
  --radio-border:    #3a3a3a;
  --radio-text:      #aaaaaa;
  --panel-h2-color:  #888888;
  --btn-clear-bg:    #2a2a2a;
  --btn-clear-fg:    #aaaaaa;
  --btn-clear-hover: #333333;
  --preview-strong:  #eeeeee;
  --preview-em:      #777777;
  --preview-hr:      #2e2e2e;
  --preview-h3:      #666666;
  --shadow:          rgba(0,0,0,0.40);
}

[data-theme="light"] {
  --bg-page:         #f3f2ef;
  --bg-surface:      #ffffff;
  --bg-muted:        #fafafa;
  --text-primary:    #1d1d1d;
  --text-muted:      #444444;
  --text-faint:      #c0c0c0;
  --border-strong:   #dddddd;
  --border-light:    #e8e8e8;
  --label-color:     #666666;
  --hint-color:      #aaaaaa;
  --radio-border:    #cccccc;
  --radio-text:      #555555;
  --panel-h2-color:  #555555;
  --btn-clear-bg:    #f0f0f0;
  --btn-clear-fg:    #555555;
  --btn-clear-hover: #e0e0e0;
  --preview-strong:  #111111;
  --preview-em:      #888888;
  --preview-hr:      #e5e5e5;
  --preview-h3:      #888888;
  --shadow:          rgba(0,0,0,0.10);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  background: #0a66c2;
  color: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
header svg { flex-shrink: 0; }
header h1 { font-size: 19px; font-weight: 600; }
header p  { font-size: 12px; opacity: 0.82; margin-top: 2px; }

#headerActions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#themeBtn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
#themeBtn:hover { background: rgba(255,255,255,0.25); }

/* ── Toolbar ── */
.toolbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-strong);
  padding: 8px 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 20px;
  flex-shrink: 0;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.toolbar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--label-color);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.format-switch { display: flex; gap: 6px; }
.format-opt input[type="radio"] { display: none; }
.format-opt span {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--radio-border);
  font-size: 13px;
  color: var(--radio-text);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.format-opt input[type="radio"]:checked + span {
  background: #0a66c2;
  border-color: #0a66c2;
  color: #fff;
  font-weight: 600;
}
.format-opt span:hover { border-color: #0a66c2; color: #0a66c2; }
.format-opt input[type="radio"]:checked + span:hover { color: #fff; }

#sourceSelect {
  padding: 5px 28px 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--radio-border);
  font-size: 13px;
  color: var(--radio-text);
  background-color: var(--bg-surface);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.15s;
}
#sourceSelect:hover { border-color: #0a66c2; color: #0a66c2; }
#sourceSelect:focus { border-color: #0a66c2; }

/* ── Three-column layout ── */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  align-items: stretch;
  gap: 16px;
  padding: 16px 20px;
  max-width: 1800px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr 1fr; }
  #previewPanel { grid-column: 1 / -1; }
}
@media (max-width: 680px) {
  main { grid-template-columns: 1fr; }
}

/* ── Panels ── */
.panel {
  background: var(--bg-surface);
  border-radius: 10px;
  box-shadow: 0 1px 3px var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.panel-header h2 {
  font-size: 11px;
  font-weight: 700;
  color: var(--panel-h2-color);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}
.panel-header .hint {
  font-size: 11px;
  color: var(--hint-color);
}
.panel-footer {
  padding: 9px 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Textarea ── */
textarea {
  flex: 1;
  min-height: 0;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px;
  font-family: "Courier New", Courier, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-muted);
  background: var(--bg-muted);
}
textarea::placeholder { color: var(--text-faint); }

/* ── Markdown source panel ── */
#output {
  flex: 1;
  min-height: 0;
  padding: 14px 16px;
  font-family: "Courier New", Courier, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  overflow-y: auto;
  background: var(--bg-muted);
}
#output.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  font-style: italic;
  white-space: normal;
  text-align: center;
}

/* ── Preview panel ── */
#preview {
  flex: 1;
  min-height: 0;
  padding: 20px 22px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-primary);
}
#preview.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-style: italic;
  font-size: 13px;
}

#preview h2 {
  font-size: 17px;
  font-weight: 700;
  color: #0a66c2;
  margin-bottom: 4px;
  line-height: 1.3;
}
#preview h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--preview-h3);
  margin: 18px 0 10px;
}
#preview hr {
  border: none;
  border-top: 1px solid var(--preview-hr);
  margin: 14px 0;
}
#preview p { margin: 0 0 8px; }
#preview strong {
  color: var(--preview-strong);
  font-weight: 700;
}
#preview em {
  color: var(--preview-em);
  font-style: normal;
  font-size: 12px;
}

#preview.full-log hr + p strong,
#preview.full-log h2 + p + hr + p strong { display: block; }

/* ── Buttons ── */
button {
  padding: 7px 16px;
  border-radius: 6px;
  border: none;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#convertBtn { background: #0a66c2; color: #fff; }
#convertBtn:hover { background: #004182; }
#clearBtn { background: var(--btn-clear-bg); color: var(--btn-clear-fg); }
#clearBtn:hover { background: var(--btn-clear-hover); }
#sampleBtn {
  background: transparent;
  color: var(--hint-color);
  border: 1.5px dashed var(--border-strong);
}
#sampleBtn:hover { border-color: #0a66c2; color: #0a66c2; background: transparent; }

#copyBtn, #copyPreviewBtn {
  background: #057642; color: #fff;
  margin-left: auto;
}
#copyBtn:hover, #copyPreviewBtn:hover { background: #045730; }
#copyBtn:disabled, #copyPreviewBtn:disabled { opacity: 0.35; cursor: default; }

.status { font-size: 11px; color: var(--hint-color); }
.auto-detect-badge {
  font-size: 11px;
  font-weight: 700;
  color: #0a66c2;
  white-space: nowrap;
}

/* ── Privacy modal ── */
#privacyOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#privacyOverlay.open { display: flex; }

#privacyDialog {
  background: var(--bg-surface);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  max-width: 560px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#privacyDialog header {
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#privacyDialog header h2 {
  font-size: 16px;
  font-weight: 700;
  flex: 1;
}
#privacyCloseBtn {
  background: var(--btn-clear-bg);
  color: var(--btn-clear-fg);
  border: none;
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
#privacyCloseBtn:hover { background: var(--btn-clear-hover); }

#privacyBody {
  overflow-y: auto;
  padding: 20px 22px 24px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-muted);
}
#privacyBody h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--label-color);
  margin: 20px 0 8px;
}
#privacyBody h3:first-child { margin-top: 0; }
#privacyBody ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#privacyBody ul li::before {
  content: "✓ ";
  color: #057642;
  font-weight: 700;
}
#privacyBody details {
  border: 1px solid var(--border-light);
  border-radius: 7px;
  margin-bottom: 6px;
}
#privacyBody details + details { margin-top: 0; }
#privacyBody summary {
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-primary);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
#privacyBody summary::-webkit-details-marker { display: none; }
#privacyBody summary::after {
  content: "+";
  font-size: 16px;
  color: var(--hint-color);
  flex-shrink: 0;
}
#privacyBody details[open] summary::after { content: "−"; }
#privacyBody details p {
  padding: 0 14px 12px;
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

#privacyBtn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  white-space: nowrap;
}
#privacyBtn:hover { background: rgba(255,255,255,0.25); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 22px; right: 22px;
  background: #057642;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  z-index: 999;
}
#toast.show { opacity: 1; }
