/* ===================================================================
   OMJ Question Converter — Main Stylesheet
   Professional teacher-facing authoring tool
   =================================================================== */

/* ─── CSS Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-primary:    #1a56db;
  --clr-primary-dk: #1240a8;
  --clr-secondary:  #374151;
  --clr-accent:     #0e9f6e;
  --clr-danger:     #e02424;
  --clr-warning-bg: #fffbeb;
  --clr-warning:    #d97706;
  --clr-error-bg:   #fff5f5;
  --clr-valid:      #0e9f6e;
  --clr-bg:         #f3f4f6;
  --clr-surface:    #ffffff;
  --clr-border:     #e5e7eb;
  --clr-text:       #111827;
  --clr-text-muted: #6b7280;
  --clr-header-bg:  #1e3a5f;
  --clr-sidebar-bg: #f9fafb;
  --radius:         6px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,.12);
  --font-sans:      'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:      'Consolas', 'Monaco', 'Courier New', monospace;
  --sidebar-width:  260px;
  --header-height:  56px;
}

html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--clr-header-bg);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

.app-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}

.app-logo img { width: 28px; height: 28px; }

.app-logo-badge {
  background: var(--clr-primary);
  font-size: .65rem;
  padding: 2px 6px;
  border-radius: 20px;
  font-weight: 600;
  letter-spacing: .04em;
  margin-left: .25rem;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: 2rem;
  flex: 1;
}

.header-nav a {
  color: rgba(255,255,255,.85);
  padding: .35rem .75rem;
  border-radius: var(--radius);
  font-size: .875rem;
  transition: background .15s;
}

.header-nav a:hover,
.header-nav a.active {
  background: rgba(255,255,255,.15);
  color: #fff;
  text-decoration: none;
}

.privacy-notice {
  font-size: .72rem;
  color: rgba(255,255,255,.6);
  margin-left: auto;
  white-space: nowrap;
}

.privacy-notice span { color: var(--clr-accent); }

/* ─── Layout ─────────────────────────────────────────────────────── */
.app-body {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

.app-sidebar {
  width: var(--sidebar-width);
  background: var(--clr-sidebar-bg);
  border-right: 1px solid var(--clr-border);
  position: fixed;
  top: var(--header-height);
  bottom: 0;
  overflow-y: auto;
  padding: 1rem .75rem;
  z-index: 50;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ─── Section pages ─────────────────────────────────────────────── */
.app-section {
  padding: 1.25rem;
  flex: 1;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--clr-secondary);
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--clr-border);
  padding-bottom: .5rem;
}

/* ─── Profile selector ───────────────────────────────────────────── */
.profile-selector {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.profile-btn {
  padding: .45rem 1.1rem;
  border-radius: 20px;
  border: 2px solid var(--clr-border);
  background: var(--clr-surface);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 600;
  transition: all .15s;
  color: var(--clr-secondary);
}

.profile-btn:hover { border-color: var(--clr-primary); color: var(--clr-primary); }
.profile-btn.active {
  background: var(--clr-primary);
  border-color: var(--clr-primary);
  color: #fff;
}

/* ─── Profile sub-options ────────────────────────────────────────── */
.profile-suboptions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  padding: .75rem;
  background: #eef2ff;
  border-radius: var(--radius);
  border: 1px solid #c7d2fe;
  align-items: center;
}

.profile-suboptions label {
  font-size: .8rem;
  font-weight: 600;
  color: #4338ca;
  white-space: nowrap;
}

.profile-suboptions select {
  padding: .3rem .6rem;
  border-radius: var(--radius);
  border: 1px solid #c7d2fe;
  font-size: .875rem;
}

