/* Matcher admin backend. System fonts only: the backend must work without reaching Google Fonts. */

@layer reset, tokens, base, components, views;

/* ---------- Tokens ---------- */

@layer tokens {
  :root {
    color-scheme: light;
    --bg: #f7f7f8;
    --surface: #ffffff;
    --surface-2: #f2f2f4;
    --surface-3: #e9e9ec;
    --text: #18181b;
    --text-2: #52525b;
    --text-3: #8b8b94;
    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --primary: #18181b;
    --primary-text: #fafafa;
    --brand: #c8352b;
    --focus: #2563eb;

    --info: #2563eb;
    --info-bg: #eff4ff;
    --success: #15803d;
    --success-bg: #ecfdf3;
    --warning: #b45309;
    --warning-bg: #fff8eb;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --neutral: #71717a;
    --neutral-bg: #f4f4f5;

    --log-bg: #fbfbfc;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
    --shadow-md: 0 1px 3px rgb(0 0 0 / 0.06), 0 1px 2px rgb(0 0 0 / 0.04);
    --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / 0.25);
    --backdrop: rgb(9 9 11 / 0.45);

    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --ease: cubic-bezier(0.2, 0, 0, 1);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --bg: #09090b;
      --surface: #111113;
      --surface-2: #18181b;
      --surface-3: #232327;
      --text: #f4f4f5;
      --text-2: #a1a1aa;
      --text-3: #71717a;
      --border: #26262a;
      --border-strong: #34343a;
      --primary: #f4f4f5;
      --primary-text: #09090b;
      --brand: #e5483d;
      --focus: #60a5fa;
      --info: #60a5fa;
      --info-bg: #172036;
      --success: #4ade80;
      --success-bg: #0f2418;
      --warning: #fbbf24;
      --warning-bg: #2a1f0a;
      --danger: #f87171;
      --danger-bg: #2c1111;
      --neutral: #a1a1aa;
      --neutral-bg: #1f1f23;
      --log-bg: #0c0c0e;
      --shadow-sm: none;
      --shadow-md: none;
      --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / 0.7);
      --backdrop: rgb(0 0 0 / 0.65);
    }
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #09090b;
    --surface: #111113;
    --surface-2: #18181b;
    --surface-3: #232327;
    --text: #f4f4f5;
    --text-2: #a1a1aa;
    --text-3: #71717a;
    --border: #26262a;
    --border-strong: #34343a;
    --primary: #f4f4f5;
    --primary-text: #09090b;
    --brand: #e5483d;
    --focus: #60a5fa;
    --info: #60a5fa;
    --info-bg: #172036;
    --success: #4ade80;
    --success-bg: #0f2418;
    --warning: #fbbf24;
    --warning-bg: #2a1f0a;
    --danger: #f87171;
    --danger-bg: #2c1111;
    --neutral: #a1a1aa;
    --neutral-bg: #1f1f23;
    --log-bg: #0c0c0e;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: 0 20px 40px -12px rgb(0 0 0 / 0.7);
    --backdrop: rgb(0 0 0 / 0.65);
  }
}

/* ---------- Reset & base ---------- */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  button, input, select, textarea { font: inherit; color: inherit; }
  ul, ol { padding: 0; list-style: none; }
  [hidden] { display: none !important; }
}

