/* ============================================================
   CREPDL·CHECK  ·  Application Stylesheet
   ISO/IEC 19757-7:2020 Character Repertoire Validator

   Aesthetic: Precision instrument — structured, technical, authoritative.
   Fonts: DM Mono (code/technical) + DM Sans (UI prose)
   ============================================================ */

/* ── Design Tokens ──────────────────────────────────────────────────────────── */
:root {
  /* Ink scale */
  --ink-900:  #0d1117;
  --ink-700:  #1c2733;
  --ink-500:  #374151;
  --ink-400:  #4b5563;
  --ink-300:  #6b7280;
  --ink-200:  #9ca3af;
  --ink-100:  #d1d5db;
  --ink-050:  #f3f4f6;
  --ink-025:  #f9fafb;

  /* Brand blue */
  --blue-700: #1d4ed8;
  --blue-600: #2563eb;
  --blue-500: #3b82f6;
  --blue-100: #dbeafe;
  --blue-050: #eff6ff;

  /* Semantic */
  --green-700: #047857;
  --green-100: #d1fae5;
  --green-050: #ecfdf5;

  --red-700:   #b91c1c;
  --red-500:   #ef4444;
  --red-100:   #fee2e2;
  --red-050:   #fef2f2;

  --amber-700: #92400e;
  --amber-100: #fef3c7;
  --amber-050: #fffbeb;

  /* Surfaces */
  --surface:       #ffffff;
  --surface-subtle: #f8f9fb;
  --surface-muted: #f3f4f6;

  /* Typography */
  --font-ui:   'DM Sans', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'DM Mono', 'Cascadia Code', 'Fira Code', monospace;

  /* Geometry */
  --r-sm: 4px;
  --r:    6px;
  --r-lg: 10px;
  --r-xl: 14px;

  /* Shadows */
  --sh-xs: 0 1px 2px rgba(0,0,0,.05);
  --sh-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --sh:    0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
  --sh-lg: 0 10px 20px -3px rgba(0,0,0,.08), 0 4px 8px -2px rgba(0,0,0,.04);

  /* Focus */
  --focus-ring: 0 0 0 3px rgba(59,130,246,.35);
}

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

html {
  height: 100%;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  background: var(--surface-subtle);
  color: var(--ink-700);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Accessibility ──────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; top: -100%; left: 12px; z-index: 9999;
  padding: 8px 18px; background: var(--blue-600); color: #fff;
  font-size: 13px; font-weight: 600;
  border-radius: 0 0 var(--r) var(--r);
  text-decoration: none; transition: top .1s;
}
.skip-link:focus { top: 0; }

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}
button:focus:not(:focus-visible),
a:focus:not(:focus-visible) { outline: none; }

/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--surface-muted); }
::-webkit-scrollbar-thumb { background: var(--ink-100); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-200); }

/* ═══════════════════════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════════════════════════ */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ─── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--ink-100);
  padding: 0 24px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--sh-xs);
}

.brand-link {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; margin-right: 18px; flex-shrink: 0;
}

.brand-mark {
  width: 32px; height: 32px;
  background: var(--ink-900);
  border-radius: var(--r);
  display: flex; align-items: center; justify-content: center;
}
.brand-mark svg {
  width: 17px; height: 17px;
  fill: none; stroke: #fff;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.brand-name {
  font-family: var(--font-mono);
  font-size: 14px; font-weight: 500;
  color: var(--ink-900); letter-spacing: -.01em; line-height: 1;
}
.brand-name em { font-style: normal; color: var(--blue-600); }

.header-sep {
  width: 1px; height: 22px;
  background: var(--ink-100); margin: 0 16px;
}

.header-standard {
  font-family: var(--font-mono);
  font-size: 11px; color: var(--ink-300); letter-spacing: .03em;
  white-space: nowrap;
}

.header-spacer { flex: 1; }

/* Active repertoire badge */
.rep-badge {
  display: none; align-items: center; gap: 8px;
  background: var(--blue-050); border: 1px solid var(--blue-100);
  border-radius: 20px; padding: 5px 12px;
}
.rep-badge.visible { display: flex; }

.rep-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green-700); flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--green-100);
}
.rep-name {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  color: var(--blue-700); max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rep-count { font-size: 11px; color: var(--ink-300); white-space: nowrap; }

/* ─── Main layout ──────────────────────────────────────────────────────────── */
main { flex: 1; display: flex; flex-direction: column; }

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  min-height: 0;
}

@media (max-width: 940px) {
  .workspace { grid-template-columns: 1fr; }
  .input-col { border-right: none !important; border-bottom: 1px solid var(--ink-100); }
}