/* ─── Tab switcher ───────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--clr-border);
  margin-bottom: 1rem;
}

.tab-btn {
  padding: .6rem 1.1rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .875rem;
  color: var(--clr-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-weight: 500;
  transition: all .15s;
}

.tab-btn:hover { color: var(--clr-primary); }
.tab-btn.active {
  color: var(--clr-primary);
  border-bottom-color: var(--clr-primary);
  font-weight: 700;
}

.tab-pane { display: block; }

/* ─── Three-column workspace ─────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: 220px 1fr 1fr;
  gap: 1rem;
  height: calc(100vh - var(--header-height) - 180px);
  min-height: 400px;
}

.workspace-col {
  background: var(--clr-surface);
  border-radius: var(--radius);
  border: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.workspace-col-header {
  padding: .6rem .875rem;
  border-bottom: 1px solid var(--clr-border);
  background: #f8fafc;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--clr-text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.workspace-col-body {
  flex: 1;
  overflow-y: auto;
  padding: .875rem;
}

/* ─── Question list ──────────────────────────────────────────────── */
#question-list {
  list-style: none;
}

.q-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .6rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .83rem;
  margin-bottom: .2rem;
  transition: background .1s;
}

.q-list-item:hover { background: #f0f4ff; }
.q-list-item.active { background: #e0eaff; }

.q-list-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.empty-list { color: var(--clr-text-muted); font-size: .85rem; padding: .5rem 0; }

/* ─── Question reorder buttons ───────────────────────────────────── */
.q-reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-right: .35rem;
  flex-shrink: 0;
}

.q-reorder-btn {
  background: none;
  border: 1px solid var(--clr-border);
  border-radius: 3px;
  padding: 0 3px;
  font-size: .65rem;
  line-height: 1.3;
  cursor: pointer;
  color: var(--clr-text-muted);
  transition: background .1s, color .1s;
}

.q-reorder-btn:hover:not(:disabled) {
  background: #e0eaff;
  color: var(--clr-primary);
  border-color: var(--clr-primary);
}

.q-reorder-btn:disabled {
  opacity: .3;
  cursor: default;
}

/* ─── Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: .65rem;
  font-weight: 700;
  flex-shrink: 0;
}

.badge-valid   { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-error   { background: #fee2e2; color: #991b1b; }

.badge-profile {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 12px;
  background: var(--clr-primary);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
}

/* ─── Editor form ────────────────────────────────────────────────── */
.form-group {
  margin-bottom: .875rem;
}

.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--clr-secondary);
  margin-bottom: .3rem;
}

.form-group label.required::after {
  content: ' *';
  color: var(--clr-danger);
}

.form-group label small {
  font-weight: 400;
  color: var(--clr-text-muted);
}

.form-group input[type="text"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .4rem .65rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  font-size: .875rem;
  font-family: var(--font-sans);
  transition: border-color .15s;
  background: var(--clr-surface);
}

.form-group input[type="text"]:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 2px rgba(26,86,219,.15);
}

.form-group textarea {
  resize: vertical;
  min-height: 70px;
}

/* Options grid */
.options-group { margin-bottom: 1rem; }
.options-grid { display: flex; flex-direction: column; gap: .4rem; }
.option-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.option-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--clr-primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.option-row input {
  flex: 1;
  padding: .35rem .6rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  font-size: .875rem;
}

/* Advanced collapsible */
.advanced-section { margin-top: .75rem; }
.advanced-toggle {
  cursor: pointer;
  font-size: .8rem;
  color: var(--clr-primary);
  font-weight: 600;
  padding: .35rem 0;
  user-select: none;
}
.advanced-toggle:hover { text-decoration: underline; }
.advanced-content { padding-top: .5rem; }

/* Inline action buttons */
.form-actions-inline {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: .75rem;
  border-top: 1px solid var(--clr-border);
}

/* ─── Buttons ─────────────────────────────────────────────────────── */
.btn-primary, .btn-secondary, .btn-danger, .btn-outline {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}