@layer base {
  html { -webkit-text-size-adjust: 100%; }
  body {
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
  h2 { font-size: 18px; }
  h3 { font-size: 15px; }
  code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
  code { padding: 1px 5px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
  .muted { color: var(--text-2); }
  .text-danger { color: var(--danger); }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
}

/* ---------- Components ---------- */

@layer components {
  /* Buttons */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 34px; padding: 0 14px; border-radius: var(--radius);
    border: 1px solid transparent; background: transparent;
    font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer;
    transition: background-color 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease), opacity 120ms;
  }
  .btn:disabled { opacity: 0.5; cursor: not-allowed; }
  .btn-primary { background: var(--primary); color: var(--primary-text); }
  .btn-primary:not(:disabled):hover { opacity: 0.88; }
  .btn-outline { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
  .btn-outline:not(:disabled):hover { background: var(--surface-2); }
  .btn-ghost { color: var(--text-2); }
  .btn-ghost:not(:disabled):hover { background: var(--surface-2); color: var(--text); }
  .btn-danger { background: var(--danger); color: #fff; }
  .btn-danger:not(:disabled):hover { opacity: 0.9; }
  .btn-danger-outline { color: var(--danger); }
  .btn-danger-outline:not(:disabled):hover { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
  .btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
  .btn-xs { height: 26px; padding: 0 8px; font-size: 12px; gap: 4px; border-radius: var(--radius-sm); }
  .btn-xs .icon { width: 14px; height: 14px; }
  .btn-icon { width: 34px; padding: 0; }
  .btn-icon.btn-sm { width: 30px; }
  .btn-block { width: 100%; }
  .btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
  .btn.is-loading::after {
    content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid var(--primary-text); border-right-color: transparent; animation: spin 0.7s linear infinite;
  }
  .link { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
  .link:hover { color: var(--focus); }

  /* Badges and status dots */
  .badge {
    display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
    border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
    background: var(--neutral-bg); color: var(--neutral); border: 1px solid transparent;
  }
  .tone-info.badge { background: var(--info-bg); color: var(--info); }
  .tone-success.badge { background: var(--success-bg); color: var(--success); }
  .tone-warning.badge { background: var(--warning-bg); color: var(--warning); }
  .tone-danger.badge { background: var(--danger-bg); color: var(--danger); }
  .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
  .dot.is-pulsing { animation: pulse 1.4s ease-in-out infinite; }

  /* Forms */
  .field { display: grid; gap: 6px; }
  .label { font-size: 13px; font-weight: 500; }
  .hint { font-size: 12px; color: var(--text-3); }
  .input {
    width: 100%; height: 36px; padding: 0 10px; border-radius: var(--radius);
    border: 1px solid var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm);
    transition: border-color 120ms, box-shadow 120ms;
  }
  .input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
  .input:disabled { opacity: 0.6; }
  .input-sm { height: 30px; font-size: 13px; }
  select.input { padding-right: 28px; appearance: none; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8b94' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
  .input-wrap { position: relative; display: block; }
  .input-icon { position: absolute; left: 10px; top: 50%; translate: 0 -50%; color: var(--text-3); pointer-events: none; }
  .input.has-icon { padding-left: 32px; }
  .input-action { position: absolute; right: 4px; top: 50%; translate: 0 -50%; display: grid; place-items: center;
    width: 28px; height: 28px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-3); cursor: pointer; }
  .input-action:hover { color: var(--text); background: var(--surface-2); }
  .input-row { display: flex; gap: 8px; }
  .form-error { min-height: 1em; color: var(--danger); font-size: 13px; }
  .form-error:empty { display: none; }
  .toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; white-space: nowrap; }
  .toggle input { accent-color: var(--primary); width: 14px; height: 14px; }

  /* Notices */
  .notice { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); font-size: 13px; }
  .notice .icon { margin-top: 2px; }
  .notice-danger { background: var(--danger-bg); color: var(--danger); }
  .notice-warning { background: var(--warning-bg); color: var(--warning); }

  /* Modal dialogs */
  dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); }
  dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
  .modal { width: min(560px, calc(100vw - 32px)); border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: var(--shadow-lg); margin: auto; }
  .modal-sm { width: min(420px, calc(100vw - 32px)); }
  .modal[open] { animation: pop-in 180ms var(--ease); }
  .modal-head { display: flex; justify-content: space-between; gap: 16px; padding: 20px 20px 0; }
  .modal-head p { margin-top: 4px; font-size: 13px; }
  .modal-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 20px; }
  .modal-body > h2 { font-size: 16px; }
  .modal-body > h2 + p { margin-top: -10px; }
  .modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
  .grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

  .disclosure { border: 1px solid var(--border); border-radius: var(--radius); }
  .disclosure > summary { padding: 9px 12px; cursor: pointer; font-size: 13px; color: var(--text-2); list-style-position: inside; }
  .disclosure[open] > summary { border-bottom: 1px solid var(--border); }
  .disclosure > :not(summary) { margin: 12px; }
  .code-block { position: relative; }
  .code-block pre { padding: 12px; padding-right: 72px; border-radius: var(--radius); background: var(--log-bg); border: 1px solid var(--border);
    font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; color: var(--text-2); }
  .code-copy { position: absolute; top: 6px; right: 6px; }

  /* Toasts */
  .toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
  .toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 13px;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toast-in 200ms var(--ease); }
  .toast .icon { margin-top: 1px; }
  .toast-success .icon { color: var(--success); }
  .toast-error .icon { color: var(--danger); }
  .toast-info .icon { color: var(--info); }
  .toast.is-leaving { animation: toast-out 160ms var(--ease) forwards; }

  /* Sparkline and meter */
  .spark { display: block; width: 100%; height: 24px; overflow: visible; }
  .spark-line { fill: none; stroke: var(--text-3); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
  .spark-area { fill: color-mix(in srgb, var(--text-3) 12%, transparent); }
  .meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin: 9px 0; }
  .meter > span { display: block; height: 100%; border-radius: inherit; background: var(--success); transition: width 300ms var(--ease); }
  .meter.is-warning > span { background: var(--warning); }
  .meter.is-danger > span { background: var(--danger); }

  .logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--brand); color: #fff; flex: none; }
  .logo .icon { width: 22px; height: 22px; }
  .logo-sm { width: 30px; height: 30px; border-radius: 8px; }
  .logo-sm .icon { width: 17px; height: 17px; }
}

@keyframes spin { to { rotate: 360deg; } }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes shimmer { 50% { opacity: 0.55; } }
@keyframes pop-in { from { opacity: 0; scale: 0.97; } }
@keyframes slide-in { from { translate: 24px 0; opacity: 0; } }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } }
@keyframes toast-out { to { opacity: 0; translate: 0 8px; } }

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