/* =====================================================================
   Platrixa — FYJC Accountancy Assistant (Phase 7G)
   ---------------------------------------------------------------------
   Preserves the existing dark institutional identity (tokens, palette,
   motion) while replacing the 3-pane terminal workspace with a simple,
   mobile-friendly, single-column FYJC student layout.

   Mobile: fully usable at 320px / 375px / 430px; stacked cards, no
   horizontal overflow, touch-friendly controls, wrapping text.
   ===================================================================== */

:root {
  /* Surfaces */
  --bg: #070b14;
  --bg-soft: #0c1220;
  --panel: #101828;
  --panel-2: #0d1524;
  --surface-hover: #16213a;
  --line: rgba(148, 163, 184, 0.14);
  --line-strong: rgba(148, 163, 184, 0.28);

  /* Type */
  --text: #e6edf7;
  --text-soft: #b9c8dd;
  --muted: #8fa3bf;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  /* Accents (institutional, restrained) */
  --accent: #38bdf8;
  --accent-2: #34d399;
  --gold: #f5c542;
  --danger: #f87171;

  /* Status tokens — same vocabulary as the backend taxonomy */
  --st-verified: #34d399;
  --st-verified-bg: rgba(52, 211, 153, 0.12);
  --st-review: #f5c542;
  --st-review-bg: rgba(245, 197, 66, 0.12);
  --st-blocked: #f87171;
  --st-blocked-bg: rgba(248, 113, 113, 0.12);
  --st-unanalyzed: #64748b;
  --st-unanalyzed-bg: rgba(100, 116, 139, 0.12);

  /* Motion tokens */
  --fade-quick: 100ms;
  --hover: 180ms;

  /* Geometry */
  --header-h: 60px;
  --radius: 14px;
  --card-pad: clamp(16px, 3.5vw, 28px);
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 15% -10%, rgba(56, 189, 248, 0.10), transparent 60%),
    radial-gradient(900px 460px at 90% 0%, rgba(52, 211, 153, 0.08), transparent 55%),
    var(--bg);
  line-height: 1.55;
  /* Vertical scroll allowed on all sizes; horizontal never. */
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 90% 60% at 50% 0%, #000 30%, transparent 75%);
  z-index: 0;
}

/* ===================== Header ===================== */
.site-header {
  position: relative;
  z-index: 30;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: rgba(7, 11, 20, 0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #04121d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 22px rgba(56, 189, 248, 0.35);
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; }
.brand-text span { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.header-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }

.gateway-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--muted);
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  cursor: default;
  max-width: 100%;
}
.gateway-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--st-unanalyzed);
  flex-shrink: 0;
}
.gateway-pill.ok .dot { background: var(--st-verified); box-shadow: 0 0 10px rgba(52, 211, 153, 0.8); }
.gateway-pill.warn .dot { background: var(--st-review); box-shadow: 0 0 10px rgba(245, 197, 66, 0.7); }
.gateway-pill.bad .dot { background: var(--st-blocked); box-shadow: 0 0 10px rgba(248, 113, 113, 0.8); }

/* ===================== Main column ===================== */
.fyjc-main {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px) clamp(14px, 3vw, 24px) 48px;
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 3vw, 20px);
}