.input-col {
  background: var(--surface);
  border-right: 1px solid var(--ink-100);
  display: flex; flex-direction: column;
}

.output-col {
  background: var(--surface-subtle);
  display: flex; flex-direction: column; overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════
   PANELS
══════════════════════════════════════════════════════════════ */
.panel { padding: 20px 22px; }
.panel + .panel { border-top: 1px solid var(--ink-100); }
.panel-grow { flex: 1; display: flex; flex-direction: column; }

.panel-hd {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px; flex-wrap: wrap;
}

.panel-title {
  font-size: 11px; font-weight: 700;
  color: var(--ink-400);
  text-transform: uppercase; letter-spacing: .07em;
}

.panel-hd-gap { flex: 1; }

/* Status chip */
.status-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600;
  padding: 2px 10px; border-radius: 20px; white-space: nowrap;
}
.status-chip.loaded {
  background: var(--green-050); color: var(--green-700);
  border: 1px solid var(--green-100);
}
.status-chip.unloaded {
  background: var(--amber-050); color: var(--amber-700);
  border: 1px solid var(--amber-100);
}

/* ═══════════════════════════════════════════════════════════
   FORM ELEMENTS
══════════════════════════════════════════════════════════════ */
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.field-label {
  font-size: 12px; font-weight: 600; color: var(--ink-500);
  display: flex; align-items: center;
  justify-content: space-between; flex-wrap: wrap; gap: 4px;
}

.char-counter {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 400; color: var(--ink-200);
}

textarea {
  background: var(--surface); color: var(--ink-700);
  border: 1px solid var(--ink-100);
  border-radius: var(--r);
  padding: 10px 12px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.7;
  resize: vertical; width: 100%;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
textarea:hover { border-color: var(--ink-200); }
textarea:focus { border-color: var(--blue-500); box-shadow: var(--focus-ring); }
textarea::placeholder { color: var(--ink-100); }
textarea.grow { flex: 1; min-height: 160px; }

/* ═══════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 8px 14px;
  border: 1px solid transparent; border-radius: var(--r);
  font-family: var(--font-ui); font-size: 13px; font-weight: 600; line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .1s, border-color .1s, box-shadow .1s, transform .08s;
  -webkit-user-select: none; user-select: none;
}
.btn:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--blue-600); color: #fff; border-color: var(--blue-600);
}
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); }

.btn-ghost {
  background: transparent; color: var(--ink-400); border-color: var(--ink-100);
}
.btn-ghost:hover {
  background: var(--ink-050); border-color: var(--ink-200); color: var(--ink-700);
}

.btn-validate {
  background: var(--blue-600); color: #fff; border-color: var(--blue-600);
  padding: 10px 22px; font-size: 14px; font-weight: 700;
  box-shadow: var(--sh-sm); letter-spacing: .01em;
}
.btn-validate:hover:not(:disabled) {
  background: var(--blue-700); border-color: var(--blue-700); box-shadow: var(--sh);
}
.btn-validate:disabled {
  background: var(--surface-muted); color: var(--ink-200);
  border-color: var(--ink-100); cursor: not-allowed; box-shadow: none;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-row {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; margin-top: 12px;
}

.validate-row {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--ink-050);
  display: flex; align-items: center; gap: 12px;
}

/* ═══════════════════════════════════════════════════════════
   INLINE MESSAGES
══════════════════════════════════════════════════════════════ */
.msg-error, .msg-warning {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 12px; border-radius: var(--r);
  padding: 9px 12px; line-height: 1.5; margin-top: 8px;
}
.msg-error {
  background: var(--red-050); color: var(--red-700); border: 1px solid var(--red-100);
}
.msg-error::before { content: '⊗'; flex-shrink: 0; }
.msg-warning {
  background: var(--amber-050); color: var(--amber-700); border: 1px solid var(--amber-100);
}
.msg-warning::before { content: '⚠'; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-red   { background: var(--red-050);   color: var(--red-700);   border: 1px solid var(--red-100); }
.badge-amber { background: var(--amber-050); color: var(--amber-700); border: 1px solid var(--amber-100); }
.badge-blue  { background: var(--blue-050);  color: var(--blue-700);  border: 1px solid var(--blue-100); }
.badge-green { background: var(--green-050); color: var(--green-700); border: 1px solid var(--green-100); }

/* ═══════════════════════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════════════════════════ */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 28px; text-align: center;
}

.empty-icon {
  width: 64px; height: 64px;
  background: var(--surface); border: 1.5px dashed var(--ink-100);
  border-radius: 50%; display: flex;
  align-items: center; justify-content: center;
  margin-bottom: 18px; color: var(--ink-200);
}
.empty-icon svg {
  width: 26px; height: 26px;
  stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.empty-title {
  font-size: 15px; font-weight: 700;
  color: var(--ink-500); margin-bottom: 8px;
}
.empty-body {
  font-size: 13px; color: var(--ink-300);
  max-width: 270px; line-height: 1.65; margin-bottom: 24px;
}

.steps { display: flex; flex-direction: column; gap: 10px; text-align: left; width: 100%; max-width: 250px; }
.step { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-400); line-height: 1.4; }
.step-n {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--ink-100);
  color: var(--blue-600); font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   RESULT SUMMARY BAR
══════════════════════════════════════════════════════════════ */
.result-summary {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--ink-100);
  background: var(--surface);
}
.result-summary.ok {
  border-left: 3px solid var(--green-700);
  background: var(--green-050);
}
.result-summary.err {
  border-left: 3px solid var(--red-700);
  background: var(--red-050);
}

