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

@layer tokens {
  :root {
    color-scheme: light;
    accent-color: var(--accent);

    /* Brand & interactive palette (Hengjian Archives) */
    --brand: #568825;
    --accent: #477521;
    --accent-hover: #34591b;
    --accent-active: #274414;
    --on-accent: #ffffff;
    --secondary: #526553;
    --secondary-hover: #3f5141;
    --focus: var(--brand);

    /* Surface & neutral hierarchy */
    --ink: #1e2a20;
    --ink-secondary: #39483b;
    --muted: #526151;
    --placeholder: #5f6d5f;
    --paper: #ffffff;
    --ground: #f4f6f2;
    --subtle: #edf2ea;
    --sidebar-surface: #fbfcfa;
    --quiet-hover: #f3f7ef;
    --tint: #e8f1e0;
    --soft-hover: #dae8ce;
    --selected-fill: #cde2b9;
    --selected-hover: #bfd7a8;
    --on-tint: #2f4f24;
    --on-selected: #213a18;
    --selected-row: #2f5121;
    --line: #d4ddd0;
    --line-strong: #b6c4b0;
    --table-divider: #e6ebe3;
    --control-edge: #778d6f;
    --value-outline: #557247;
    --located: #3e5f34;
    --tooltip: #243327;

    /* Semantic status tokens (single source of truth) */
    --neutral-fill: #e9ede7;
    --neutral-text: #465448;
    --neutral-border: #ced6cb;

    --pending-fill: #fff1cf;
    --pending-text: #754700;
    --pending-border: #ebd193;

    --progress-fill: #dceff0;
    --progress-text: #1f575a;
    --progress-border: #b3d8da;

    --checked-fill: #e0efe4;
    --checked-text: #1f5939;
    --checked-border: #b6d6bf;

    --warn: #885511;
    --warn-fill: #fcf0d9;
    --warn-text: #7e4d0c;
    --warn-border: #e7c98f;
    --warn-solid: #885511;
    --warn-solid-hover: #6e420b;

    --danger: #9c3426;
    --danger-fill: #fceae6;
    --danger-text: #942e21;
    --danger-border: #e5b7ae;
    --danger-solid: #a63532;
    --danger-solid-hover: #862926;

    /* Scan canvas & annotations */
    --scan-mat: #dfe4dd;
    --scan-stage-border: #a7b2a4;
    --scan-dark-mat: #1b211d;
    --scan-dark-surface: #242c27;
    --scan-dark-ink: #e5ece3;
    --scan-dark-muted: #bcccb9;
    --scan-dark-line: #3b473f;
    --scan-dark-control: #2d3731;
    --scan-dark-control-hover: #38463d;
    --scan-dark-track: #1d2420;
    --scan-dark-thumb: #334237;
    --scan-dark-warn-text: #f3c46b;
    --scan-dark-warn-fill: rgb(243 196 107 / 14%);
    --scan-dark-warn-border: #d99b38;
    --annotation-border: rgb(70 107 53 / 70%);
    --annotation-fill: rgb(86 136 37 / 5%);
    --annotation-selected: #385f22;
    --annotation-selected-fill: rgb(86 136 37 / 16%);
    --annotation-hover-fill: rgb(86 136 37 / 22%);
    --annotation-draft-fill: rgb(86 136 37 / 14%);
    --annotation-candidate: #9a611d;
    --annotation-candidate-fill: rgb(223 163 56 / 8%);
    --annotation-batch: #00615a;
    --annotation-batch-fill: rgb(0 131 120 / 21%);
    --annotation-batch-candidate-fill: rgb(255 198 90 / 27%);
    --annotation-inspected: #a30755;
    --annotation-inspected-fill: #fae2ee;
    --annotation-inspected-text: #681237;
    --annotation-inspected-box-fill: rgb(218 18 100 / 23%);
    --mark-highlight-bg: #ffe6a4;
    --mark-highlight-fg: #442c04;

    /* Elevation, radii & layout metrics */
    --shadow-xs: 0 1px 2px rgb(24 38 26 / 5%);
    --shadow-sm: 0 2px 8px rgb(28 43 30 / 8%);
    --shadow-md: 0 8px 24px rgb(24 38 26 / 14%);
    --shadow-lg: 0 18px 56px rgb(20 33 22 / 24%);
    --backdrop-scrim: rgb(22 34 25 / 46%);
    --task-drop-scrim: linear-gradient(180deg, rgb(232 241 224 / 94%), rgb(244 246 242 / 96%));
    --tabs-scroll-fade: linear-gradient(90deg, transparent 0%, var(--subtle) 82%);

    /* Archive AI Q&A semantic surfaces & elevation */
    --qa-hero-glow: radial-gradient(closest-side at 50% 45%, rgb(86 136 37 / 8%), transparent 100%);
    --qa-composer-border: #b5c7ad;
    --qa-composer-hover-border: #7a9470;
    --qa-composer-shadow: 0 8px 28px rgb(26 42 28 / 9%), 0 1px 3px rgb(26 42 28 / 5%);
    --qa-composer-focus-shadow: 0 12px 34px rgb(55 96 28 / 14%), 0 0 0 3px rgb(86 136 37 / 18%);
    --qa-composer-docked-shadow: 0 -6px 20px rgb(24 38 26 / 5%), 0 2px 10px rgb(24 38 26 / 7%);
    --qa-user-bubble: #eaf3e3;
    --qa-user-border: #c8deba;
    --qa-avatar-bg: linear-gradient(145deg, #528523, #375e1a);
    --qa-avatar-shadow: 0 2px 6px rgb(55 94 26 / 26%);
    --qa-card-hover-shadow: 0 4px 14px rgb(26 42 28 / 9%);
    --qa-shimmer-base: #eaeee7;
    --qa-shimmer-peak: #f6f9f4;
    --qa-box-fill: rgb(86 136 37 / 17%);
    --qa-box-glow: 0 0 0 4px rgb(86 136 37 / 24%);
    --qa-box-glow-peak: 0 0 0 9px rgb(86 136 37 / 34%);
    --qa-box-secondary-fill: rgb(154 97 29 / 11%);

    /* Login portal — Immersive Twilight Architectural Panorama & Auth Chamber */
    --in-oklab: ;
    --login-bg-deep: #06100f;
    --login-bg-stage: #081514;
    --login-backdrop:
      radial-gradient(64rem 42rem at 28% 24%, rgb(29 58 61 / 48%), transparent 72%),
      linear-gradient(165deg var(--in-oklab), #0b1b1c 0%, #071211 54%, #050c0b 100%);
    --login-backdrop-sizes:
      100% 100%,
      100% 100%;

    --login-card-surface: linear-gradient(
      168deg var(--in-oklab),
      rgb(13 28 31 / 62%) 0%,
      rgb(7 17 19 / 76%) 100%
    );
    --login-card-solid: #091514;
    --login-card-border: rgb(232 243 239 / 15%);
    --login-card-border-focus: rgb(232 243 239 / 23%);
    --login-card-shadow:
      0 28px 68px rgb(0 0 0 / 38%),
      0 1px 0 rgb(255 255 255 / 11%) inset;
    --login-card-bar: linear-gradient(
      90deg,
      transparent 0%,
      rgb(236 244 240 / 26%) 35%,
      rgb(236 244 240 / 42%) 50%,
      rgb(236 244 240 / 26%) 65%,
      transparent 100%
    );
    --login-corner-stroke: transparent;

    --login-ink: #f3f7f5;
    --login-ink-secondary: #d5e2dc;
    --login-muted: #a1b6ad;
    --login-placeholder: #859c92;
    --login-neon: #7bc043;
    --login-cyan: #8ab8a8;
    --login-kicker-accent: #7bc043;

    --login-chip-bg: transparent;
    --login-chip-border: transparent;
    --login-chip-ink: #dce8e1;
    --login-brand-halo: 0 4px 14px rgb(0 0 0 / 28%);

    --login-input-bg: rgb(6 14 16 / 62%);
    --login-input-hover-bg: rgb(7 17 19 / 74%);
    --login-input-focus-bg: rgb(8 20 21 / 86%);
    --login-input-border: #637d77;
    --login-input-hover-border: #809b94;
    --login-input-focus-border: #7bc043;
    --login-input-focus-ring: rgb(123 192 67 / 20%);
    --login-input-focus-shadow:
      inset 0 0 0 1px #7bc043,
      0 0 0 3px var(--login-input-focus-ring);

    --login-autofill-bg: #10231e;
    --login-autofill-ring: #6db338;

    --login-danger: #ff7a6b;
    --login-danger-text: #ffa89e;
    --login-danger-fill: #2a1212;
    --login-danger-border: rgb(255 122 107 / 48%);
    --login-danger-surface: rgb(72 18 18 / 74%);
    --login-input-invalid-ring: rgb(255 122 107 / 22%);
    --login-input-invalid-shadow:
      inset 0 0 0 1px var(--login-danger),
      0 0 0 3px var(--login-input-invalid-ring);
    --login-warn-text: #ffd27d;
    --login-info-surface: rgb(20 46 34 / 76%);
    --login-info-border: rgb(146 202 104 / 32%);

    --login-btn-bg: linear-gradient(180deg, #4e8023 0%, #3c651a 100%);
    --login-btn-hover: linear-gradient(180deg, #588f28 0%, #45731f 100%);
    --login-btn-active: linear-gradient(180deg, #3a6219 0%, #2d4d13 100%);
    --login-btn-border: rgb(196 232 168 / 24%);
    --login-btn-shadow:
      0 8px 22px rgb(0 0 0 / 34%),
      0 1px 0 rgb(255 255 255 / 16%) inset;
    --login-btn-hover-shadow:
      0 10px 26px rgb(0 0 0 / 42%),
      0 1px 0 rgb(255 255 255 / 22%) inset;
    --login-btn-sheen: linear-gradient(
      105deg,
      transparent 22%,
      rgb(255 255 255 / 16%) 50%,
      transparent 78%
    );

    --login-control-hover: rgb(232 242 238 / 9%);
    --login-control-active: rgb(232 242 238 / 15%);
    --login-divider: rgb(228 240 234 / 12%);
    --login-motion-bg: #0b1918;
    --login-motion-border: #4e6963;
    --login-auth-halo: radial-gradient(
      closest-side,
      rgb(6 15 17 / 28%) 0%,
      transparent 100%
    );

    --login-stage-bg: #06100f;
    --login-stage-shadow: none;
    --login-on-stage: #f5f8f6;
    --login-on-stage-muted: rgb(216 227 222 / 82%);
    --login-stage-index: rgb(186 204 195 / 68%);
    --login-glass-bg: transparent;
    --login-glass-card-bg: transparent;
    --login-glass-border: transparent;
    --login-glass-highlight: transparent;
    --login-stage-hairline: rgb(236 244 240 / 16%);
    --login-stage-divider: rgb(236 244 240 / 22%);
    --login-hud-line: rgb(226 238 232 / 22%);
    --login-hud-rail: rgb(176 212 192 / 18%);
    --login-hud-orbit: rgb(214 232 220 / 28%);
    --login-hud-frame: transparent;
    --login-scan-beam: linear-gradient(
      180deg,
      transparent 0%,
      rgb(186 218 202 / 4%) 58%,
      rgb(186 218 202 / 14%) 94%,
      rgb(224 240 230 / 42%) 100%
    );
    --login-scrim:
      linear-gradient(
        90deg var(--in-oklab),
        rgb(5 13 15 / 22%) 0%,
        rgb(5 13 15 / 2%) 24%,
        rgb(5 13 15 / 6%) 48%,
        rgb(6 16 18 / 26%) 64%,
        rgb(6 15 17 / 44%) 84%,
        rgb(5 13 15 / 54%) 100%
      ),
      linear-gradient(
        180deg var(--in-oklab),
        rgb(5 13 15 / 56%) 0%,
        rgb(5 13 15 / 14%) 18%,
        transparent 34%,
        transparent 58%,
        rgb(4 11 12 / 66%) 78%,
        rgb(4 10 11 / 90%) 100%
      );
    --login-scrim-compact: linear-gradient(
      180deg var(--in-oklab),
      rgb(5 13 14 / 56%) 0%,
      rgb(6 15 15 / 68%) 46%,
      rgb(5 13 13 / 86%) 78%,
      rgb(5 12 12 / 94%) 100%
    );
    --login-copy-scrim: none;

    --radius-xs: 0.25rem;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.625rem;
    --radius-xl: 0.75rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;

    --control-height: 2.25rem;
    --control-height-sm: 1.9375rem;
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23526151' stroke-width='1.65' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4.5 6.25 3.5 3.5 3.5-3.5'/%3E%3C/svg%3E");

    --sidebar: 13.75rem;
    --sidebar-collapsed: 4.125rem;
    --page-max: 122rem;

    --font-sans: Inter, 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif;
    --font-mono: 'SFMono-Regular', ui-monospace, Consolas, monospace;
  }

  @supports (background: linear-gradient(in oklab, white, black)) {
    :root {
      --in-oklab: in oklab;
    }
  }
}

@layer reset {
  :where(html) {
    box-sizing: border-box;
    scrollbar-gutter: stable;
  }
  :where(
      body,
      main,
      aside,
      header,
      footer,
      nav,
      section,
      article,
      div,
      form,
      fieldset,
      dialog,
      table,
      thead,
      tbody,
      tr,
      th,
      td,
      input,
      select,
      textarea,
      button,
      a,
      label,
      details,
      summary,
      figure,
      figcaption,
      ul,
      ol,
      li,
      dl,
      dt,
      dd,
      p,
      h1,
      h2,
      h3,
      h4,
      span,
      pre,
      code,
      output
    ) {
    box-sizing: inherit;
  }
  :where(body) {
    margin: 0;
  }
  :where(h1, h2, h3, h4, p) {
    margin: 0;
  }
}

@layer base {
  body {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--ink);
    background: var(--ground);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }

  h1 {
    font-size: clamp(1.375rem, 1.15rem + 0.7vw, 1.75rem);
    line-height: 1.28;
    font-weight: 680;
    letter-spacing: -0.025em;
    text-wrap: balance;
  }

  h2 {
    font-size: 1rem;
    line-height: 1.4;
    font-weight: 650;
  }

  h3 {
    font-size: 0.9375rem;
    line-height: 1.4;
    font-weight: 620;
  }

  a {
    color: var(--accent);
    text-underline-offset: 3px;
  }

  img,
  a[draggable='false'] {
    user-select: none;
    -webkit-user-drag: none;
  }

  svg {
    display: inline-block;
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.65;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  :focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
  }

  [hidden] {
    display: none !important;
  }

  input[type='checkbox'],
  input[type='radio'] {
    accent-color: var(--accent);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--placeholder);
  }

  textarea {
    width: 100%;
    resize: vertical;
    line-height: 1.6;
  }

  .quiet,
  .empty {
    color: var(--muted);
    font-size: 0.75rem;
  }

  .code,
  .num {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
  }

  .nowrap {
    white-space: nowrap;
  }

  .skip {
    position: fixed;
    inset-inline-start: 0.75rem;
    inset-block-start: -4.5rem;
    z-index: 50;
    background: var(--paper);
    color: var(--ink);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.875rem;
    font-weight: 600;
    text-decoration: none;
    box-shadow: var(--shadow-md);
  }

  .skip:focus {
    inset-block-start: 0.75rem;
  }

  @media (prefers-reduced-motion: reduce) {
    * {
      scroll-behavior: auto !important;
    }
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
      animation: none !important;
    }
  }

    @media (forced-colors: active) {
      :focus-visible {
        outline: 3px solid Highlight;
      }
      select:not(.page-jump-select) {
        appearance: auto;
        background-image: none;
      }
    .surface,
    .source-panel,
    .review-panel,
    .metrics,
    .company-picker,
    .account-bar,
    .page-title-mark,
    .icon-action,
    .page-nav-btn,
    .item-step-btn,
    button,
    .action,
    .back-link,
    .tag,
    .task-state,
    dialog,
    [popover] {
      border: 1px solid CanvasText;
    }
    nav a[aria-current='page'],
    .category-pick[aria-current='true'],
    #itemList button[aria-current='true'] {
      border: 2px solid Highlight;
    }
  }
}

@layer utilities {
  .visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }
}
