@import "tailwindcss";
@import "tw-animate-css";

/* ============================================================
   Theme Variables — app-owned light/dark contract
   ============================================================ */

:root {
  /* --- Font defaults --- */
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.5;
  font-weight: 400;
  font-size: 14px;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[data-radix-popper-content-wrapper] {
  zoom: var(--tolaria-overlay-zoom-inverse, 1);
}

[data-radix-popper-content-wrapper] > [data-slot="dropdown-menu-content"],
[data-radix-popper-content-wrapper] > [data-slot="popover-content"],
[data-radix-popper-content-wrapper] > [data-slot="select-content"],
[data-radix-popper-content-wrapper] > [data-slot="tooltip-content"] {
  zoom: var(--tolaria-overlay-zoom-factor, 1);
}

:root,
[data-theme="light"] {
  color-scheme: light;

  /* --- Semantic surfaces (light mode) --- */
  --surface-app: #FFFFFF;
  --surface-sidebar: #F7F6F3;
  --surface-panel: #FFFFFF;
  --surface-card: #FFFFFF;
  --surface-popover: #FFFFFF;
  --surface-input: #FFFFFF;
  --surface-button: #EBEBEA;
  --surface-dialog: #FFFFFF;
  --surface-editor: #FFFFFF;
  --surface-overlay: rgba(0, 0, 0, 0.3);

  /* --- Semantic text (light mode) --- */
  --text-primary: #37352F;
  --text-secondary: #787774;
  --text-tertiary: #787774;
  --text-muted: #B4B4B4;
  --text-faint: #B4B4B4;
  --text-heading: #37352F;
  --text-inverse: #FFFFFF;

  /* --- Semantic borders (light mode) --- */
  --border-default: #E9E9E7;
  --border-subtle: #E9E9E7;
  --border-strong: #D9D9D6;
  --border-input: #E9E9E7;
  --border-dialog: #E9E9E7;
  --border-focus: #155DFF;

  /* --- Interaction states (light mode) --- */
  --state-hover: #EBEBEA;
  --state-hover-subtle: #F0F0EF;
  --state-selected: #E8F4FE;
  --state-selected-strong: #D8ECFE;
  --state-active: #E8F4FE;
  --state-focus-ring: #155DFF;
  --state-drag-target: #155DFF18;
  --state-disabled: #F0F0EF;

  /* --- Accent roles (light mode) --- */
  --accent-blue: #155DFF;
  --accent-blue-bg: #155DFF18;
  --accent-blue-hover: #0D4AD6;
  --accent-blue-light: #155DFF14;
  --accent-green: #38A169;
  --accent-green-light: rgba(56, 161, 105, 0.1);
  --accent-orange: #D9730D;
  --accent-orange-light: rgba(217, 115, 13, 0.1);
  --accent-red: #E53E3E;
  --accent-red-light: rgba(229, 62, 62, 0.1);
  --accent-purple: #805AD5;
  --accent-purple-light: rgba(128, 90, 213, 0.1);
  --accent-yellow: #D69E2E;
  --accent-yellow-light: rgba(214, 158, 46, 0.1);
  --accent-teal: #319795;
  --accent-teal-light: rgba(49, 151, 149, 0.1);
  --accent-pink: #D53F8C;
  --accent-pink-light: rgba(213, 63, 140, 0.1);
  --accent-gray: #718096;
  --accent-gray-light: rgba(113, 128, 150, 0.1);

  /* --- Feedback roles (light mode) --- */
  --feedback-info-text: var(--accent-blue);
  --feedback-info-bg: var(--accent-blue-light);
  --feedback-success-text: var(--accent-green);
  --feedback-success-bg: var(--accent-green-light);
  --feedback-warning-text: #92400E;
  --feedback-warning-bg: #FEF3C7;
  --feedback-warning-border: #D97706;
  --feedback-error-text: var(--accent-red);
  --feedback-error-bg: var(--accent-red-light);

  /* --- Syntax and diff roles (light mode) --- */
  --syntax-heading: #0969DA;
  --syntax-link: #0969DA;
  --syntax-monospace: #C9383E;
  --syntax-monospace-bg: rgba(175, 184, 193, 0.15);
  --syntax-muted: #636C76;
  --syntax-frontmatter-key: #C9383E;
  --syntax-frontmatter-value: #2A7E4F;
  --syntax-highlight-comment: #6A737D;
  --syntax-highlight-keyword: #D73A49;
  --syntax-highlight-string: #032F62;
  --syntax-highlight-number: #005CC5;
  --syntax-highlight-title: #6F42C1;
  --syntax-highlight-type: #E36209;
  --syntax-highlight-deletion: #B31D28;
  --syntax-highlight-deletion-bg: #FFEEF0;
  --diff-added-text: #4CAF50;
  --diff-added-bg: rgba(76, 175, 80, 0.12);
  --diff-removed-text: #F44336;
  --diff-removed-bg: rgba(244, 67, 54, 0.12);
  --diff-hunk-bg: rgba(33, 150, 243, 0.08);
  --editor-code-block-background: var(--surface-sidebar);
  --editor-code-block-border: var(--border-subtle);
  --editor-code-block-text: var(--text-primary);
  --editor-code-block-language: var(--text-secondary);

  /* --- Overlays and shadows (light mode) --- */
  --shadow-overlay: var(--surface-overlay);
  --shadow-dialog: rgba(0, 0, 0, 0.15);

  /* --- shadcn theme aliases (light mode) --- */
  --radius: 0.5rem;
  --background: var(--surface-app);
  --foreground: var(--text-primary);
  --card: var(--surface-card);
  --card-foreground: var(--text-primary);
  --popover: var(--surface-popover);
  --popover-foreground: var(--text-primary);
  --primary: var(--accent-blue);
  --primary-foreground: var(--text-inverse);
  --secondary: var(--state-hover);
  --secondary-foreground: var(--text-primary);
  --muted: var(--state-hover-subtle);
  --muted-foreground: var(--text-secondary);
  --accent: var(--state-hover);
  --accent-foreground: var(--text-primary);
  --destructive: var(--accent-red);
  --destructive-foreground: var(--text-inverse);
  --border: var(--border-default);
  --input: var(--border-input);
  --ring: var(--state-focus-ring);
  --sidebar: var(--surface-sidebar);
  --sidebar-foreground: var(--text-primary);
  --sidebar-primary: var(--accent-blue);
  --sidebar-primary-foreground: var(--text-inverse);
  --sidebar-accent: var(--state-hover);
  --sidebar-accent-foreground: var(--text-primary);
  --sidebar-border: var(--border-default);
  --sidebar-ring: var(--state-focus-ring);

  /* --- Compatibility aliases for existing product code --- */
  --bg-primary: var(--surface-app);
  --bg-sidebar: var(--surface-sidebar);
  --bg-card: var(--surface-card);
  --bg-hover: var(--state-hover);
  --bg-hover-subtle: var(--state-hover-subtle);
  --bg-selected: var(--state-selected);
  --bg-input: var(--surface-input);
  --bg-button: var(--surface-button);
  --bg-dialog: var(--surface-dialog);
  --border-primary: var(--border-default);
  --hover: var(--state-hover);
  --link-color: var(--accent-blue);
  --link-hover: var(--accent-blue-hover);
}

:root.dark,
[data-theme="dark"] {
  color-scheme: dark;

  /* --- Semantic surfaces (dark mode) --- */
  --surface-app: #1F1E1B;
  --surface-sidebar: #191814;
  --surface-panel: #23221F;
  --surface-card: #23221F;
  --surface-popover: #292823;
  --surface-input: #1F1E1B;
  --surface-button: #34322D;
  --surface-dialog: #272622;
  --surface-editor: #1F1E1B;
  --surface-overlay: rgba(8, 8, 7, 0.58);

  /* --- Semantic text (dark mode) --- */
  --text-primary: #E6E1D8;
  --text-secondary: #B8B1A6;
  --text-tertiary: #9C9488;
  --text-muted: #7F776D;
  --text-faint: #625B53;
  --text-heading: #F1ECE3;
  --text-inverse: #151411;

  /* --- Semantic borders (dark mode) --- */
  --border-default: #34322D;
  --border-subtle: #2A2925;
  --border-strong: #46433B;
  --border-input: #3A3832;
  --border-dialog: #3A3832;
  --border-focus: #78A4FF;

  /* --- Interaction states (dark mode) --- */
  --state-hover: #2D2B27;
  --state-hover-subtle: #262520;
  --state-selected: #1E344C;
  --state-selected-strong: #25415F;
  --state-active: #203A55;
  --state-focus-ring: #78A4FF;
  --state-drag-target: rgba(120, 164, 255, 0.2);
  --state-disabled: #292824;

  /* --- Accent roles (dark mode) --- */
  --accent-blue: #78A4FF;
  --accent-blue-bg: rgba(120, 164, 255, 0.2);
  --accent-blue-hover: #9BBEFF;
  --accent-blue-light: rgba(120, 164, 255, 0.16);
  --accent-green: #79D89D;
  --accent-green-light: rgba(121, 216, 157, 0.16);
  --accent-orange: #F3A15B;
  --accent-orange-light: rgba(243, 161, 91, 0.17);
  --accent-red: #FF8A86;
  --accent-red-light: rgba(255, 138, 134, 0.16);
  --accent-purple: #B69CFF;
  --accent-purple-light: rgba(182, 156, 255, 0.17);
  --accent-yellow: #F2C86B;
  --accent-yellow-light: rgba(242, 200, 107, 0.18);
  --accent-teal: #64D1C8;
  --accent-teal-light: rgba(100, 209, 200, 0.16);
  --accent-pink: #F28AC3;
  --accent-pink-light: rgba(242, 138, 195, 0.16);
  --accent-gray: #A7B0BD;
  --accent-gray-light: rgba(167, 176, 189, 0.14);

  /* --- Feedback roles (dark mode) --- */
  --feedback-info-text: var(--accent-blue);
  --feedback-info-bg: var(--accent-blue-light);
  --feedback-success-text: var(--accent-green);
  --feedback-success-bg: var(--accent-green-light);
  --feedback-warning-text: #F5C36B;
  --feedback-warning-bg: rgba(245, 195, 107, 0.16);
  --feedback-warning-border: #D99B3D;
  --feedback-error-text: var(--accent-red);
  --feedback-error-bg: var(--accent-red-light);

  /* --- Syntax and diff roles (dark mode) --- */
  --syntax-heading: #83B2FF;
  --syntax-link: #83B2FF;
  --syntax-monospace: #FFA6A3;
  --syntax-monospace-bg: rgba(167, 176, 189, 0.16);
  --syntax-muted: #9C9488;
  --syntax-frontmatter-key: #FFA6A3;
  --syntax-frontmatter-value: #8EDFAE;
  --syntax-highlight-comment: #8E877D;
  --syntax-highlight-keyword: #FF9BA0;
  --syntax-highlight-string: #A9D6FF;
  --syntax-highlight-number: #8BB7FF;
  --syntax-highlight-title: #C2AAFF;
  --syntax-highlight-type: #F3B175;
  --syntax-highlight-deletion: #FF9C9A;
  --syntax-highlight-deletion-bg: rgba(255, 138, 134, 0.16);
  --diff-added-text: #79D89D;
  --diff-added-bg: rgba(121, 216, 157, 0.14);
  --diff-removed-text: #FF8A86;
  --diff-removed-bg: rgba(255, 138, 134, 0.14);
  --diff-hunk-bg: rgba(120, 164, 255, 0.13);
  --editor-code-block-background: #161616;
  --editor-code-block-border: transparent;
  --editor-code-block-text: #FFFFFF;
  --editor-code-block-language: rgba(255, 255, 255, 0.7);

  /* --- Overlays and shadows (dark mode) --- */
  --shadow-overlay: var(--surface-overlay);
  --shadow-dialog: rgba(0, 0, 0, 0.42);

  /* --- shadcn theme aliases (dark mode) --- */
  --background: var(--surface-app);
  --foreground: var(--text-primary);
  --card: var(--surface-card);
  --card-foreground: var(--text-primary);
  --popover: var(--surface-popover);
  --popover-foreground: var(--text-primary);
  --primary: var(--accent-blue);
  --primary-foreground: var(--text-inverse);
  --secondary: var(--state-hover);
  --secondary-foreground: var(--text-primary);
  --muted: var(--state-hover-subtle);
  --muted-foreground: var(--text-secondary);
  --accent: var(--state-hover);
  --accent-foreground: var(--text-primary);
  --destructive: var(--accent-red);
  --destructive-foreground: var(--text-inverse);
  --border: var(--border-default);
  --input: var(--border-input);
  --ring: var(--state-focus-ring);
  --sidebar: var(--surface-sidebar);
  --sidebar-foreground: var(--text-primary);
  --sidebar-primary: var(--accent-blue);
  --sidebar-primary-foreground: var(--text-inverse);
  --sidebar-accent: var(--state-hover);
  --sidebar-accent-foreground: var(--text-primary);
  --sidebar-border: var(--border-default);
  --sidebar-ring: var(--state-focus-ring);

  /* --- Compatibility aliases for existing product code --- */
  --bg-primary: var(--surface-app);
  --bg-sidebar: var(--surface-sidebar);
  --bg-card: var(--surface-card);
  --bg-hover: var(--state-hover);
  --bg-hover-subtle: var(--state-hover-subtle);
  --bg-selected: var(--state-selected);
  --bg-input: var(--surface-input);
  --bg-button: var(--surface-button);
  --bg-dialog: var(--surface-dialog);
  --border-primary: var(--border-default);
  --hover: var(--state-hover);
  --link-color: var(--accent-blue);
  --link-hover: var(--accent-blue-hover);
}

/* --- Tailwind v4 theme inline: register colors + radii --- */
@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
  --color-surface-app: var(--surface-app);
  --color-surface-sidebar: var(--surface-sidebar);
  --color-surface-panel: var(--surface-panel);
  --color-surface-card: var(--surface-card);
  --color-surface-popover: var(--surface-popover);
  --color-surface-editor: var(--surface-editor);
  --color-state-hover: var(--state-hover);
  --color-state-selected: var(--state-selected);
  --color-border-default: var(--border-default);
  --color-border-subtle: var(--border-subtle);
  --color-text-primary: var(--text-primary);
  --color-text-secondary: var(--text-secondary);
  --color-text-muted: var(--text-muted);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
}

