/* ==========================================================================
   Visa Bulletin Pages - tokens and styles.
   Every color/size/space here traces to DESIGN.md. Raw values appear only in
   the :root token block (Section 2/3/4) or as documented browser mechanics
   (clamp, percentages, minmax).
   ========================================================================== */

:root {
  color-scheme: dark;

  /* --- Surface (DESIGN.md §2) --- */
  --surface-canvas: #08090a;
  --surface-panel: #0f1011;
  --surface-elevated: #191a1b;
  --surface-hover: #28282c;

  /* --- Text (DESIGN.md §2) --- */
  --text-primary: #f7f8f8;
  --text-secondary: #d0d6e0;
  --text-tertiary: #8a8f98;
  --text-quaternary: #62666d;

  /* --- Borders (DESIGN.md §2) --- */
  --border-default: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.05);

  /* --- Accent - interactive only (DESIGN.md §2) --- */
  --accent-indigo: #5e6ad2;
  --accent-violet: #7170ff;
  --accent-hover: #828fff;

  /* --- Movement semantics (DESIGN.md §2) --- */
  --status-advance: #3ecf8e;
  --status-advance-bg: rgba(16, 185, 129, 0.12);
  --status-regress: #ff6369;
  --status-regress-bg: rgba(225, 72, 77, 0.14);
  --status-flat: #8a8f98;
  --status-flat-bg: rgba(255, 255, 255, 0.05);
  --pill-current-bg: rgba(113, 112, 255, 0.14);
  --pill-current-fg: #a5a3ff;
  --pill-unavailable-bg: rgba(226, 160, 63, 0.14);
  --pill-unavailable-fg: #f0b357;
  /* Compare "Di chuyển" badge: unavailable-current (N/A) navy pill. */
  --pill-na-bg: #16213e;
  --pill-na-fg: #8ea2e6;

  /* --- Type (DESIGN.md §3) --- */
  --font-sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --fs-display: clamp(2rem, 7vw, 3.5rem);
  --fs-h1: 1.5rem;
  --fs-h2: 1.125rem;
  --fs-body-lg: 1rem;
  --fs-body: 0.9375rem;
  --fs-small: 0.875rem;
  --fs-caption: 0.8125rem;
  --fs-micro: 0.6875rem;

  /* --- Spacing, base 4px (DESIGN.md §4) --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* --- Radius scale (DESIGN.md §5 shape lock) --- */
  --radius-micro: 2px;
  --radius-control: 6px;
  --radius-card: 8px;
  --radius-pill: 9999px;

  /* --- Motion (DESIGN.md §6) --- */
  --dur-micro: 120ms;
  --dur-standard: 200ms;
  --dur-emphasis: 400ms;
  --ease-out: ease-out;
  --ease-standard: ease-in-out;
  --ease-emphasis: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ------------------------------------------------------------------ base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--surface-canvas);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface-canvas);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

a {
  color: var(--accent-violet);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--surface-canvas),
    0 0 0 4px var(--accent-violet);
}

.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;
}

/* ----------------------------------------------------------------- shell */

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-12);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

@media (min-width: 768px) {
  .page {
    padding: var(--space-12) var(--space-6) var(--space-16);
    gap: var(--space-8);
  }
}

.panel {
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
}

/* --------------------------------------------------------------- masthead */

.masthead {
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  animation: rise-in var(--dur-emphasis) var(--ease-emphasis) both;
}

@media (min-width: 768px) {
  .masthead {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    padding: var(--space-6);
  }
}

.masthead-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.site-title {
  font-size: var(--fs-h1);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.runway {
  font-family: var(--font-mono);
  font-size: var(--fs-display);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-3);
  font-variant-numeric: tabular-nums;
}

.runway[data-state="loading"] .runway-month,
.runway[data-state="loading"] .runway-arrow {
  color: var(--text-quaternary);
}

.runway-arrow {
  color: var(--accent-violet);
  font-weight: 400;
}

.runway-month--prev {
  color: var(--text-tertiary);
}

.masthead-meta {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: flex-start;
}

@media (min-width: 768px) {
  .masthead-meta {
    align-items: flex-end;
    text-align: right;
  }
}

