/* ═══════════════════════════════════════════════════════════════════════════
   AmericasNLP Annotator — Stylesheet
   Mobile-first, no external dependencies
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --color-primary:    #2D6A4F;
  --color-primary-d:  #1B4332;
  --color-primary-l:  #40916C;
  --color-accent:     #95D5B2;
  --color-warn:       #F4A261;
  --color-danger:     #E63946;
  --color-info:       #4895EF;
  --color-success:    #2D6A4F;

  --color-bg:         #F4F7F5;
  --color-surface:    #FFFFFF;
  --color-border:     #D1E0D8;
  --color-text:       #1A2E22;
  --color-muted:      #6B8C7A;

  --radius:           8px;
  --shadow:           0 2px 8px rgba(0,0,0,.10);
  --shadow-md:        0 4px 16px rgba(0,0,0,.14);

  --font-body:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono:        'Courier New', Courier, monospace;

  --max-w:            1200px;
  --header-h:         60px;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

img { max-width: 100%; height: auto; display: block; }

ul, ol { padding-left: 1.4rem; }

/* ─── Layout ────────────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 1rem;
}

.site-main {
  flex: 1;
  padding: 1.5rem 0 3rem;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--color-primary-d);
  color: #fff;
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-inner {
  display: flex;
  align-items: center;
  height: 100%;
  gap: 1rem;
}

.site-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  text-decoration: none;
}

.site-nav {
  display: none;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.site-nav.is-open { display: flex; }

.site-nav a {
  color: rgba(255,255,255,.85);
  font-size: .9rem;
  padding: .25rem .5rem;
  border-radius: 4px;
  transition: background .15s;
  text-decoration: none;
}

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

.nav-user {
  color: rgba(255,255,255,.7);
  font-size: .85rem;
  text-decoration: none;
}
.nav-user:hover { color: #fff; text-decoration: underline; }
.nav-user small { margin-left: .25rem; }

/* Language switcher */
.lang-switch {
  display: flex;
  gap: 2px;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.lang-btn {
  padding: .2rem .55rem;
  font-size: .75rem;
  font-weight: 700;
  color: rgba(255,255,255,.7);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.lang-btn:hover { color: #fff; background: rgba(255,255,255,.15); text-decoration: none; }
.lang-btn--active { background: rgba(255,255,255,.25); color: #fff; }

.nav-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  padding: .25rem;
}

@media (min-width: 768px) {
  .nav-toggle  { display: none; }
  .site-nav    { display: flex !important; }
}

/* Mobile nav overlay */
@media (max-width: 767px) {
  .site-nav.is-open {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    background: var(--color-primary-d);
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    gap: .75rem;
    box-shadow: var(--shadow-md);
    z-index: 99;
  }
}

/* ─── Footer ────────────────────────────────────────────────────────────────── */
.site-footer {
  background: var(--color-primary-d);
  color: rgba(255,255,255,.6);
  font-size: .8rem;
  padding: 1rem 0;
  text-align: center;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  text-decoration: none;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}
.btn--primary:hover {
  background: var(--color-primary-d);
  color: #fff;
  text-decoration: none;
}

.btn--outline {
  background: transparent;
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.btn--outline:hover {
  background: var(--color-primary);
  color: #fff;
  text-decoration: none;
}

.btn--ghost {
  background: transparent;
  color: var(--color-muted);
}
.btn--ghost:hover {
  background: var(--color-border);
  text-decoration: none;
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn--danger:hover { background: #c1121f; text-decoration: none; }

.btn--sm  { padding: .3rem .75rem; font-size: .8rem; }
.btn--full { width: 100%; justify-content: center; }

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .9rem;
}
.alert--info    { background: #e0f0ff; color: #1a5276; border-left: 4px solid var(--color-info); }
.alert--success { background: #d4edda; color: #155724; border-left: 4px solid var(--color-success); }
.alert--warning { background: #fff3cd; color: #856404; border-left: 4px solid var(--color-warn); }
.alert--danger  { background: #fce4e4; color: #7b1a1a; border-left: 4px solid var(--color-danger); }

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-weight: 600;
  font-size: .9rem;
  color: var(--color-text);
}

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

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: .6rem .8rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: var(--font-body);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary-l);
  box-shadow: 0 0 0 3px rgba(64,145,108,.2);
}

textarea { resize: vertical; min-height: 120px; line-height: 1.5; }

.req { color: var(--color-danger); }
.select-sm { width: auto; padding: .3rem .6rem; font-size: .85rem; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
}

.form-row .form-group { flex: 1 1 180px; margin-bottom: 0; }
.form-row .form-group--action { flex: 0 0 auto; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.5rem;
}

.form-inline { /* admin form-row wrapper */ }

.info-line {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  margin-bottom: 1rem;
  font-size: .9rem;
}

/* ─── Auth pages ─────────────────────────────────────────────────────────────── */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--color-primary-d) 0%, var(--color-primary) 100%);
}

.auth-card {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo h1 {
  font-size: 1.5rem;
  color: var(--color-primary);
}

.auth-logo p {
  color: var(--color-muted);
  font-size: .9rem;
  margin-top: .25rem;
}

.auth-form .btn { margin-top: .5rem; }

/* ─── Page header ────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h2 {
  font-size: 1.4rem;
  color: var(--color-primary-d);
}

.page-actions { display: flex; gap: .75rem; flex-wrap: wrap; }

/* ─── Panel ──────────────────────────────────────────────────────────────────── */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.panel h3 {
  font-size: 1.05rem;
  margin-bottom: 1rem;
  color: var(--color-primary-d);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.panel-header h3 { margin-bottom: 0; }

/* ─── Dashboard stats — Admin ────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-card h3 {
  font-size: 1rem;
  color: var(--color-primary-d);
  margin-bottom: .75rem;
}

.stat-card h3 small { color: var(--color-muted); font-weight: 400; }

.stat-numbers {
  display: flex;
  gap: 1.5rem;
  margin-bottom: .75rem;
}

.stat-item { text-align: center; }
.stat-value { display: block; font-size: 1.8rem; font-weight: 700; color: var(--color-primary); }
.stat-label { font-size: .75rem; color: var(--color-muted); }

.progress-bar-wrap {
  height: 8px;
  background: var(--color-border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: .25rem;
}

.progress-bar {
  height: 100%;
  background: var(--color-primary-l);
  border-radius: 4px;
  transition: width .4s;
}

/* ─── Dashboard stats — Annotator ────────────────────────────────────────────── */
.annotator-stats {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.astat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .75rem 1.25rem;
  text-align: center;
  min-width: 80px;
}

.astat-value { display: block; font-size: 1.6rem; font-weight: 700; }
.astat-label { font-size: .75rem; color: var(--color-muted); }

.astat--done  .astat-value { color: var(--color-primary); }
.astat--half  .astat-value { color: var(--color-info); }
.astat--draft .astat-value { color: var(--color-warn); }
.astat--todo  .astat-value { color: var(--color-muted); }

/* ─── Filter tabs ────────────────────────────────────────────────────────────── */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1.25rem;
}

.filter-tab {
  padding: .35rem .9rem;
  border-radius: 20px;
  border: 1.5px solid var(--color-border);
  font-size: .85rem;
  color: var(--color-muted);
  text-decoration: none;
  transition: all .15s;
}

.filter-tab:hover, .filter-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  text-decoration: none;
}

/* ─── Image grid ─────────────────────────────────────────────────────────────── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

@media (min-width: 480px) {
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

@media (min-width: 900px) {
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

.img-card {
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow .15s, transform .15s;
}

.img-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.img-card--done  { border-color: var(--color-primary-l); }
.img-card--half  { border-color: var(--color-info); }
.img-card--draft { border-color: var(--color-warn); }

.img-card-link { display: block; text-decoration: none; color: inherit; }

.img-thumb-wrap {
  position: relative;
  aspect-ratio: 4/3;
  background: var(--color-bg);
  overflow: hidden;
}

.img-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.img-status-overlay {
  position: absolute;
  top: .4rem;
  left: .4rem;
}

.img-upload-badge {
  position: absolute;
  bottom: .4rem;
  right: .4rem;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-warn);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-upload-badge--admin { background: var(--color-info); }

.img-card-body {
  padding: .5rem .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.img-key { font-size: .75rem; font-weight: 600; color: var(--color-muted); font-family: var(--font-mono); }

/* ─── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  border-radius: 12px;
  font-size: .7rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge--draft { background: #fff3cd; color: #856404; }
.badge--half  { background: #d0e8ff; color: #0b4f9a; }
.badge--done  { background: #d4edda; color: #155724; }
.badge--todo  { background: #f0f0f0; color: #666; }
.badge--admin { background: #d0e8ff; color: #0b4f9a; }
.badge--user  { background: #fde8d0; color: #7b4200; }
.badge--annotator  { background: #e8d4f0; color: #5a1a7b; }
.badge--lang_admin { background: #d4f0e8; color: #155724; }

/* ─── Annotation layout ───────────────────────────────────────────────────────── */
.annotate-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 900px) {
  .annotate-layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.annotate-image-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.img-frame {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.annotate-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  max-height: 65vh;
}

.img-meta {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .85rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .25rem;
}

.img-meta p { color: var(--color-muted); }
.img-meta strong { color: var(--color-text); }

/* ─── Guidelines box ──────────────────────────────────────────────────────────── */
.guidelines-box {
  background: #f0f9f4;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  font-size: .85rem;
}

.guidelines-box summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--color-primary-d);
  list-style: none;
  padding: .1rem 0;
}

.guidelines-box summary::before { content: '▶ '; font-size: .75rem; }
.guidelines-box[open] summary::before { content: '▼ '; }

.guidelines-box ol {
  margin-top: .75rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  color: var(--color-text);
}

.guidelines-panel .guidelines-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  font-size: .9rem;
}

