/* Super_T Monitor design system: tokens + component looks. The single source of truth (DESIGN.md).
   Loaded FIRST. styles.css holds page/layout specifics only and never redefines a component. */

@font-face {
  font-family: Anuphan;
  src: url('/monitor/fonts/Anuphan.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/monitor/fonts/JetBrainsMono.ttf') format('truetype');
  font-weight: 100 900;
  font-display: swap;
}

/* #region zone:monitor.ui.interval — แผนภาพช่วงค่าใช้โทเคนกลาง */
.ui-interval {
  display: grid;
  grid-template-columns: minmax(0, 260px) minmax(0, 640px) max-content;
  gap: var(--s-2) var(--s-3);
  margin: var(--s-5) 0;
  min-width: 0;
}
.ui-interval-row {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
  align-items: center;
}
.ui-interval-plot {
  min-width: 0;
  padding-inline: var(--s-4);
}
.ui-interval-plot > svg {
  width: 100%;
  min-width: 0;
  height: 32px;
  display: block;
  overflow: visible;
}
.ui-interval-grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
}
.ui-interval-ticks {
  display: flex;
  justify-content: space-between;
  padding-inline: var(--s-2);
  color: var(--text-3);
  font-size: var(--fs-xs);
}
.ui-interval-tick {
  width: 0;
  display: flex;
  justify-content: center;
}
.ui-interval-value {
  max-width: 14rem;
  white-space: normal;
}
.ui-interval > figcaption {
  grid-column: 1 / -1;
}
.ui-interval-track {
  stroke: var(--chart-grid);
  stroke-width: 1;
}
.ui-interval-range {
  stroke: var(--series-1);
  stroke-width: 2;
}
.ui-interval-point {
  fill: var(--series-1);
}
@media (max-width: 700px) {
  /* phone: label and value share a line, the plot (and the tick row) take the full width below */
  .ui-interval {
    grid-template-columns: minmax(0, 1fr);
  }
  .ui-interval-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'label value' 'plot plot';
    row-gap: var(--s-1);
  }
  .ui-interval-row > span:first-child {
    grid-area: label;
  }
  .ui-interval-row > .ui-interval-plot,
  .ui-interval-axis > .ui-interval-ticks {
    grid-area: plot;
  }
  .ui-interval-row > .ui-interval-value {
    grid-area: value;
    text-align: right;
  }
  .ui-interval-axis > span {
    display: none;
  }
}
/* #endregion */
/* #region zone:monitor.ui.tokens — โทเคน */
:root {
  --surface-0: var(--u-page);
  --surface-sidebar: var(--u-page);
  --surface-1: var(--u-card);
  --surface-2: var(--u-card);
  --surface-3: var(--u-card-2);
  --surface-hover: var(--u-card-2);
  --surface-raised: var(--u-sheet);
  --border: var(--u-border);
  --border-soft: var(--u-border);
  --border-strong: var(--u-border);
  --header-bg: var(--u-glass);
  --shadow-raised: none;
  --shadow-overlay: var(--u-shadow-overlay);
  --text-1: var(--u-text);
  --text-2: var(--u-text-muted);
  --text-3: var(--u-text-muted);
  --text-faint: var(--u-text-muted);
  --s-1: var(--u-space-1, 4px);
  --s-2: var(--u-space-2, 8px);
  --s-3: var(--u-space-3, 12px);
  --s-4: var(--u-space-4, 16px);
  --s-5: 20px;
  --s-6: var(--u-space-5, 24px);
  --s-7: 28px;
  --s-8: var(--u-space-6, 32px);
  --s-10: 40px;
  --s-12: 48px;
  --card-padding: var(--s-6);
  --card-header-gap: var(--s-4);
  --filter-content-gap: var(--s-3);
  --control-stack-gap: var(--s-2);
  --table-cell-block: var(--s-2);
  --table-cell-inline: var(--s-4);
  --table-inset: var(--s-3);
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-full: var(--u-radius-pill, 999px);
  --h-sm: 32px;
  --h-md: 38px;
  --h-lg: 44px;
  --fs-xs: var(--u-text-xs, 12px);
  --fs-sm: var(--u-text-sm, 13px);
  --fs-md: var(--u-text-md);
  --fs-lg: var(--u-text-lg);
  --fs-xl: var(--u-text-xl);
  --fs-2xl: var(--u-text-2xl);
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --icon-sm: 16px;
  --icon-md: 18px;
  --icon-lg: 20px;
  --icon-xl: 32px;
  --dur-fast: 120ms;
  --dur: 180ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: Anuphan, 'Noto Sans Thai', 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --content-max: 1360px;
  --gutter: 24px;
  --sidebar-w: 248px;
  --topbar-h: 64px;
  --luna-size: 52px;
  --luna-clear: calc(var(--luna-size) + var(--gutter) * 2 + env(safe-area-inset-bottom, 0px));
}
:root,
:root[data-theme='dark'] {
  --accent: #3ecf8e;
  --accent-hover: #57da9f;
  --accent-fg: #052117;
  --accent-soft: rgba(62, 207, 142, 0.13);
  --accent-text: #5edba2;
  --switch-on: var(--success);
  --switch-off: var(--text-3);
  --switch-blocked: var(--warning);
  --switch-knob: var(--surface-1);
  --success: #3ecf8e;
  --success-soft: rgba(62, 207, 142, 0.13);
  --success-fg: #62dba4;
  --warning: #f5a623;
  --warning-soft: rgba(245, 166, 35, 0.14);
  --warning-fg: #f7ba55;
  --danger: #f2545b;
  --danger-soft: rgba(242, 84, 91, 0.14);
  --danger-fg: #f77b80;
  --info: #6fa8ff;
  --info-soft: rgba(111, 168, 255, 0.14);
  --info-fg: #8dbaff;
  --neutral-soft: rgba(255, 255, 255, 0.07);
  --neutral-fg: #bac5c0;
  --focus: #3ecf8e;
  --focus-ring: 0 0 0 3px rgba(62, 207, 142, 0.28);
  --scrim: rgba(3, 5, 4, 0.62);
  --chart-grid: rgba(255, 255, 255, 0.07);
  --chart-base: rgba(255, 255, 255, 0.18);
  --chart-label: #7f8a85;
  --chart-cpu: #5b9dff;
  --chart-memory: #b98bff;
  --chart-line-received: #3ecf8e;
  --chart-line-accepted: #8be0ba;
  --chart-queue-processing: #f5a623;
  --chart-queue-outgoing: #ffd479;
  /* Categorical series, fixed order (validated: CVD, lightness and contrast against --surface-1 #141817) */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --line-bg: #8cabd8;
  --line-bubble: #ffffff;
  --line-ink: #111111;
  --scheme: dark;
}
:root[data-theme='light'] {
  --accent: #138456;
  --accent-hover: #0f7149;
  --accent-fg: #ffffff;
  --accent-soft: rgba(19, 132, 86, 0.1);
  --accent-text: #0f7149;
  --success: #138456;
  --success-soft: rgba(19, 132, 86, 0.1);
  --success-fg: #0f6e47;
  --warning: #a86400;
  --warning-soft: rgba(214, 138, 0, 0.13);
  --warning-fg: #8a5200;
  --danger: #c0303a;
  --danger-soft: rgba(192, 48, 58, 0.1);
  --danger-fg: #a4252f;
  --info: #1f5fbf;
  --info-soft: rgba(31, 95, 191, 0.1);
  --info-fg: #1a52a6;
  --neutral-soft: rgba(16, 24, 20, 0.06);
  --neutral-fg: #3a4842;
  --focus: #138456;
  --focus-ring: 0 0 0 3px rgba(19, 132, 86, 0.25);
  --scrim: rgba(20, 28, 24, 0.38);
  --chart-grid: rgba(16, 24, 20, 0.07);
  --chart-base: rgba(16, 24, 20, 0.2);
  --chart-label: #5e6b65;
  --chart-cpu: #1a62cc;
  --chart-memory: #7a45d0;
  --chart-line-received: #0f7a50;
  --chart-line-accepted: #52b889;
  --chart-queue-processing: #9a5b00;
  --chart-queue-outgoing: #e5a92b;
  /* Categorical series, fixed order (validated against --surface-1 #ffffff; slot 3-4 below 3:1 so charts also ship a legend, tooltip and table view) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --scheme: light;
}
@media (max-width: 699px) {
  :root {
    --h-md: 44px;
    --gutter: 16px;
    --card-padding: var(--s-4);
    --table-inset: var(--s-3);
  }
}
@media (pointer: coarse) {
  :root {
    --h-sm: 44px;
    --h-md: 44px;
    --touch-min: 44px;
  }
  /* Every control reaches the 44 px touch minimum; the gate's TAP_TARGET rule enforces it. */
  .chip {
    min-width: var(--touch-min);
    justify-content: center;
  }
  summary {
    min-height: var(--touch-min);
    padding-block: max(var(--s-2), calc((var(--touch-min) - 1lh) / 2));
  }
}