/* ===================== Cards ===================== */
.card {
  background: linear-gradient(180deg, rgba(16, 24, 40, 0.92), rgba(13, 21, 36, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--card-pad);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
  animation: fade-in var(--fade-quick) ease-out;
}

.card-title { margin: 0 0 4px; font-size: clamp(19px, 4.5vw, 24px); font-weight: 800; letter-spacing: -0.01em; }
.card-title-small { margin: 0 0 8px; font-size: 17px; font-weight: 700; }
.card-sub { margin: 0 0 14px; font-size: 13.5px; color: var(--muted); }

/* ===================== Input ===================== */
.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

textarea {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  font-family: var(--font);
  font-size: 16px; /* ≥16px prevents iOS zoom-on-focus */
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--hover) ease, box-shadow var(--hover) ease;
}
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18); }
textarea:disabled { opacity: 0.6; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 12px 20px;
  min-height: 46px; /* touch-friendly */
  transition: transform var(--hover) ease, box-shadow var(--hover) ease,
    background var(--hover) ease, border-color var(--hover) ease, color var(--hover) ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  color: #04121d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.28);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 10px 32px rgba(56, 189, 248, 0.45); }

.btn-secondary { color: var(--text); background: var(--bg-soft); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-process { width: 100%; margin-top: 12px; }

/* Example chips */
.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.examples-label { font-size: 12px; color: var(--muted); }
.example-chip {
  font-family: var(--font);
  font-size: 12.5px;
  color: var(--text-soft);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  min-height: 34px;
  cursor: pointer;
  transition: border-color var(--hover) ease, color var(--hover) ease, background var(--hover) ease;
}
.example-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ===================== Loading ===================== */
.card-loading { display: flex; align-items: flex-start; gap: 14px; }
.loading-title { margin: 0 0 2px; font-weight: 700; font-size: 15px; }
.loading-sub { margin: 0; font-size: 12.5px; color: var(--muted); }

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid rgba(56, 189, 248, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  flex-shrink: 0;
  margin-top: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Error ===================== */
.card-error { border-color: rgba(248, 113, 113, 0.4); background: linear-gradient(180deg, rgba(40, 17, 24, 0.9), rgba(13, 21, 36, 0.92)); }
.error-message { margin: 0 0 10px; font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.error-hint { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }

/* ===================== Result ===================== */
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 14px;
  border: 1px solid transparent;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.status-badge.ok      { color: var(--st-verified); background: var(--st-verified-bg); border-color: rgba(52, 211, 153, 0.35); }
.status-badge.review  { color: var(--st-review);   background: var(--st-review-bg);   border-color: rgba(245, 197, 66, 0.35); }
.status-badge.blocked { color: var(--st-blocked);  background: var(--st-blocked-bg);  border-color: rgba(248, 113, 113, 0.35); }
.status-badge.offline { color: var(--muted);       background: var(--st-unanalyzed-bg); border-color: var(--line-strong); }

.status-explain { margin: 2px 0 4px; font-size: 14px; color: var(--text-soft); }

.result-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.section-title {
  margin: 0 0 10px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Facts (what Platrixa understood) */
.fact-list { margin: 0; display: grid; gap: 8px; }
.fact { display: flex; flex-direction: column; gap: 1px; }
.fact dt { font-size: 12px; color: var(--muted); }
.fact dd { margin: 0; font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; }

/* Issues */
.issue-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.issue-list li { font-size: 13.5px; color: var(--text-soft); overflow-wrap: anywhere; }

/* Journal table */
.journal-narration { margin: 0 0 10px; font-size: 14px; font-style: italic; color: var(--text-soft); }

.journal-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--line); }

.journal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 300px;
}
.journal-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg-soft);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.journal-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.journal-table tr:last-child td { border-bottom: none; }
.journal-table td.num, .journal-table th:nth-child(2), .journal-table th:nth-child(3) {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.journal-table th:nth-child(1) { text-align: left; }

/* Accordion (extra accounting details) */
.accordion { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-soft); }
.accordion summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  padding: 10px 13px;
  list-style: none;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary:hover { color: var(--text); }
.accordion-body { padding: 2px 13px 12px; display: grid; gap: 8px; }
.accordion-body:empty { display: none; }

.balance-note { margin: 0; font-size: 13px; }
.balance-note.ok { color: var(--st-verified); }
.balance-note.bad { color: var(--st-blocked); }

.extra-title { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); font-weight: 700; }
.calc-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.calc-list li { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.calc-list li span:first-child { color: var(--text-soft); overflow-wrap: anywhere; }
.calc-list .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Next action */
.next-action { margin: 0; font-size: 14px; color: var(--text); }

.trust-note { margin: 14px 0 0; font-size: 12px; color: var(--muted); }

/* ===================== Empty state ===================== */
.card-empty { text-align: center; padding: clamp(24px, 6vw, 44px) var(--card-pad); }
.empty-emoji { margin: 0; font-size: 34px; }
.empty-title { margin: 8px 0 4px; font-weight: 700; font-size: 15.5px; }
.empty-sub { margin: 0 auto; max-width: 46ch; font-size: 13px; color: var(--muted); }

/* ===================== Footer ===================== */
.site-footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 14px clamp(14px, 3vw, 32px) 18px;
  color: var(--muted);
  font-size: 11.5px;
  border-top: 1px solid var(--line);
  background: rgba(7, 11, 20, 0.85);
  max-width: 100%;
}
.site-footer code { color: var(--accent); overflow-wrap: anywhere; }
.api-ref { overflow-wrap: anywhere; }

/* ===================== Focus visibility ===================== */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===================== Motion ===================== */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ===================== Reduced motion ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: none !important; }
}

/* ===================== Responsive: tablet & below ===================== */
@media (max-width: 640px) {
  .site-header { padding: 10px 14px; }
  .brand-text strong { font-size: 14px; }
  .brand-text span { font-size: 10.5px; }
  .gateway-pill { font-size: 11px; padding: 6px 10px; }

  .card-title { font-size: 18px; }
  .card { border-radius: 12px; }

  /* Facts: keep label + value rows compact but readable */
  .fact dd { font-size: 14px; }

  .result-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .status-badge { align-self: flex-start; }
}

/* ===================== Responsive: small phones (≤430px) ===================== */
@media (max-width: 430px) {
  :root { --card-pad: 16px; }

  .brand-mark { width: 34px; height: 34px; font-size: 10px; }
  .header-actions { width: 100%; }
  .gateway-pill { width: 100%; justify-content: center; }

  .fyjc-main { padding: 14px 12px 40px; gap: 12px; }

  textarea { font-size: 16px; min-height: 68px; }
  .btn { font-size: 14.5px; }

  .journal-table { font-size: 13px; min-width: 260px; }
  .journal-table th, .journal-table td { padding: 8px 10px; }

  .status-explain, .next-action { font-size: 13.5px; }
  .issue-list li { font-size: 13px; }
}

/* ===================== Responsive: narrow phones (≤320px) ===================== */
@media (max-width: 320px) {
  .brand-text span { display: none; } /* keep the header single-line */
  .fyjc-main { padding: 12px 10px 36px; }
  .examples { gap: 6px; }
  .example-chip { font-size: 11.5px; padding: 6px 10px; min-height: 32px; }
  .journal-table { min-width: 220px; }
  .fact dd { font-size: 13.5px; }
}
