/* ═══════════════════════════════════════════════════════════════════
   TEKMYR craft layer — typographic character, tactile controls, focus
   clarity. Loaded after every other stylesheet; refines without
   replacing the layout systems.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --craft-serif: "tekmyr-didot", "Noto Serif SC", "Songti SC", Georgia, serif;
  --craft-sans: "Noto Sans SC", -apple-system, "system-ui", "PingFang SC", sans-serif;
  --craft-gold: #d4b582;
  --craft-gold-soft: rgba(212, 181, 130, 0.14);
  --craft-gold-line: rgba(212, 181, 130, 0.38);
  --craft-ring: 0 0 0 3px rgba(212, 181, 130, 0.22);
  --craft-radius-input: 10px;
  --craft-ease: cubic-bezier(0.32, 0.72, 0, 1);
}

/* ── brand typography returns ────────────────────────────────────── */
body, .workspace, .landing {
  font-family: var(--craft-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "tnum" 0;
}

h1, h2, .page-title, .card-title, .section-title, .mode-card-body strong,
.paper h3, .closing-copy h2, .hero-copy h1 {
  font-family: var(--craft-serif) !important;
  letter-spacing: 0.01em;
  font-weight: 500;
}

.eyebrow {
  font-family: var(--craft-sans);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72em;
  font-weight: 600;
}

.num, .stat-value, .table .num, dd.num, .wallet-chip strong {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Chinese body text breathes a little more */
p, li, dd, td { line-height: 1.75; }
.card-text, .page-lead, .hero-lead { line-height: 1.85; }

/* ── controls: inputs gain weight and clarity ─────────────────────── */
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]),
select.input, .input, textarea.input, textarea {
  border-radius: var(--craft-radius-input) !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 42%),
    rgba(6, 8, 12, 0.9) !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.45);
  transition: border-color 0.18s var(--craft-ease), box-shadow 0.18s var(--craft-ease), background 0.18s var(--craft-ease);
  font-size: 15px;
}

input:not([type="checkbox"]):not([type="radio"]):hover,
select.input:hover, .input:hover, textarea:hover {
  border-color: rgba(255, 255, 255, 0.28) !important;
}

input:not([type="checkbox"]):not([type="radio"]):focus,
input:not([type="checkbox"]):not([type="radio"]):focus-visible,
select.input:focus, select.input:focus-visible, .input:focus, .input:focus-visible,
textarea:focus, textarea:focus-visible {
  outline: none !important;
  border-color: var(--craft-gold) !important;
  box-shadow: var(--craft-ring), inset 0 1px 2px rgba(0, 0, 0, 0.45) !important;
}

input::placeholder, textarea::placeholder, .input::placeholder {
  color: rgba(255, 255, 255, 0.34);
  font-weight: 300;
}

input[aria-invalid="true"], .has-error input, .has-error .input {
  border-color: rgba(248, 113, 113, 0.65) !important;
}
input[aria-invalid="true"]:focus, input[aria-invalid="true"]:focus-visible, .has-error input:focus, .has-error input:focus-visible {
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18), inset 0 1px 2px rgba(0, 0, 0, 0.45) !important;
}

/* select chevron refined */
select.input, .form-fields select, .field select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--craft-gold) 50%),
    linear-gradient(135deg, var(--craft-gold) 50%, transparent 50%) !important;
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50% !important;
  background-size: 5px 5px, 5px 5px !important;
  background-repeat: no-repeat !important;
}

/* checkboxes — tactile */
.check-row input[type="checkbox"], .form-fields input[type="checkbox"] {
  appearance: none;
  width: 19px; height: 19px;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: 5px;
  background: rgba(6, 8, 12, 0.9);
  transition: all 0.16s var(--craft-ease);
  cursor: pointer;
  position: relative;
}
.check-row input[type="checkbox"]:checked, .form-fields input[type="checkbox"]:checked {
  background: var(--craft-gold);
  border-color: var(--craft-gold);
}
.check-row input[type="checkbox"]:checked::after, .form-fields input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5.5px; top: 1.5px;
  width: 5px; height: 10px;
  border: solid #1a1308;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
.check-row input[type="checkbox"]:focus-visible, .form-fields input[type="checkbox"]:focus-visible {
  box-shadow: var(--craft-ring);
  outline: none;
}

/* ── buttons: press, lift, ring ─────────────────────────────────── */
.btn, button.chip {
  border-radius: var(--craft-radius-input) !important;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.16s var(--craft-ease), box-shadow 0.16s var(--craft-ease),
    background 0.16s var(--craft-ease), border-color 0.16s var(--craft-ease), filter 0.16s var(--craft-ease);
}
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.55);
}
.btn:active:not(:disabled) { transform: translateY(0); filter: brightness(0.97); }
.btn:focus-visible, button.chip:focus-visible, a:focus-visible {
  outline: none;
  box-shadow: var(--craft-ring);
}
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.55; cursor: wait; }