/* #endregion */
/* #region zone:monitor.component.luna — แชท Agent และ infographic ตามโทเคนกลาง */
.monitor-luna {
  --luna-line: var(--border);
  --luna-surface: var(--surface-2);
  --luna-text: var(--text-1);
  --luna-muted: var(--text-3);
  position: fixed;
  z-index: 45;
  right: calc(var(--gutter) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--luna-clear) + var(--s-2));
  width: min(460px, calc(100vw - 2 * var(--gutter)));
  height: min(760px, calc(100dvh - var(--topbar-h) - var(--luna-clear) - var(--s-4)));
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-overlay);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  color: var(--text-1);
}
.monitor-luna[hidden],
.btn.monitor-luna-launcher[hidden] {
  display: none;
}
.monitor-luna > header {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.monitor-luna > header > div {
  flex: 1;
  min-width: 0;
}
.monitor-luna h2 {
  font-size: 19px;
  margin: 0;
}
.monitor-luna header p,
.monitor-luna > small {
  font-size: var(--u-text-xs);
  color: var(--text-3);
  line-height: 1.6;
  margin: 0;
}
.monitor-luna-avatar {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--surface-2);
}
.ai-mascot {
  --mascot-shell: #a8f3d0;
  --mascot-visor: #102c22;
  --mascot-eye: #c0ffdf;
  display: inline-block;
  width: 32px;
  height: 32px;
  flex: none;
  vertical-align: middle;
}
:root[data-theme='light'] .ai-mascot {
  --mascot-shell: #e2fff0;
  --mascot-visor: #0b3d2c;
}
.ai-mascot-glow {
  fill: var(--accent-soft);
}
.ai-mascot-accent {
  fill: var(--accent);
}
.ai-mascot-shell {
  fill: var(--mascot-shell);
  stroke: var(--accent);
  stroke-width: 2;
}
.ai-mascot-visor {
  fill: var(--mascot-visor);
}
.ai-mascot-eye {
  fill: var(--mascot-eye);
}
.ai-mascot-line,
.ai-mascot-smile {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
}
.ai-mascot-smile {
  stroke: var(--mascot-eye);
  stroke-width: 2;
}
/* Floating bottom-right like Finance/Account. The ring and busy halo come from assistant/luna-thinking.css.
   Page content is never covered: #main reserves --luna-clear below its last row (styles.css). */