/* ─── Step indicator ──────────────────────────────────────────────────────────── */
.step-indicator {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: .5rem;
}

.step {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--color-muted);
  flex: 1;
}

.step--active { color: var(--color-primary); }
.step--done   { color: var(--color-primary-l); }

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.step--active .step-num { background: var(--color-primary); color: #fff; }
.step--done   .step-num { background: var(--color-primary-l); color: #fff; }

.step-label { font-size: .85rem; font-weight: 600; }

.step-connector {
  flex: 0 0 2rem;
  height: 2px;
  background: var(--color-border);
}

/* ─── Timer ───────────────────────────────────────────────────────────────────── */
.timer-display {
  display: inline-block;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: .15rem .6rem;
  font-size: .8rem;
  font-family: var(--font-mono);
  color: var(--color-muted);
  margin-bottom: .25rem;
  align-self: flex-start;
}

/* ─── Step 1 preview ──────────────────────────────────────────────────────────── */
.step1-preview {
  background: #f0f9f4;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
  font-size: .9rem;
}

.step1-preview blockquote {
  margin: .5rem 0;
  padding-left: .75rem;
  border-left: 3px solid var(--color-primary-l);
  color: var(--color-text);
  font-style: italic;
}

/* ─── Complete view ───────────────────────────────────────────────────────────── */
.annotation-complete {
  text-align: center;
  padding: 1rem;
}

.complete-icon {
  font-size: 3rem;
  color: var(--color-primary-l);
  margin-bottom: .5rem;
}

.review-item {
  text-align: left;
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin: .75rem 0;
}

.review-item label {
  font-weight: 700;
  font-size: .85rem;
  color: var(--color-muted);
  display: block;
  margin-bottom: .3rem;
}

.review-item p { color: var(--color-text); }
.review-item small { color: var(--color-muted); font-size: .78rem; }

.question-display {
  background: #fff8e1;
  border: 1px solid var(--color-warn);
  border-radius: var(--radius);
  padding: .6rem .9rem;
  font-size: .85rem;
  margin-bottom: 1rem;
}

/* ─── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table th {
  text-align: left;
  padding: .6rem .75rem;
  background: var(--color-bg);
  color: var(--color-muted);
  font-weight: 700;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #f9fbfa; }
.empty-cell { text-align: center; color: var(--color-muted); padding: 2rem; }

/* ─── Tab bar ─────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1.5rem;
}

.tab {
  padding: .6rem 1.25rem;
  font-weight: 600;
  font-size: .9rem;
  color: var(--color-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  text-decoration: none;
  transition: all .15s;
}

.tab:hover { color: var(--color-primary); text-decoration: none; }

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* ─── Upload drop zone ────────────────────────────────────────────────────────── */
.upload-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .upload-container { grid-template-columns: 2fr 1fr; }
}

.drop-zone {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--color-bg);
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--color-primary-l);
  background: #f0f9f4;
}

.drop-zone-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.drop-zone-text { color: var(--color-muted); font-size: .9rem; pointer-events: none; }

.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .75rem;
}

.file-preview img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

/* ─── Annotations filter bar ─────────────────────────────────────────────────── */
.filter-bar { margin-bottom: 1rem; }
.filter-bar-inner { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }

.caption-cell { max-width: 220px; font-size: .82rem; }

/* ─── Code block ──────────────────────────────────────────────────────────────── */
.code-block {
  background: #1a2e22;
  color: #95D5B2;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: .82rem;
  overflow-x: auto;
  line-height: 1.6;
}

/* ─── Misc ────────────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-muted);
  grid-column: 1/-1;
}

.empty-state a { color: var(--color-primary-l); }
.muted { color: var(--color-muted); }

.annotate-form-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