.summary-icon-wrap {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700; flex-shrink: 0;
}
.result-summary.ok  .summary-icon-wrap { background: var(--green-100); color: var(--green-700); }
.result-summary.err .summary-icon-wrap { background: var(--red-100);   color: var(--red-700); }

.summary-body { flex: 1; min-width: 0; }
.summary-title { font-size: 15px; font-weight: 700; line-height: 1.3; }
.result-summary.ok  .summary-title { color: var(--green-700); }
.result-summary.err .summary-title { color: var(--red-700); }
.summary-detail { font-size: 12px; color: var(--ink-400); margin-top: 3px; }

.summary-aside { text-align: right; flex-shrink: 0; padding-top: 2px; }
.summary-aside .aside-label { font-size: 10px; color: var(--ink-300); text-transform: uppercase; letter-spacing: .06em; }
.summary-aside .aside-value { font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: var(--blue-700); margin-top: 1px; }

/* ═══════════════════════════════════════════════════════════
   TABS
══════════════════════════════════════════════════════════════ */
.tab-strip {
  display: flex; background: var(--surface);
  border-bottom: 1px solid var(--ink-100);
  padding: 0 22px; overflow-x: auto; flex-shrink: 0;
}

.tab-btn {
  padding: 10px 16px; background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  font-family: var(--font-ui); font-size: 13px; font-weight: 600;
  color: var(--ink-300); cursor: pointer; white-space: nowrap;
  transition: color .12s, border-color .12s; flex-shrink: 0;
}
.tab-btn:hover { color: var(--ink-500); }
.tab-btn[aria-selected="true"] { color: var(--blue-600); border-bottom-color: var(--blue-600); }
.tab-btn:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--r-sm); outline: none; }

.tab-body {
  flex: 1; overflow: auto;
  padding: 20px 22px;
  background: var(--surface-subtle);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ═══════════════════════════════════════════════════════════
   VIOLATIONS TABLE
══════════════════════════════════════════════════════════════ */
.table-card {
  background: var(--surface);
  border: 1px solid var(--ink-100);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--sh-sm);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

caption {
  font-size: 11px; font-weight: 700; color: var(--ink-300);
  text-transform: uppercase; letter-spacing: .07em;
  text-align: left; padding: 12px 16px 10px;
  border-bottom: 1px solid var(--ink-050);
  background: var(--surface-muted); caption-side: top;
}

thead tr { background: var(--surface-muted); }
th {
  padding: 9px 14px; text-align: left;
  font-size: 11px; font-weight: 700; color: var(--ink-300);
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--ink-100);
}

tbody tr { border-bottom: 1px solid var(--ink-050); transition: background .08s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--blue-050); }

td { padding: 10px 14px; vertical-align: middle; }

.char-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px;
  background: var(--red-050); border: 1px solid var(--red-100);
  border-radius: var(--r); color: var(--red-700);
  font-family: var(--font-mono); font-weight: 500; font-size: 17px;
  padding: 0 8px;
}
.cp-code { font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: var(--blue-700); }
.uni-name { font-size: 12px; color: var(--ink-400); }
.count-cell { text-align: right; }