.btn.monitor-luna-launcher {
  position: fixed;
  z-index: 44;
  right: calc(var(--gutter) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  display: grid;
  place-items: center;
  flex: none;
  gap: 0;
  width: var(--luna-size);
  min-width: var(--luna-size);
  height: var(--luna-size);
  padding: 0;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  box-shadow: none;
}
/* Back to top: round 44px button stacked directly above the Luna launcher (same right edge). */
.btn.back-to-top {
  position: fixed;
  z-index: 43;
  right: calc(var(--gutter) + env(safe-area-inset-right, 0px) + (var(--luna-size) - 44px) / 2);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px) + var(--luna-size) + var(--s-3));
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--r-full);
  box-shadow: var(--shadow-raised);
}
.btn.back-to-top[hidden] {
  display: none;
}
@media (prefers-reduced-motion: no-preference) {
  .btn.back-to-top {
    animation: back-to-top-in var(--dur) var(--ease);
  }
}
@keyframes back-to-top-in {
  from {
    opacity: 0;
    transform: translateY(var(--s-2));
  }
}
.monitor-luna-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.monitor-luna-bubble {
  margin-bottom: var(--s-4);
  padding: var(--s-3);
  background: var(--surface-2);
  border-radius: var(--r-lg);
  font-size: 14px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}
.monitor-luna-bubble.user {
  background: var(--accent-soft);
  margin-left: var(--s-8);
}
.monitor-luna-bubble > p {
  margin: 0;
  white-space: pre-wrap;
}
.monitor-luna-controls,
.monitor-luna-links {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-top: var(--s-3);
}
.monitor-luna form textarea {
  width: 100%;
  resize: none;
}
.monitor-luna-status {
  margin: 0;
  font-size: var(--u-text-xs);
  color: var(--text-3);
}
.monitor-luna.is-thinking .monitor-luna-status {
  color: var(--accent);
}
.monitor-luna-error {
  color: var(--danger);
  font-size: var(--u-text-xs);
  margin: 0;
}
.monitor-luna-prompts {
  display: flex;
  gap: var(--s-2);
  overflow: auto;
  flex-shrink: 0;
}
.monitor-luna-prompts .btn {
  white-space: nowrap;
}
.monitor-luna-welcome {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-2);
}
@media (max-width: 600px) {
  .monitor-luna {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(680px, calc(100dvh - var(--topbar-h) - var(--s-4)));
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: calc(var(--s-4) + env(safe-area-inset-bottom, 0px));
  }
}
@media (max-width: 700px) {
  .monitor-luna {
    padding: var(--s-4);
  }
  .luna-metric-label {
    flex-wrap: wrap;
  }
}
/* #endregion */
/* #region zone:monitor.ui.base — พื้นฐาน */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  color-scheme: var(--scheme);
  -webkit-text-size-adjust: 100%;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--surface-0);
}
body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  min-width: 320px;
}
button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}
h1,
h2,
h3,
h4,
p {
  margin: 0;
}
h1 {
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  line-height: 1.3;
}
h2 {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: 1.35;
}
h3 {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  line-height: 1.4;
}
a {
  color: var(--accent-text);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
[hidden] {
  display: none !important;
}
.icon {
  width: var(--icon-md);
  height: var(--icon-md);
  flex: none;
  display: block;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.num,
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-sm);
}
.num {
  white-space: nowrap;
}
.muted {
  color: var(--text-3);
  font-size: var(--fs-sm);
}
kbd,
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 var(--s-1);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 500 11px/1 var(--mono);
  color: var(--text-3);
  background: var(--surface-2);
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
::selection {
  background: var(--accent-soft);
}
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* #endregion */