.updated {
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.source-link {
  font-size: var(--fs-small);
  font-weight: 500;
}

.source-note {
  font-size: var(--fs-caption);
  color: var(--text-quaternary);
}

/* --------------------------------------------------------------- controls */

.controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

@media (min-width: 1024px) {
  .controls {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.tabbar {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
  padding: var(--space-1);
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
}

.tabbar::-webkit-scrollbar {
  display: none;
}

@media (min-width: 1024px) {
  .tabbar {
    flex: 1 1 auto;
    min-width: 0;
    margin-right: var(--space-3);
  }
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: 1.3;
  padding: var(--space-2) var(--space-3);
  min-height: 36px;
  border-radius: var(--radius-control);
  white-space: nowrap;
  cursor: pointer;
  flex: 0 0 auto;
  transition:
    background-color var(--dur-standard) var(--ease-standard),
    color var(--dur-standard) var(--ease-standard);
}

.tab:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.tab.is-active {
  background: var(--accent-indigo);
  color: var(--text-primary);
}

.modeswitch {
  position: relative;
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  align-self: flex-start;
}

@media (min-width: 1024px) {
  .modeswitch {
    align-self: auto;
    flex: 0 0 auto;
  }
}

.segment-indicator {
  position: absolute;
  top: var(--space-1);
  left: 0;
  height: calc(100% - var(--space-2));
  background: var(--accent-indigo);
  border-radius: var(--radius-control);
  transition: transform var(--dur-standard) var(--ease-standard);
  pointer-events: none;
}

.segment {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  min-height: 36px;
  border-radius: var(--radius-control);
  cursor: pointer;
  position: relative;
  z-index: 1;
  white-space: nowrap;
  transition: color var(--dur-standard) var(--ease-standard);
}

.segment:hover:not(.is-active) {
  color: var(--text-primary);
}

.segment.is-active {
  color: var(--text-primary);
}

/* ---------------------------------------------------------------- content */

.content {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 320px;
}

.summary-strip {
  background: var(--surface-panel);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-caption);
  color: var(--text-tertiary);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  align-items: center;
  font-variant-numeric: tabular-nums;
  animation: fade-in var(--dur-standard) var(--ease-standard) both;
}

.summary-strip .count-up {
  color: var(--status-advance);
  font-weight: 600;
}

.summary-strip .count-down {
  color: var(--status-regress);
  font-weight: 600;
}

.summary-strip .count-flat {
  color: var(--text-secondary);
  font-weight: 600;
}

.summary-strip .count-text {
  color: var(--pill-unavailable-fg);
  font-weight: 600;
}

.panel--table {
  overflow: hidden;
  animation: rise-in var(--dur-emphasis) var(--ease-emphasis) both;
}

/* ------------------------------------------------------------ empty/error */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-4);
  max-width: 46ch;
  margin: 0 auto;
  animation: fade-in var(--dur-standard) var(--ease-standard) both;
}

.state-title {
  font-size: var(--fs-h2);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.state-body {
  font-size: var(--fs-small);
  color: var(--text-tertiary);
  line-height: 1.6;
}

.state--error .state-title {
  color: var(--status-regress);
}

.btn {
  appearance: none;
  border: 0;
  margin-top: var(--space-2);
  background: var(--accent-indigo);
  color: #ffffff;
  font-family: inherit;
  font-size: var(--fs-small);
  font-weight: 600;
  padding: var(--space-2) var(--space-5);
  min-height: 36px;
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out);
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:active {
  transform: translateY(1px);
}

/* --------------------------------------------------------------- skeleton */

.skeleton {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.skeleton-line {
  height: 40px;
  border-radius: var(--radius-control);
  background: linear-gradient(
    90deg,
    var(--surface-elevated) 25%,
    var(--surface-hover) 50%,
    var(--surface-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.skeleton-line--title {
  height: 56px;
  width: min(420px, 80%);
}

.skeleton-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ---------------------------------------------------------------- tables */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll:focus-visible {
  box-shadow:
    inset 0 0 0 2px var(--accent-violet),
    inset 0 0 0 4px var(--surface-canvas);
}

.vb-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 640px;
  font-size: var(--fs-small);
  animation: fade-in var(--dur-standard) var(--ease-standard) both;
}

.vb-table caption {
  text-align: left;
}

.vb-table th,
.vb-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  vertical-align: top;
}

.vb-table th:last-child,
.vb-table td:last-child {
  border-right: 0;
}

.vb-table tbody tr:last-child th,
.vb-table tbody tr:last-child td {
  border-bottom: 0;
}

.vb-table thead th {
  background: var(--surface-elevated);
  color: var(--text-tertiary);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
  text-align: right;
  white-space: normal;
  min-width: 7.5rem;
}

.vb-table thead th:first-child {
  text-align: left;
  left: 0;
  z-index: 2;
}

.vb-table th[scope="row"] {
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-panel);
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 7rem;
  white-space: nowrap;
}

.vb-table td {
  text-align: right;
  min-width: 7.5rem;
}

.vb-table tbody tr:hover th[scope="row"],
.vb-table tbody tr:hover td {
  background: var(--surface-hover);
}

.vb-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-1);
}

