/* ==========================================================================
   NEXGATE AI — Refinement layer
   --------------------------------------------------------------------------
   Loaded last (after style.css / admin.css / auth.css / mobile.css).

   This file deliberately works WITH the base design system instead of
   painting over pieces of it.

   Why this approach:
     • The base sheets are fully token driven — style.css alone references
       var(--token) over 1,200 times. Redefining the SAME token names
       (--bg-*, --text-*, --border, --accent, --user-msg) shifts every screen
       together: chat, settings, billing, tasks, projects, admin, API portal.
       Overriding individual selectors instead leaves whole screens on the old
       palette, which is what made the previous layer feel inconsistent.
     • Radii and shadows keep the base scale (6–12px). Nothing is moved onto a
       different scale — that mismatch was the other half of the inconsistency.
     • Only genuine excess is removed: the animated blurred "ambient" blobs and
       the near-invisible low-contrast greys.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Palette — dark (default theme)
   -------------------------------------------------------------------------- */
:root,
[data-theme="dark"] {
  --bg-primary: #1e1e21;
  --bg-secondary: #161618;
  --bg-sidebar: #111113;
  --bg-hover: #2c2c31;
  --bg-input: #28282d;
  --user-msg: #2c2c31;

  --text-primary: #eaeaec;
  --text-secondary: #b0b4ba;

  --border: #34343a;
  --border-subtle: rgba(255, 255, 255, 0.07);

  --accent: #46a8c2;
  --accent-fg: #031d26;

  --chat-grid-bg: #232327;
  --chat-grid-dot: rgba(255, 255, 255, 0.07);

  /* Auth screens carry their own token set in auth.css. Redefined here so the
     auth pages share the app palette and stay readable (the base files go as
     low as 28% white on the faint text). */
  --ng-black: #0a0a0d;
  --ng-surface: #101014;
  --ng-elevated: #16161b;
  --ng-line: rgba(255, 255, 255, 0.09);
  --ng-line-strong: rgba(255, 255, 255, 0.16);
  --ng-text: #f2f3f5;
  --ng-text-muted: rgba(255, 255, 255, 0.64);
  --ng-text-subtle: rgba(255, 255, 255, 0.44);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f9;
  --bg-sidebar: #f1f1f4;
  --bg-hover: #e9e9ee;
  --bg-input: #f4f4f7;
  --user-msg: #ececf1;

  --text-primary: #15161a;
  --text-secondary: #55585f;

  --border: #dcdce2;
  --border-subtle: rgba(0, 0, 0, 0.07);

  /* The base light accent (#7ee8ff) is too pale on white — darkened for
     contrast and used as a proper interactive colour. */
  --accent: #0b6f8a;
  --accent-fg: #ffffff;

  --chat-grid-bg: #e7eaf0;
  --chat-grid-dot: rgba(20, 30, 50, 0.14);

  /* The auth sheets are dark-only; give them a light palette too. */
  --ng-black: #ffffff;
  --ng-surface: #f6f6f9;
  --ng-elevated: #ededf2;
  --ng-line: rgba(0, 0, 0, 0.1);
  --ng-line-strong: rgba(0, 0, 0, 0.18);
  --ng-text: #15161a;
  --ng-text-muted: rgba(0, 0, 0, 0.64);
  --ng-text-subtle: rgba(0, 0, 0, 0.44);
}

[data-theme="midnight"] {
  --bg-primary: #000000;
  --bg-secondary: #08080a;
  --bg-sidebar: #000000;
  --bg-hover: #121215;
  --bg-input: #0a0a0c;
  --user-msg: #121215;

  --text-primary: #ffffff;
  /* 0.45 white on black is under the comfortable reading threshold. */
  --text-secondary: rgba(255, 255, 255, 0.58);

  --border: rgba(255, 255, 255, 0.1);
  --border-subtle: rgba(255, 255, 255, 0.06);

  --accent: #a6e3f4;
  --accent-fg: #000000;

  --chat-grid-bg: #0a0a0c;
  --chat-grid-dot: rgba(255, 255, 255, 0.07);

  --ng-black: #000000;
  --ng-surface: #0a0a0d;
  --ng-elevated: #111115;
  --ng-line: rgba(255, 255, 255, 0.1);
  --ng-line-strong: rgba(255, 255, 255, 0.18);
  --ng-text: #ffffff;
  --ng-text-muted: rgba(255, 255, 255, 0.66);
  --ng-text-subtle: rgba(255, 255, 255, 0.46);
}

[data-theme="system"] {
  --bg-primary: #1e1e21;
  --bg-secondary: #161618;
  --bg-sidebar: #111113;
  --bg-hover: #2c2c31;
  --bg-input: #28282d;
  --user-msg: #2c2c31;

  --text-primary: #eaeaec;
  --text-secondary: #b0b4ba;

  --border: #34343a;
  --border-subtle: rgba(255, 255, 255, 0.07);

  --accent: #46a8c2;
  --accent-fg: #031d26;

  --chat-grid-bg: #232327;
  --chat-grid-dot: rgba(255, 255, 255, 0.07);
}