/* #region zone:monitor.component.ops-sheet — แชทติดขอบล่างและชิปคำถามไม่หดทับกัน */
.monitor-luna {
  overflow: hidden;
}
.monitor-luna > :not(.monitor-luna-log) {
  flex-shrink: 0;
  min-width: 0;
}
.monitor-luna form {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.monitor-luna form textarea,
.monitor-luna > input {
  font-size: max(16px, 1rem);
}
.monitor-luna-controls {
  margin-top: 0;
}
.monitor-luna-prompts {
  padding: var(--s-1) var(--s-2);
  scroll-padding-inline: var(--s-2);
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
.monitor-luna-prompts .btn.u-chip {
  flex: 0 0 auto;
  width: auto;
  min-height: 44px;
  height: auto;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  scroll-snap-align: start;
}
.monitor-luna-prompts .btn.u-chip:hover {
  background: var(--accent-soft);
}
.monitor-luna-status {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  line-height: 1.6;
}
.monitor-luna-feedback {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.monitor-luna-feedback:has(.monitor-luna-error[hidden]) {
  display: none;
}
.monitor-luna-feedback .monitor-luna-error {
  flex: 1;
  max-height: 72px;
  overflow-y: auto;
}
.monitor-luna-feedback button {
  flex: none;
}
.monitor-luna-dots {
  letter-spacing: 0.15em;
}
.monitor-luna [hidden] {
  display: none;
}
@media (min-width: 768px) {
  .monitor-luna-prompts {
    flex-wrap: wrap;
  }
}
@media (max-width: 767px) {
  .monitor-luna-prompts {
    -webkit-mask-image: linear-gradient(
      90deg,
      transparent,
      #000 var(--s-2),
      #000 calc(100% - var(--s-4)),
      transparent
    );
    mask-image: linear-gradient(
      90deg,
      transparent,
      #000 var(--s-2),
      #000 calc(100% - var(--s-4)),
      transparent
    );
  }
  .monitor-luna[data-viewport-sheet] {
    left: 0;
    right: 0;
    top: auto;
    bottom: var(--u-keyboard-inset, 0px);
    width: 100%;
    max-width: 100%;
    height: min(680px, calc(var(--u-viewport-height, 100dvh) - env(safe-area-inset-top, 0px) - var(--s-2)));
    padding: var(--s-3);
    padding-bottom: calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
    gap: var(--s-2);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .monitor-luna > header p,
  .monitor-luna > small {
    font-size: 11px;
    line-height: 1.4;
  }
  .monitor-luna-avatar {
    width: 36px;
    height: 36px;
  }
  .monitor-luna textarea {
    height: 68px;
    min-height: 44px;
    padding: var(--s-2);
    line-height: 1.5;
  }
  .monitor-luna[data-viewport-compact]:has(.monitor-luna-error:not([hidden])) .monitor-luna-prompts {
    display: none;
  }
  .monitor-luna[data-viewport-compact] > input,
  .monitor-luna[data-viewport-compact] > small,
  .monitor-luna[data-viewport-compact] > header p {
    display: none;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .monitor-luna.is-thinking .monitor-luna-avatar {
    animation: ops-avatar-bob 1.8s ease-in-out infinite;
  }
  .monitor-luna.is-thinking .ai-mascot-eye {
    transform-box: fill-box;
    transform-origin: center;
    animation: ops-avatar-blink 3.6s infinite;
  }
  .monitor-luna-dots {
    animation: ops-typing 1.2s ease-in-out infinite;
  }
  .monitor-luna-status-text.is-swap {
    animation: ops-status-fade 0.35s ease-out;
  }
}
@keyframes ops-avatar-bob {
  50% {
    transform: translateY(-3px) rotate(-3deg);
  }
}
@keyframes ops-avatar-blink {
  0%,
  44%,
  50%,
  100% {
    transform: scaleY(1);
  }
  47% {
    transform: scaleY(0.12);
  }
}
@keyframes ops-typing {
  50% {
    opacity: 0.35;
  }
}
@keyframes ops-status-fade {
  from {
    opacity: 0.2;
  }
  to {
    opacity: 1;
  }
}
/* #endregion */
