/* ============================================================
   Markah — Mobile-First CSS
   ============================================================ */

:root {
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #EFF6FF;
  --success: #16A34A;
  --success-light: #F0FDF4;
  --warning: #D97706;
  --warning-light: #FFFBEB;
  --error: #DC2626;
  --error-light: #FEF2F2;
  --surface: #F8FAFC;
  --card: #FFFFFF;
  --text: #1E293B;
  --text-muted: #64748B;
  --border: #E2E8F0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --nav-h: 64px;
  --header-h: 56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  padding-top: var(--header-h);
  padding-bottom: calc(var(--nav-h) + 16px);
  min-height: 100vh;
}

/* ── Header ── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}
.header-back {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none;
  color: var(--primary); font-size: 20px; cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  text-decoration: none;
}
.header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  padding: 8px 4px;
  border: none;
  background: none;
  cursor: pointer;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 22px; height: 22px; stroke-width: 1.8; }

/* ── Container ── */
.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* ── Form Elements ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px; /* prevents iOS zoom */
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-textarea { resize: vertical; min-height: 120px; }

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-sm {
  min-height: 36px;
  padding: 8px 14px;
  font-size: 14px;
  width: auto;
}

/* ── Upload Area ── */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-area input[type="file"] { display: none; }
.upload-icon { font-size: 36px; margin-bottom: 8px; }
.upload-label { font-size: 15px; font-weight: 600; color: var(--text); }
.upload-hint { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Camera / Gallery Buttons ── */
.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.photo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 80px;
  padding: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: border-color .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.photo-btn:hover { border-color: var(--primary); color: var(--primary); }
.photo-btn .photo-icon { font-size: 28px; }
.photo-btn input[type="file"] { display: none; }

/* ── Thumbnail Grid ── */
.thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.thumb-item {
  position: relative;
  width: 80px; height: 80px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.thumb-item img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.thumb-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,.65);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

/* ── Score Badge ── */
.score-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 72px; height: 72px;
  border-radius: 50%;
  font-weight: 700;
  flex-shrink: 0;
}
.score-badge .score-val { font-size: 20px; line-height: 1; }
.score-badge .score-max { font-size: 11px; opacity: .8; }
.score-badge.green { background: var(--success-light); color: var(--success); }
.score-badge.amber { background: var(--warning-light); color: var(--warning); }
.score-badge.red { background: var(--error-light); color: var(--error); }

/* ── Criteria Bar ── */
.criteria-list { display: flex; flex-direction: column; gap: 10px; }
.criterion-row {}
.criterion-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.criterion-name { font-size: 13px; font-weight: 600; }
.criterion-score { font-size: 13px; font-weight: 700; color: var(--primary); }
.criterion-bar-bg {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.criterion-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .5s ease;
}
.criterion-feedback { font-size: 12px; color: var(--text-muted); }