.cell-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ------------------------------------------------------------- value bits */

.pill {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
}

.pill--current {
  background: var(--pill-current-bg);
  color: var(--pill-current-fg);
}

.pill--unavailable {
  background: var(--pill-unavailable-bg);
  color: var(--pill-unavailable-fg);
}

.delta {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.delta--up {
  background: var(--status-advance-bg);
  color: var(--status-advance);
}

.delta--down {
  background: var(--status-regress-bg);
  color: var(--status-regress);
}

.delta--flat {
  background: var(--status-flat-bg);
  color: var(--status-flat);
}

.delta--text {
  background: var(--status-flat-bg);
  color: var(--text-tertiary);
  border: 1px solid var(--border-subtle);
}

.delta-note {
  font-family: var(--font-sans);
  font-size: var(--fs-micro);
  font-weight: 500;
  color: var(--text-quaternary);
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------- compare table */

.vb-table--compare {
  min-width: 860px;
}

.vb-table--compare th,
.vb-table--compare td {
  padding: var(--space-2) var(--space-3);
  vertical-align: middle;
}

.vb-table--compare thead th {
  background: var(--accent-indigo);
  color: #ffffff;
  font-size: var(--fs-caption);
  font-weight: 700;
  letter-spacing: normal;
  text-transform: none;
  line-height: 1.3;
  text-align: right;
  vertical-align: bottom;
}

.vb-table--compare thead th:nth-child(1),
.vb-table--compare thead th:nth-child(2) {
  text-align: left;
}

.vb-table--compare thead th:nth-child(6) {
  text-align: center;
  min-width: 5.5rem;
}

.vb-table--compare tbody th.compare-category {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface-hover);
  color: var(--text-primary);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
  min-width: 7.5rem;
}

.vb-table--compare tbody tr:nth-child(even) td {
  background: var(--surface-elevated);
}

.vb-table--compare tbody tr:hover td,
.vb-table--compare tbody tr:hover th {
  background: var(--surface-hover);
}

.vb-table--compare tbody tr.is-group-end th,
.vb-table--compare tbody tr.is-group-end td {
  border-bottom-color: var(--border-default);
}

.vb-table--compare .compare-region {
  text-align: left;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 9.5rem;
}

.vb-table--compare .compare-delta-cell {
  min-width: 7rem;
}

.vb-table--compare .compare-move-cell {
  text-align: center;
  min-width: 5.5rem;
}

.cell-value--none {
  color: var(--text-quaternary);
}

.delta--none {
  background: transparent;
  color: var(--text-quaternary);
  font-weight: 500;
}

.move {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: var(--fs-small);
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.move--up {
  background: var(--status-advance);
  color: var(--surface-canvas);
}

.move--down {
  background: var(--status-regress);
  color: var(--surface-canvas);
}

.move--flat {
  background: var(--status-flat);
  color: var(--surface-canvas);
}

.move--na {
  width: auto;
  height: auto;
  padding: 3px var(--space-2);
  background: var(--pill-na-bg);
  color: var(--pill-na-fg);
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.06em;
}

.move--text {
  width: auto;
  height: auto;
  padding: 3px var(--space-2);
  background: var(--pill-current-bg);
  color: var(--pill-current-fg);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
}

.move--none {
  background: transparent;
  color: var(--text-quaternary);
  font-weight: 500;
}

/* ---------------------------------------------------------------- footer */

.footer {
  font-size: var(--fs-caption);
  color: var(--text-quaternary);
  line-height: 1.6;
}

/* --------------------------------------------------------------- motion */

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

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

  .skeleton-line {
    background: var(--surface-elevated);
  }
}