/* --- Base layer --- */
@layer base {
  * {
    @apply border-border;
    box-sizing: border-box;
  }
  body {
    @apply bg-background text-foreground;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  body.custom-window-chrome {
    padding-top: 32px;
  }
  html, body {
    height: 100%;
    width: 100%;
  }
  #root {
    width: 100%;
    height: 100%;
  }
  html.ai-workspace-native-window,
  html.ai-workspace-native-window body,
  html.ai-workspace-native-window #root {
    background: transparent;
    overflow: hidden;
  }
  html.ai-workspace-native-window body {
    padding: 20px;
  }
  html.ai-workspace-native-window #root {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12), 0 1px 3px rgba(15, 23, 42, 0.10);
  }
  html.ai-workspace-native-window.dark #root,
  html.ai-workspace-native-window[data-theme="dark"] #root {
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.30), 0 1px 4px rgba(0, 0, 0, 0.22);
  }
  /* Interactive controls should advertise clickability unless disabled. */
  :where(
    button:not(:disabled):not([aria-disabled="true"]),
    [role="button"]:not([aria-disabled="true"]):not([data-disabled]),
    [role="menuitem"]:not([aria-disabled="true"]):not([data-disabled]),
    [role="menuitemcheckbox"]:not([aria-disabled="true"]):not([data-disabled]),
    [role="menuitemradio"]:not([aria-disabled="true"]):not([data-disabled]),
    [role="option"]:not([aria-disabled="true"]):not([data-disabled])
  ) {
    cursor: pointer;
  }
}