@media (prefers-color-scheme: light) {
  [data-theme="system"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f9;
    --bg-sidebar: #f1f1f4;
    --bg-hover: #e9e9ee;
    --bg-input: #f4f4f7;
    --user-msg: #ececf1;

    --text-primary: #15161a;
    --text-secondary: #55585f;

    --border: #dcdce2;
    --border-subtle: rgba(0, 0, 0, 0.07);

    --accent: #0b6f8a;
    --accent-fg: #ffffff;

    --chat-grid-bg: #e7eaf0;
    --chat-grid-dot: rgba(20, 30, 50, 0.14);
  }
}

/* --------------------------------------------------------------------------
   2. Remove excess decoration
   -------------------------------------------------------------------------- */
/* The animated blurred blobs behind the auth layout read as noise rather than
   polish, and cost a compositing layer on every frame. */
.auth-ambient,
.auth-ambient-layer,
.auth-ambient-wave {
  display: none;
}

/* auth.css uppercases every label it owns, which turns "Googleでログイン" into
   "GOOGLEでログイン" and mixes two typographic systems. */
.auth-oauth-btn,
.auth-oauth-btn span {
  text-transform: none;
  letter-spacing: 0;
}

/* --------------------------------------------------------------------------
   3. Interaction states — one consistent focus ring everywhere
   -------------------------------------------------------------------------- */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   4. Typography — hierarchy from weight and spacing, not from new sizes
   -------------------------------------------------------------------------- */
.auth-panel-title,
.settings-panel-header h2,
.settings-card h3 {
  letter-spacing: -0.01em;
}

.auth-hero-eyebrow,
.settings-card h3,
.admin-model-card__section-title {
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------------------
   5. Restraint where the base gets loud
   -------------------------------------------------------------------------- */
/* The assistant avatar is filled with the full brand gradient, making it the
   single brightest element on the chat screen. A flat accent keeps it
   identifiable without competing with the message next to it. */
.message.assistant .message-avatar {
  background: var(--accent);
  color: var(--accent-fg);
}

/* Filled accent buttons need a legible foreground in every theme. */
.auth-submit,
.settings-btn--primary,
.btn-primary {
  color: var(--accent-fg);
}

/* --------------------------------------------------------------------------
   6. Auth screens
   --------------------------------------------------------------------------
   auth.css is styled as a fashion-editorial layout: 0.62–0.72rem uppercase
   text, 300-weight headings, and fully rounded pills. On a Japanese product
   that reads as tiny, faint and hard to scan, and it clashes with every other
   screen. The layout is kept; the type scale, casing and shapes are brought
   in line with the application. */

/* Headings carry weight instead of lightness */
.auth-panel-title {
  font-weight: 600;
  letter-spacing: -0.01em;
}
.auth-hero-tagline {
  font-weight: 400;
  letter-spacing: -0.015em;
}
.auth-hero-tagline em {
  font-weight: 600;
}
.auth-page .auth-hero-logo.logo-brand {
  font-weight: 700;
}

/* Body copy at a readable size */
.auth-hero-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--ng-text-muted);
}
.auth-hero-desc,
.auth-panel .auth-subtitle {
  font-size: 0.92rem;
  color: var(--ng-text-muted);
}

/* Labels are Japanese — uppercase and 0.62rem make them illegible */
.auth-field label {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--ng-text-muted);
  margin-bottom: 6px;
}
.auth-field input {
  font-size: 0.95rem;
}
.auth-field-hint {
  font-size: 0.78rem;
}
.auth-highlight strong {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}
.auth-highlight span {
  font-size: 0.78rem;
}

/* Pills → the base 8–12px radius, so controls match the rest of the product */
.auth-oauth-btn,
.auth-submit {
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  padding: 12px 18px;
}
.auth-oauth-btn {
  color: var(--ng-text-muted);
}
.auth-oauth-btn:hover {
  color: var(--ng-text);
}
.auth-divider {
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}
.auth-link,
.auth-switch-text {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

/* The base fills the primary button with brand-200 (#d4f7ff) — almost white,
   and louder than anything else in the product. */
.auth-submit {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.auth-submit:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 86%, #ffffff);
  border-color: color-mix(in srgb, var(--accent) 86%, #ffffff);
}

/* Hero and panel were both pure black; lift the hero so the two halves read
   as separate surfaces. */
.auth-hero {
  background: var(--ng-surface);
}

/* --------------------------------------------------------------------------
   7. Responsive — base sheets already handle layout; only soften headings
   -------------------------------------------------------------------------- */
@media (max-width: 520px) {
  .auth-panel-title {
    letter-spacing: -0.005em;
  }
}