/* ── Essay Cards ── */
.essay-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  transition: border-color .15s;
}
.essay-card.approved { border-color: var(--success); }
.essay-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.essay-name { font-size: 15px; font-weight: 600; flex: 1; }
.essay-id { font-size: 12px; color: var(--text-muted); }
.essay-score-mini {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.essay-status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.essay-status-dot.draft { background: var(--warning); }
.essay-status-dot.approved { background: var(--success); }
.essay-card-body {
  padding: 0 16px 16px;
  display: none;
}
.essay-card.open .essay-card-body { display: block; }
.essay-chevron {
  font-size: 18px;
  color: var(--text-muted);
  transition: transform .2s;
}
.essay-card.open .essay-chevron { transform: rotate(180deg); }

/* ── Alert / Notice ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}
.alert-warning { background: var(--warning-light); color: var(--warning);        border: 1px solid #FDE68A; }
.alert-error   { background: var(--error-light);   color: var(--error);          border: 1px solid #FECACA; }
.alert-success { background: var(--success-light); color: var(--success);        border: 1px solid #BBF7D0; }
.alert-info    { background: var(--primary-light); color: var(--primary);        border: 1px solid #BFDBFE; }

/* ── Loading Spinner ── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner.dark {
  border-color: rgba(37,99,235,.2);
  border-top-color: var(--primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Overlay Loader ── */
.overlay-loader {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
}
.overlay-loader .loader-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 36px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.overlay-loader .loader-icon { font-size: 36px; margin-bottom: 8px; }
.overlay-loader .loader-text { font-size: 15px; font-weight: 600; color: var(--text); }
.overlay-loader .loader-sub  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Tag ── */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.tag-blue   { background: var(--primary-light); color: var(--primary); }
.tag-green  { background: var(--success-light); color: var(--success); }
.tag-amber  { background: var(--warning-light); color: var(--warning); }

/* ── Divider ── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Stats Row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Step Indicator ── */
.step-indicator {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.step-circle {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.step-circle.done   { background: var(--success); color: #fff; }
.step-circle.active { background: var(--primary); color: #fff; }
.step-circle.future { background: var(--border); color: var(--text-muted); }
.step-label { font-size: 11px; color: var(--text-muted); }
.step-line { flex: 1; height: 2px; background: var(--border); margin-top: -20px; }
.step-line.done { background: var(--success); }

/* ── Editable score input ── */
.score-input {
  width: 60px;
  padding: 6px 10px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}
.score-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Strengths / Improvements ── */
.feedback-list { list-style: none; padding: 0; }
.feedback-list li {
  padding: 6px 0 6px 22px;
  position: relative;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.feedback-list li:last-child { border-bottom: none; }
.feedback-list li::before {
  content: attr(data-icon);
  position: absolute;
  left: 0;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .25s ease, toast-out .25s ease 2.75s forwards;
  pointer-events: all;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--error); }
.toast.warning { background: var(--warning); }
@keyframes toast-in  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; } }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state-text  { font-size: 14px; }

/* ── Tablet/Desktop ── */
@media (min-width: 768px) {
  .container { padding: 24px; }
  .photo-actions { grid-template-columns: repeat(3, 1fr); }
  .stats-row { grid-template-columns: repeat(4, 1fr); }
}

/* ── Dark Mode ── */
/* Applied when OS prefers dark OR when [data-theme="dark"] is set on <html>. */
/* The manual toggle in app.js writes data-theme so the user can override the OS. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface:        #0F172A;
    --card:           #1E293B;
    --text:           #F1F5F9;
    --text-muted:     #94A3B8;
    --border:         #334155;
    --primary-light:  #1E3A5F;
    --success-light:  #14532D;
    --warning-light:  #78350F;
    --error-light:    #7F1D1D;
    --shadow:         0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-md:      0 4px 6px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
  }
}

[data-theme="dark"] {
  --surface:        #0F172A;
  --card:           #1E293B;
  --text:           #F1F5F9;
  --text-muted:     #94A3B8;
  --border:         #334155;
  --primary-light:  #1E3A5F;
  --success-light:  #14532D;
  --warning-light:  #78350F;
  --error-light:    #7F1D1D;
  --shadow:         0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md:      0 4px 6px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
}

/* ── Pill Group (exam type / part selector) ── */
.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pill {
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}
.pill:hover { border-color: var(--primary); color: var(--primary); }
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Annotated Essay (error highlighting) ── */
.annotated-essay {
  font-size: 14px;
  line-height: 1.9;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.annotated-essay .err {
  color: var(--error);
  font-weight: 600;
  text-decoration: underline wavy var(--error);
  text-underline-offset: 3px;
}

/* ── CEFR Badge ── */
.cefr-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary);
  gap: 4px;
}

/* ── Lifting Warning ── */
.lifting-warning {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  background: var(--warning-light);
  color: var(--warning);
  border: 1px solid #FDE68A;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
}

/* ── Question photo upload (compact) ── */
.upload-area-sm {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface);
  font-size: 14px;
  color: var(--text-muted);
}
.upload-area-sm:hover { border-color: var(--primary); color: var(--primary); }
.upload-area-sm input[type="file"] { display: none; }

/* ── Dark Mode Toggle Button ── */
.dark-toggle {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none;
  font-size: 20px; cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  color: var(--text-muted);
  margin-left: auto;
  -webkit-tap-highlight-color: transparent;
}
.dark-toggle:hover { color: var(--text); }