.btn-secondary {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--craft-gold-line);
  background: var(--craft-gold-soft);
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-accent {
  background: linear-gradient(180deg, #e5c895, #c4a46f);
  color: #1a1308;
  box-shadow: 0 2px 10px -2px rgba(212, 181, 130, 0.4);
}
.btn-accent:hover:not(:disabled) { box-shadow: 0 6px 22px -6px rgba(212, 181, 130, 0.55); }

/* ── cards: layered depth, hairline headers ─────────────────────── */
.card {
  border-radius: 14px !important;
  border: 1px solid rgba(255, 255, 255, 0.13) !important;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.045) inset,
    0 24px 60px -18px rgba(0, 0, 0, 0.8) !important;
  transition: border-color 0.2s var(--craft-ease), transform 0.2s var(--craft-ease);
}
.card:hover { border-color: rgba(255, 255, 255, 0.2) !important; }
.card-accent, .card-accent.corners {
  border-color: var(--craft-gold-line) !important;
  box-shadow:
    0 1px 0 rgba(212, 181, 130, 0.1) inset,
    0 24px 60px -18px rgba(0, 0, 0, 0.8) !important;
}

.card-header { border-bottom: 1px solid rgba(255, 255, 255, 0.07); padding-bottom: 10px; }
.section-header { border-bottom: 1px solid rgba(255, 255, 255, 0.06); }

/* ── badges & chips ──────────────────────────────────────────────── */
.badge {
  letter-spacing: 0.04em;
  border-radius: 999px;
  font-weight: 500;
  padding: 0.22em 0.7em;
}
.chip {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.03);
}
.chip:hover { border-color: var(--craft-gold); color: var(--craft-gold); }

/* ── links ───────────────────────────────────────────────────────── */
a { transition: color 0.14s var(--craft-ease); }
.link { text-underline-offset: 3px; text-decoration-color: rgba(255, 255, 255, 0.25); }
.link:hover { text-decoration-color: var(--craft-gold); }

/* ── tables ──────────────────────────────────────────────────────── */
.table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.45);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.table tbody tr { transition: background 0.12s ease; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

/* ── chat window: the flagship surface ───────────────────────────── */
.scan-chat .chat-feed {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(212, 181, 130, 0.045), transparent 55%),
    rgba(4, 6, 9, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 14px;
  gap: 8px;
}
.chat-msg { border-radius: 11px; animation: chat-in 0.28s var(--craft-ease); }
@keyframes chat-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-time { font-variant-numeric: tabular-nums; }
.chat-llm { border-left: 2px solid var(--craft-gold-line); }
.chat-http { border-left: 2px solid rgba(255, 255, 255, 0.18); }
.chat-finding { border-left: 2px solid var(--craft-gold); }
.chat-system { opacity: 0.85; }

/* typing shimmer while running */
[data-live-chat] .chat-feed::after {
  content: "";
  display: block;
  height: 2px;
  width: 46px;
  margin: 4px auto 0;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--craft-gold), transparent);
  background-size: 200% 100%;
  animation: craft-shimmer 1.6s linear infinite;
}
@keyframes craft-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── mode cards (scan composer) ───────────────────────────────────── */
.mode-card { border-radius: 12px !important; }
.mode-card.is-selected {
  border-color: var(--craft-gold) !important;
  box-shadow: var(--craft-ring);
  background: linear-gradient(180deg, rgba(212, 181, 130, 0.1), rgba(212, 181, 130, 0.04)) !important;
}

/* ── global details ──────────────────────────────────────────────── */
::selection { background: rgba(212, 181, 130, 0.32); color: #fff; }

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: rgba(212, 181, 130, 0.45); }

.notice { border-radius: 10px; }
.disclosure summary { cursor: pointer; transition: color 0.14s ease; }
.disclosure summary:hover { color: var(--craft-gold); }

hr, .frieze { opacity: 0.9; }

/* pagination */
.pagination .btn { border-radius: 8px !important; }

/* reduced motion honoured */
@media (prefers-reduced-motion: reduce) {
  .chat-msg { animation: none; }
  [data-live-chat] .chat-feed::after { animation: none; display: none; }
  .btn:hover:not(:disabled) { transform: none; }
}

/* ═══ override stray blue glows with the gold system ═══ */
.mode-card.is-selected, .mode-card:has(input:checked) {
  box-shadow: 0 0 0 3px rgba(212, 181, 130, 0.22), 0 12px 32px -8px rgba(0, 0, 0, 0.55) !important;
}
.btn:focus-visible, .btn:focus { box-shadow: var(--craft-ring) !important; }
[data-scan-submit], .btn-accent, .btn { box-shadow: none; }
[data-scan-submit]:hover:not(:disabled), .btn:hover:not(:disabled) {
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.55) !important;
}