/* ═══════════════════════════════════════════════════════════
   ALL-VALID VIEW
══════════════════════════════════════════════════════════════ */
.all-valid {
  background: var(--surface); border: 1px solid var(--green-100);
  border-radius: var(--r-xl); padding: 40px 28px;
  text-align: center; box-shadow: var(--sh-sm);
}
.all-valid-circle {
  width: 60px; height: 60px;
  background: var(--green-050); border: 2px solid var(--green-100);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.all-valid-circle svg {
  width: 28px; height: 28px; stroke: var(--green-700); fill: none;
  stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
}
.all-valid-title { font-size: 17px; font-weight: 700; color: var(--green-700); margin-bottom: 8px; }
.all-valid-body  { font-size: 13px; color: var(--ink-400); line-height: 1.65; }
.all-valid-body strong { color: var(--blue-700); }

/* ═══════════════════════════════════════════════════════════
   SCHEMA MESSAGES
══════════════════════════════════════════════════════════════ */
.messages-card {
  margin-top: 14px;
  background: var(--blue-050); border: 1px solid var(--blue-100);
  border-radius: var(--r-lg); padding: 14px 16px;
}
.messages-hd {
  font-size: 11px; font-weight: 700; color: var(--blue-700);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px;
}
.message-row {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 12px; color: var(--ink-500); line-height: 1.6;
  padding: 5px 0; border-top: 1px solid var(--blue-100);
}
.message-row:first-of-type { border-top: none; }

/* ═══════════════════════════════════════════════════════════
   ANNOTATED PREVIEW
══════════════════════════════════════════════════════════════ */
.preview-legend {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--ink-300); margin-bottom: 10px;
}
.legend-swatch {
  background: var(--red-050); border: 1px solid var(--red-100);
  border-radius: var(--r-sm); color: var(--red-700);
  font-family: var(--font-mono); font-weight: 500;
  text-decoration: underline; text-decoration-style: wavy;
  text-decoration-color: var(--red-500); padding: 1px 6px;
}

.preview-box {
  background: var(--surface); border: 1px solid var(--ink-100);
  border-radius: var(--r-xl); padding: 16px 18px;
  max-height: 420px; overflow: auto;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.85;
  word-break: break-all; white-space: pre-wrap;
  color: var(--ink-700); box-shadow: var(--sh-sm);
}

.vchar {
  background: var(--red-050); border-radius: 2px;
  color: var(--red-700); font-weight: 500; cursor: help;
  text-decoration: underline; text-decoration-style: wavy;
  text-decoration-color: var(--red-500); padding: 0 1px;
}

/* ═══════════════════════════════════════════════════════════
   STATISTICS
══════════════════════════════════════════════════════════════ */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat-card {
  background: var(--surface); border: 1px solid var(--ink-100);
  border-radius: var(--r-lg); padding: 14px 16px;
  box-shadow: var(--sh-xs); transition: box-shadow .15s, transform .15s;
}
.stat-card:hover { box-shadow: var(--sh-sm); transform: translateY(-1px); }

.stat-label {
  font-size: 11px; font-weight: 600; color: var(--ink-300);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
}

.stat-value {
  font-size: 26px; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-value.c-neutral { color: var(--ink-700); }
.stat-value.c-good    { color: var(--green-700); }
.stat-value.c-bad     { color: var(--red-700); }
.stat-value.c-warn    { color: var(--amber-700); }

/* ═══════════════════════════════════════════════════════════
   FOOTER
══════════════════════════════════════════════════════════════ */
.app-footer {
  background: var(--surface); border-top: 1px solid var(--ink-100);
  padding: 11px 24px; display: flex; flex-wrap: wrap;
  align-items: center; gap: 4px 14px;
  font-size: 11px; color: var(--ink-300);
}
.footer-dot { color: var(--ink-100); }

/* ═══════════════════════════════════════════════════════════
   SPINNER
══════════════════════════════════════════════════════════════ */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .65s linear infinite; flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   ANIMATIONS & MOTION
══════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: no-preference) {
  @keyframes spin   { to { transform: rotate(360deg); } }
  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .fade-up { animation: fadeUp .2s ease forwards; }
}

@media (prefers-reduced-motion: reduce) {
  .fade-up { animation: none; }
  .spinner { animation: none; opacity: .7; }
}

/* ── High-contrast mode ─────────────────────────────────────────────────────── */
@media (forced-colors: active) {
  .vchar { outline: 2px solid ButtonText; }
  .btn-validate, .btn-primary { border: 2px solid ButtonText; }
  .result-summary.ok, .result-summary.err { border-left: 4px solid ButtonText; }
}

/* ── Tutorial link in header ────────────────────────────────────────────────── */
.header-help-link {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--ink-400);
  text-decoration: none; padding: 5px 10px;
  border-radius: var(--r); transition: background .15s, color .15s;
  margin-right: 8px;
}
.header-help-link:hover { background: var(--ink-050); color: var(--blue-600); }
.header-help-link:focus-visible { outline: none; box-shadow: var(--focus-ring); }