/* --- Label typography (Inter, sentence case) --- */
/* t8: Section labels, metadata tags — 11px medium */
.font-mono-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
}

/* t9: Overlines, category labels — 10px regular */
.font-mono-overline {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.referenced-by-panel button:hover {
  text-decoration: underline;
  text-decoration-style: dotted;
}

/* --- AI Chat markdown rendering --- */

.ai-markdown {
  font-size: 13px;
  line-height: 1.6;
  color: var(--foreground);
  overflow-wrap: anywhere;
  word-break: normal;
}

.ai-markdown > :first-child { margin-top: 0; }
.ai-markdown > :last-child { margin-bottom: 0; }

.ai-markdown p { margin: 0.5em 0; }

.ai-markdown strong { font-weight: 600; }

.ai-markdown h1,
.ai-markdown h2,
.ai-markdown h3,
.ai-markdown h4 {
  font-weight: 600;
  margin: 0.8em 0 0.4em;
  line-height: 1.3;
}
.ai-markdown h1 { font-size: 1.25em; }
.ai-markdown h2 { font-size: 1.15em; }
.ai-markdown h3 { font-size: 1.05em; }
.ai-markdown h4 { font-size: 1em; }

.ai-markdown ul,
.ai-markdown ol {
  margin: 0.4em 0;
  padding-inline-start: 1.5em;
}
.ai-markdown li { margin: 0.15em 0; }
.ai-markdown li > ul,
.ai-markdown li > ol { margin: 0.1em 0; }

.ai-markdown code {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-size: 0.9em;
  background: var(--muted);
  border-radius: 3px;
  padding: 0.15em 0.35em;
  overflow-wrap: anywhere;
}

.ai-markdown pre {
  margin: 0.5em 0;
  border-radius: 6px;
  background: var(--muted);
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 400px;
}

.ai-markdown pre code {
  display: block;
  padding: 0.75em 1em;
  background: none;
  border-radius: 0;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}

.ai-markdown blockquote {
  margin: 0.5em 0;
  padding: 0.25em 0.75em;
  border-inline-start: 3px solid var(--border);
  color: var(--muted-foreground);
}

.ai-markdown a {
  color: var(--link-color);
  text-decoration: none;
}
.ai-markdown a:hover { text-decoration: underline; }

.ai-markdown .chat-wikilink {
  display: inline;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border-radius: 4px;
  padding: 0 4px;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease;
}
.ai-markdown .chat-wikilink:hover {
  background: color-mix(in srgb, var(--primary) 20%, transparent);
  text-decoration: underline;
}

.ai-markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.75em 0;
}