.btn-primary  { background: var(--clr-primary); color: #fff; }
.btn-primary:hover  { background: var(--clr-primary-dk); }
.btn-secondary { background: #e5e7eb; color: var(--clr-secondary); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger   { background: var(--clr-danger); color: #fff; }
.btn-danger:hover { opacity: .88; }
.btn-outline  { background: transparent; color: var(--clr-primary); border: 1px solid var(--clr-primary); }
.btn-outline:hover { background: #eff6ff; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

button:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Upload zone ─────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--clr-border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--clr-primary);
  background: #eff6ff;
}

.upload-zone-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.upload-zone p { font-size: .9rem; color: var(--clr-text-muted); }
.upload-zone strong { color: var(--clr-primary); }

.upload-status {
  margin-top: .75rem;
  padding: .5rem .875rem;
  border-radius: var(--radius);
  font-size: .875rem;
}

.upload-status.success { background: #d1fae5; color: #065f46; }
.upload-status.warning { background: #fef3c7; color: #92400e; }
.upload-status.error   { background: #fee2e2; color: #991b1b; }
.upload-status.parsing { background: #e0e7ff; color: #3730a3; }

/* ─── Paste editor ───────────────────────────────────────────────── */
#paste-textarea {
  width: 100%;
  height: 320px;
  font-family: var(--font-mono);
  font-size: .82rem;
  padding: .75rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  resize: vertical;
  line-height: 1.5;
}

.paste-actions {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
}

/* ─── Preview card ───────────────────────────────────────────────── */
.preview-card {
  background: #fafafa;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 1rem;
}

.preview-meta {
  display: flex;
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}

.preview-section {
  font-size: .75rem;
  background: #e0e7ff;
  color: #3730a3;
  padding: 1px 8px;
  border-radius: 12px;
}

.preview-id { font-size: .75rem; color: var(--clr-text-muted); margin-bottom: .5rem; }
.preview-title { font-weight: 600; font-size: .9rem; margin-bottom: .5rem; color: var(--clr-secondary); }
.preview-passage { font-style: italic; margin-bottom: .5rem; background: #f0f4ff; padding: .5rem; border-radius: 4px; }
.preview-question { font-size: 1rem; margin-bottom: .75rem; font-weight: 500; }

.preview-options { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .75rem; }
.preview-option {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .4rem .6rem;
  border-radius: var(--radius);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
}

.preview-option.is-answer {
  background: #f0fdf4;
  border-color: #86efac;
}

.opt-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e5e7eb;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.preview-option.is-answer .opt-key {
  background: var(--clr-accent);
  color: #fff;
}

.correct-marker {
  font-size: .72rem;
  color: var(--clr-accent);
  font-weight: 700;
  margin-left: auto;
}

.preview-option-img {
  max-width: 120px;
  max-height: 80px;
  border-radius: 3px;
}

.preview-answer {
  font-size: .82rem;
  padding: .35rem .6rem;
  background: #ecfdf5;
  border-radius: var(--radius);
  margin-bottom: .5rem;
}

.preview-audio {
  margin-bottom: .5rem;
}

.preview-audio audio { display: block; margin-top: .3rem; }

.media-path {
  font-size: .75rem;
  color: var(--clr-text-muted);
  font-family: var(--font-mono);
}

.media-warn {
  font-size: .78rem;
  color: var(--clr-warning);
  display: block;
}

.preview-explanation {
  font-size: .85rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: .5rem .6rem;
  margin-bottom: .5rem;
}

.preview-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
}

/* ─── Validation panel ───────────────────────────────────────────── */
.validation-summary {
  padding: .65rem .875rem;
  border-radius: var(--radius);
  margin-bottom: .75rem;
  font-size: .875rem;
}

.status-valid   { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.status-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.status-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

.vs-counts { display: flex; gap: .75rem; margin-top: .25rem; font-size: .8rem; }
.err-count  { color: var(--clr-danger); font-weight: 700; }
.warn-count { color: var(--clr-warning); font-weight: 700; }

.issue-list { list-style: none; display: flex; flex-direction: column; gap: .35rem; }
.issue-error   { background: #fff5f5; border-left: 3px solid var(--clr-danger); padding: .4rem .6rem; border-radius: 0 var(--radius) var(--radius) 0; font-size: .82rem; }
.issue-warning { background: #fffbeb; border-left: 3px solid var(--clr-warning); padding: .4rem .6rem; border-radius: 0 var(--radius) var(--radius) 0; font-size: .82rem; }

.issue-icon { font-weight: 700; margin-right: .3rem; }
.all-clear { color: var(--clr-valid); font-weight: 600; font-size: .9rem; }
.error-list { list-style: none; display: flex; flex-direction: column; gap: .3rem; }
.error-list li { font-size: .82rem; color: var(--clr-danger); }

/* ─── JSON preview ───────────────────────────────────────────────── */
#json-preview {
  display: block;
  font-family: var(--font-mono);
  font-size: .78rem;
  line-height: 1.5;
  background: #1e2433;
  color: #e2e8f0;
  padding: .875rem;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 400px;
  white-space: pre;
  tab-size: 2;
}

.export-controls {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: .75rem;
}

.export-filename-group {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.export-filename-group label { font-size: .8rem; font-weight: 600; white-space: nowrap; }
.export-filename-group input {
  padding: .35rem .6rem;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  font-size: .875rem;
  width: 260px;
}

/* ─── Template library ───────────────────────────────────────────── */
.template-group {
  margin-bottom: 1.5rem;
}

.template-group-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--clr-secondary);
  margin-bottom: .75rem;
  padding-bottom: .35rem;
  border-bottom: 2px solid var(--clr-border);
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .75rem;
}

.template-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .875rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s;
}

.template-card:hover { box-shadow: var(--shadow-md); }

.template-card-title {
  font-weight: 700;
  font-size: .9rem;
  margin-bottom: .25rem;
}

.template-card-meta {
  font-size: .75rem;
  color: var(--clr-text-muted);
  margin-bottom: .5rem;
}

.template-card-desc {
  font-size: .82rem;
  color: var(--clr-secondary);
  margin-bottom: .75rem;
}

.template-card-actions { display: flex; gap: .5rem; }

/* ─── Help page ──────────────────────────────────────────────────── */
.help-content h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--clr-secondary);
  margin: 1.25rem 0 .5rem;
}

.help-content h3 {
  font-size: .95rem;
  font-weight: 700;
  margin: .875rem 0 .35rem;
}

.help-content p { font-size: .9rem; margin-bottom: .5rem; }
.help-content ul, .help-content ol { padding-left: 1.5rem; font-size: .9rem; }
.help-content li { margin-bottom: .25rem; }
.help-content code { font-family: var(--font-mono); font-size: .82rem; background: #f3f4f6; padding: 1px 5px; border-radius: 3px; }

.help-content pre {
  background: #1e2433;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: var(--radius);
  overflow: auto;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.6;
  margin: .75rem 0;
}

/* ─── Empty state ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--clr-text-muted);
  font-size: .9rem;
  padding: 2rem 1rem;
}

/* ─── Alerts ─────────────────────────────────────────────────────── */
.alert {
  padding: .65rem .875rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: .75rem;
}

.alert-info { background: #eff6ff; border-left: 3px solid var(--clr-primary); color: #1e3a8a; }
.alert-warning { background: var(--clr-warning-bg); border-left: 3px solid var(--clr-warning); color: #78350f; }

/* ─── Sidebar nav ────────────────────────────────────────────────── */
.sidebar-nav { list-style: none; }
.sidebar-nav li a {
  display: block;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--clr-secondary);
  transition: background .1s;
}

.sidebar-nav li a:hover { background: #e5e7eb; text-decoration: none; }
.sidebar-nav li a.active { background: #e0eaff; color: var(--clr-primary); font-weight: 600; }

.sidebar-section-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--clr-text-muted);
  padding: .75rem .75rem .25rem;
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .app-sidebar {
    width: 100%;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--clr-border);
    display: none; /* use header nav on mobile */
  }

  .app-main {
    margin-left: 0;
  }

  .header-nav { display: none; }
  .privacy-notice { display: none; }
}

@media (max-width: 600px) {
  .profile-selector { gap: .3rem; }
  .profile-btn { padding: .35rem .75rem; font-size: .8rem; }
  .export-filename-group input { width: 100%; }
  .export-controls { flex-direction: column; align-items: flex-start; }
}

/* ─── Scrollbars ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ─── Print ──────────────────────────────────────────────────────── */
@media print {
  .app-header, .app-sidebar, .tab-bar, .profile-selector,
  .form-actions-inline, .export-controls, .paste-actions { display: none !important; }
}