/* selects inside form-fields need the full craft treatment too */
.form-fields select, .field select, .form-fields input, .field input,
.form-fields textarea, .field textarea, select {
  border-radius: var(--craft-radius-input) !important;
  background-image: none;
}
select.input, .form-fields select, .field select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--craft-gold) 50%),
    linear-gradient(135deg, var(--craft-gold) 50%, transparent 50%) !important;
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50% !important;
  background-size: 5px 5px, 5px 5px !important;
  background-repeat: no-repeat !important;
  padding-right: 40px !important;
}

/* ═══ unify OpenAI's mode glows and laser into the gold system ═══ */
.refined-ui:not(.landing) form[data-active-mode="blue"] [data-scan-submit]:not(:disabled),
.refined-ui:not(.landing) form[data-active-mode="red"] [data-scan-submit]:not(:disabled) {
  box-shadow: 0 4px 22px rgba(212, 181, 130, 0.3) !important;
}
.refined-ui:not(.landing) .card[data-live-scan] {
  border-color: var(--craft-gold-line) !important;
  box-shadow: 0 1px 0 rgba(212, 181, 130, 0.08) inset, 0 24px 60px -18px rgba(0, 0, 0, 0.8) !important;
}
.refined-ui:not(.landing) .card[data-live-scan]::before {
  background: linear-gradient(90deg, transparent, var(--craft-gold), #fff8e8, var(--craft-gold), transparent) !important;
}

/* ═══ chat status line + working pulse ═══ */
.chat-statusline {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.62);
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
.chat-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  flex: none;
}
.chat-status-dot.is-live {
  background: #9fc48c;
  box-shadow: 0 0 0 0 rgba(159, 196, 140, 0.5);
  animation: chat-pulse 2s infinite;
}
@keyframes chat-pulse {
  0% { box-shadow: 0 0 0 0 rgba(159, 196, 140, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(159, 196, 140, 0); }
  100% { box-shadow: 0 0 0 0 rgba(159, 196, 140, 0); }
}
.chat-clock { color: var(--craft-gold); font-weight: 600; letter-spacing: 0.04em; }
.chat-counters { display: flex; gap: 6px; align-items: baseline; }
.chat-working { margin-left: auto; color: rgba(255, 255, 255, 0.5); }
.chat-working .working-dots i { font-style: normal; animation: dot-bounce 1.4s infinite; }
.chat-working .working-dots i:nth-child(2) { animation-delay: 0.2s; }
.chat-working .working-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .chat-status-dot.is-live, .chat-working .working-dots i { animation: none; }
}

/* feed slightly taller on wide screens for a proper console feel */
@media (min-width: 1000px) { .scan-chat .chat-feed { max-height: 520px; } }