.ai-markdown table {
  border-collapse: collapse;
  display: block;
  margin: 0.5em 0;
  font-size: 12px;
  max-width: 100%;
  overflow-x: auto;
  width: 100%;
}
.ai-markdown th,
.ai-markdown td {
  border: 1px solid var(--border);
  padding: 0.35em 0.6em;
  text-align: start;
}
.ai-markdown th {
  background: var(--muted);
  font-weight: 600;
}

/* --- highlight.js light theme (GitHub-style) --- */

.ai-markdown .hljs { color: var(--foreground); }
.ai-markdown .hljs-comment,
.ai-markdown .hljs-quote { color: var(--syntax-highlight-comment); font-style: italic; }
.ai-markdown .hljs-keyword,
.ai-markdown .hljs-selector-tag { color: var(--syntax-highlight-keyword); }
.ai-markdown .hljs-string,
.ai-markdown .hljs-addition { color: var(--syntax-highlight-string); }
.ai-markdown .hljs-number,
.ai-markdown .hljs-literal { color: var(--syntax-highlight-number); }
.ai-markdown .hljs-title,
.ai-markdown .hljs-section { color: var(--syntax-highlight-title); }
.ai-markdown .hljs-built_in,
.ai-markdown .hljs-type { color: var(--syntax-highlight-type); }
.ai-markdown .hljs-attr,
.ai-markdown .hljs-name,
.ai-markdown .hljs-attribute { color: var(--syntax-highlight-number); }
.ai-markdown .hljs-deletion { color: var(--syntax-highlight-deletion); background: var(--syntax-highlight-deletion-bg); }
.ai-markdown .hljs-meta { color: var(--syntax-highlight-comment); }

/* --- AI panel working border animation --- */

@keyframes ai-border-pulse {
  0%, 100% { border-color: var(--accent-blue); opacity: 1; }
  50% { border-color: var(--accent-blue-hover); opacity: 0.6; }
}

/* --- Typing indicator dots --- */

.typing-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted-foreground);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}