/* balance health + budget warning details */
.balance-health { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; padding: 0.15em 0.55em; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.balance-health.is-good { color: #9fc48c; background: rgba(159, 196, 140, 0.12); }
.balance-health.is-ok { color: #e5c895; background: rgba(212, 181, 130, 0.14); }
.balance-health.is-low { color: #f87171; background: rgba(248, 113, 113, 0.14); }
.balance-warn { margin: 10px 0 2px; font-size: 0.85rem; }
.budget-afterline.is-warning { color: #f87171; font-weight: 600; }

.stat-note.balance-warn-note { color: #e5c895; font-weight: 500; }

/* ═══ sidebar: unmistakable active state ═══ */
.sidebar .nav-item {
  border-radius: 10px !important;
  position: relative;
  transition: background 0.14s var(--craft-ease), color 0.14s var(--craft-ease);
}
.sidebar .nav-item:hover { background: rgba(255, 255, 255, 0.05); }
.sidebar .nav-item.active {
  background: linear-gradient(90deg, rgba(212, 181, 130, 0.14), rgba(212, 181, 130, 0.05)) !important;
  color: var(--craft-gold) !important;
  font-weight: 600;
}
.sidebar .nav-item.active::before {
  content: "";
  position: absolute;
  left: -16px; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--craft-gold);
  box-shadow: 0 0 12px rgba(212, 181, 130, 0.5);
}
.sidebar .nav-item.active svg { color: var(--craft-gold); }
.stat-value small { font-size: 0.42em; letter-spacing: 0.08em; opacity: 0.6; margin-left: 0.35em; font-weight: 500; }
.page-title { font-size: 2rem; line-height: 1.25; }
.card-title { font-size: 1.18rem; }
.section-title { font-size: 1.3rem; }
.notice { border: 1px solid rgba(255, 255, 255, 0.09); border-left-width: 3px; }
.notice.warning { border-left-color: var(--craft-gold); background: rgba(212, 181, 130, 0.06); }

/* ═══ dashboard live mini-stats + completion toast ═══ */
.scan-live-mini {
  display: flex; align-items: baseline; gap: 12px;
  padding: 8px 12px; margin-top: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  width: 100%;
}
.scan-live-mini .mini-clock { color: var(--craft-gold); font-weight: 600; }
.scan-live-mini .mini-counts b { color: var(--text); font-weight: 600; }
.scan-live-mini .mini-last {
  margin-left: auto; color: rgba(255, 255, 255, 0.45);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44%;
}

.scan-toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 90;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--craft-gold-line);
  background: rgba(10, 13, 18, 0.96);
  box-shadow: 0 18px 50px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(212, 181, 130, 0.12);
  color: var(--text); text-decoration: none; font-size: 0.88rem;
  opacity: 0; transform: translateY(12px);
  transition: opacity 0.3s var(--craft-ease), transform 0.3s var(--craft-ease);
}
.scan-toast.is-in { opacity: 1; transform: none; }
.scan-toast:hover { border-color: var(--craft-gold); }
.scan-toast .toast-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #9fc48c; box-shadow: 0 0 10px rgba(159, 196, 140, 0.6);
}
.scan-toast strong { color: var(--craft-gold); }

.chat-resume-note { font-size: 0.82rem; color: rgba(255, 255, 255, 0.5); margin: 2px 0 8px; }
.chat-resume-note::before { content: "↻ "; color: var(--craft-gold); }

/* ═══ finding cards inside the live chat feed ═══ */
.chat-msg.chat-finding-card {
  align-self: stretch; max-width: 100%;
  border: 1px solid var(--craft-gold-line);
  background: linear-gradient(180deg, rgba(212, 181, 130, 0.08), rgba(212, 181, 130, 0.03));
  animation: chat-in 0.3s var(--craft-ease);
}
.finding-card-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.finding-card-body strong { font-size: 0.92rem; color: var(--text); }
.finding-card-body p { margin: 2px 0 0; font-size: 0.82rem; color: rgba(255, 255, 255, 0.62); line-height: 1.6; }
.chat-url { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.75rem; color: var(--craft-gold); word-break: break-all; }
.chat-sev {
  align-self: flex-start;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
  padding: 0.14em 0.6em; border-radius: 999px;
}
.chat-sev-critical { color: #fca5a5; background: rgba(248, 113, 113, 0.16); }
.chat-sev-high { color: #fdba74; background: rgba(251, 146, 60, 0.16); }
.chat-sev-medium { color: #e5c895; background: rgba(212, 181, 130, 0.16); }
.chat-sev-low { color: #93c5fd; background: rgba(96, 165, 250, 0.14); }
.chat-sev-info { color: rgba(255, 255, 255, 0.6); background: rgba(255, 255, 255, 0.08); }

/* ═══ mobile fixes ═══ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.hero-figure { overflow: hidden; }
@media (max-width: 480px) {
  .site-header .site-actions { gap: 8px; }
  .site-header .site-actions .site-login { display: none; }
  .site-header .site-actions .btn-sm { padding: 0 12px; min-height: 34px; }
}
@media (max-width: 760px) {
  .topbar .topbar-end { flex-wrap: wrap; gap: 8px; justify-content: flex-end; max-width: 100%; }
  .topbar .topbar-end .btn-text { padding: 0 10px; min-height: 32px; font-size: 0.82rem; }
  /* chat window: comfortable phone sizing */
  .scan-chat .chat-feed { max-height: 65vh; padding: 10px; }
  .chat-statusline { flex-wrap: wrap; gap: 8px 10px; font-size: 0.72rem; padding: 8px 10px; }
  .chat-statusline .chat-counters { flex-wrap: wrap; }
  .chat-msg { max-width: 100%; }
  .scan-live-mini { flex-wrap: wrap; font-size: 0.72rem; }
  .scan-live-mini .mini-last { max-width: 100%; flex-basis: 100%; }
  /* mode cards stack tighter */
  .mode-card { padding: 12px; }
  .chip { min-height: 38px; }
  .budget-row { flex-wrap: wrap; }
  /* findings and forms: bigger touch targets */
  .btn { min-height: 42px; }
  input:not([type="checkbox"]):not([type="radio"]), select.input, .input, textarea { min-height: 46px; }
  .disclosure summary { padding: 10px 0; min-height: 44px; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap !important; }
  .topbar-start, .topbar-end { flex-shrink: 1 !important; min-width: 0; }
  .topbar .breadcrumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
