@layer theme, base, antd, components, utilities;

@import 'tailwindcss/theme.css' layer(theme);
@import 'tailwindcss/preflight.css' layer(base);
@import 'tailwindcss/utilities.css' layer(utilities);

@custom-variant dark (&:where(.dark, .dark *));

/* Tailwind theme reads the CSS variables generated from src/theme/tokens.ts */
@theme inline {
  --color-primary: var(--tcx-primary);
  --color-sider: var(--tcx-sider);
  --color-page: var(--tcx-bg);
  --color-surface: var(--tcx-surface);
  --color-sunken: var(--tcx-sunken);
  --color-ink: var(--tcx-text);
  --color-ink-2: var(--tcx-text-2);
  --color-muted: var(--tcx-muted);
  --color-line: var(--tcx-border);
  --color-line-2: var(--tcx-border-strong);
  --color-success: var(--tcx-success);
  --color-danger: var(--tcx-error);
  --color-warning: var(--tcx-warning);
  --font-sans: var(--tcx-font);
  --radius-control: var(--tcx-radius-control);
  --radius-card: var(--tcx-radius-card);
  --radius-modal: var(--tcx-radius-modal);
  --spacing-topbar: var(--tcx-topbar-h);
}

@layer base {
  /* 14px on body only (as in the prototype) so Tailwind rem spacing stays 16px-based */
  html,
  body {
    background: var(--tcx-bg);
    color: var(--tcx-text);
    font-family: var(--tcx-font);
  }
  body {
    font-size: var(--tcx-font-size, 14px);
    line-height: 1.45;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  html {
    scroll-behavior: smooth;
  }

  /* Prototype "scroll-polish": thin, quiet scrollbars */
  * {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--tcx-muted) 35%, transparent) transparent;
  }
}

/* Details antd tokens cannot express (plan.md §3.1, item 4). Values from crm-prototype.html. */
@layer components {
  /* ---- Sidebar ---- */
  .tcx-sider-scroll {
    scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
  }
  .tcx-brand-mark {
    display: grid;
    flex: none;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: var(--tcx-radius-control, 10px);
    background: var(--tcx-primary);
    color: var(--tcx-on-primary, #fff);
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.02em;
    box-shadow: 0 6px 16px var(--tcx-primary-glow-strong, rgba(201, 28, 0, 0.35));
  }
  .tcx-nav .ant-menu-item-group {
    margin-top: 16px;
  }
  .tcx-nav .ant-menu-item-group-title {
    padding: 0 12px 8px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }
  .tcx-nav .ant-menu-item {
    font-weight: 500;
    padding-inline: 12px !important; /* antd sets inline padding from inlineIndent via style */
  }
  .tcx-nav .ant-menu-item .ant-menu-title-content {
    flex: 1;
    min-width: 0;
  }
  .tcx-nav .ant-menu-item:not(.ant-menu-item-selected) .ant-menu-item-icon {
    color: var(--tcx-side-icon);
  }
  .tcx-nav .ant-menu-item:not(.ant-menu-item-selected):hover .ant-menu-item-icon {
    color: #e2e8f0;
  }
  .tcx-nav .ant-menu-item-selected {
    box-shadow: 0 6px 16px var(--tcx-primary-glow, rgba(201, 28, 0, 0.3));
  }
  .ant-menu-inline-collapsed.tcx-nav .ant-menu-item {
    padding-inline: 0 !important;
    justify-content: center;
  }
  .tcx-count {
    margin-left: auto;
    padding: 1px 7px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    font-variant-numeric: tabular-nums;
  }
  .tcx-count-alert {
    background: rgba(220, 38, 38, 0.22);
    color: #fca5a5;
  }
  .ant-menu-item-selected .tcx-count {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
  }
  .tcx-side-btn.ant-btn {
    color: var(--tcx-side-mute);
  }
  .tcx-side-btn.ant-btn:hover {
    background: var(--tcx-side-hover, rgba(255, 255, 255, 0.06)) !important;
    color: var(--tcx-side-hover-text, #fff) !important;
  }

  /* ---- Top bar ---- */
  .tcx-top-btn.ant-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--tcx-radius-control, 10px);
  }
  .tcx-search {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(460px, 42vw);
    height: 40px;
    padding: 0 10px 0 11px;
    border-radius: var(--tcx-radius-control, 10px);
    border: 1px solid transparent;
    background: var(--tcx-sunken);
    color: var(--tcx-muted);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.15s;
  }
  .tcx-search:hover {
    border-color: var(--tcx-border-strong);
  }
  .tcx-kbd {
    margin-left: auto;
    padding: 1px 6px;
    border-radius: 5px;
    border: 1px solid var(--tcx-border-strong);
    background: var(--tcx-surface);
    color: var(--tcx-muted);
    font-family: var(--tcx-font);
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
  }
  .tcx-dot-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tcx-error);
    box-shadow: 0 0 0 2px var(--tcx-surface);
  }
  .tcx-avatar.ant-avatar {
    background: hsl(var(--h) 80% 95%);
    color: hsl(var(--h) 55% 36%);
    font-size: 13px;
    font-weight: 700;
  }
  .dark .tcx-avatar.ant-avatar {
    background: hsl(var(--h) 35% 22%);
    color: hsl(var(--h) 75% 80%);
  }
  .tcx-avatar-ring.ant-avatar {
    font-size: 13px;
    letter-spacing: 0.01em;
    box-shadow:
      0 0 0 2px var(--tcx-surface),
      0 0 0 3px var(--tcx-border-strong);
  }

  /* ---- Page ---- */
  /* Prototype .view: centred column, max 1520px, on wide screens */
  .tcx-view {
    width: 100%;
    max-width: 1520px;
    margin: 0 auto;
    padding: 30px 32px 60px;
  }
  .tcx-h1 {
    margin: 0;
    color: var(--tcx-text);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.025em;
  }
  .tcx-seg.ant-segmented {
    border: 1px solid var(--tcx-border-strong);
  }
  .tcx-seg .ant-segmented-item-label {
    min-height: 32px;
    line-height: 32px;
    padding: 0 13px;
    font-weight: 600;
  }
  .tcx-card.ant-card {
    border-color: var(--tcx-border);
    box-shadow: var(--tcx-shadow-sm);
  }
  .tcx-tile {
    display: grid;
    flex: none;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }
  .tcx-tile-blue {
    background: var(--tcx-soft-blue);
    color: var(--tcx-blue);
  }
  .tcx-tile-indigo {
    background: var(--tcx-soft-indigo);
    color: var(--tcx-indigo);
  }
  .tcx-tile-green {
    background: var(--tcx-soft-green);
    color: var(--tcx-success);
  }
  .tcx-tile-amber {
    background: var(--tcx-soft-amber);
    color: var(--tcx-warning);
  }

  @media (max-width: 960px) {
    .tcx-view {
      padding: 22px 18px 48px;
    }
  }
  @media (max-width: 720px) {
    .tcx-view {
      padding: 20px 16px 48px;
    }
    .tcx-h1 {
      font-size: 24px;
    }
    .tcx-search {
      width: 40px;
      padding: 0;
      justify-content: center;
    }
    .tcx-search-lbl,
    .tcx-search .tcx-kbd {
      display: none;
    }
  }

  /* Equal top & bottom spacing for tooltips */
  .ant-tooltip-container,
  .ant-tooltip-unique-container,
  .ant-tooltip .ant-tooltip-container,
  .ant-tooltip .ant-tooltip-unique-container,
  .ant-tooltip .ant-tooltip-inner {
    min-height: unset !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    padding: 5px 9px !important;
    font-size: 13px !important;
    line-height: 1.25 !important;
    box-sizing: border-box !important;
  }
}

/* Also ensure unlayered rule takes absolute precedence over antd CSS-in-JS */
.ant-tooltip-container,
.ant-tooltip-unique-container,
.ant-tooltip .ant-tooltip-container,
.ant-tooltip .ant-tooltip-unique-container,
.ant-tooltip .ant-tooltip-inner {
  min-height: unset !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  padding: 5px 9px !important;
  font-size: 13px !important;
  line-height: 1.25 !important;
  box-sizing: border-box !important;
}

/* ---- Public pages (landing and sign-in): motion and abstract artwork ---- */
@keyframes tcx-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes tcx-float-alt {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(9px);
  }
}

@keyframes tcx-hero-up {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tcx-hero-enter {
  animation: tcx-hero-up 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.tcx-float {
  animation: tcx-float 7s ease-in-out infinite;
}

.tcx-float-alt {
  animation: tcx-float-alt 8s ease-in-out infinite;
}

.tcx-reveal {
  opacity: 0;
  transition:
    opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.tcx-reveal-up {
  transform: translate3d(0, 32px, 0);
}

.tcx-reveal-left {
  transform: translate3d(-32px, 0, 0);
}

.tcx-reveal-right {
  transform: translate3d(32px, 0, 0);
}

.tcx-reveal-scale {
  transform: translate3d(0, 20px, 0) scale(0.95);
}

.tcx-reveal.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

.tcx-glass {
  background: color-mix(in srgb, var(--tcx-surface) 70%, transparent);
  backdrop-filter: blur(18px) saturate(1.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border: 1px solid color-mix(in srgb, #ffffff 55%, transparent);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 24px 48px -20px rgba(2, 6, 38, 0.28);
}

.tcx-on-navy .tcx-glass {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08) inset,
    0 24px 48px -20px rgba(0, 0, 0, 0.6);
}

.tcx-glow {
  background: radial-gradient(closest-side at 35% 40%, rgba(255, 122, 92, 0.32), transparent), radial-gradient(closest-side at 70% 60%, rgba(43, 53, 133, 0.18), transparent);
  filter: blur(48px);
}

.tcx-mesh {
  background: radial-gradient(55% 60% at 88% 8%, rgba(255, 138, 107, 0.22), transparent 70%), radial-gradient(40% 45% at 62% 40%, rgba(255, 196, 160, 0.18), transparent 70%), radial-gradient(45% 50% at 0% 100%, rgba(201, 28, 0, 0.07), transparent 70%), var(--tcx-bg);
}

.tcx-navy-band {
  background: radial-gradient(50% 70% at 85% 30%, rgba(224, 62, 38, 0.28), transparent 70%), radial-gradient(40% 60% at 10% 90%, rgba(88, 86, 214, 0.2), transparent 70%), #020626;
}

.tcx-grid-lines {
  background-image: linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 60% 40%, #000 20%, transparent 72%);
}

.tcx-text-gradient {
  background: linear-gradient(100deg, #c91c00 0%, #ff5a36 45%, #ff9a6b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tcx-on-navy .tcx-text-gradient {
  background-image: linear-gradient(100deg, #ff7a5c 0%, #ffa07a 50%, #ffd0b5 100%);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .tcx-hero-enter,
  .tcx-float,
  .tcx-float-alt {
    animation: none !important;
  }
  .tcx-reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}

.announce {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  border-radius: 12px;
  margin-bottom: 20px;
  background: rgba(88, 86, 214, 0.08);
  color: #5856d6;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid rgba(88, 86, 214, 0.15);
}

.announce .announce-dismiss {
  margin-left: auto;
  color: inherit;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  border: none;
  font-size: 12.5px;
}
.announce .announce-dismiss:hover {
  opacity: 0.8;
}

.proto-seg {
  display: inline-flex;
  background: var(--tcx-sunken, #f8fafc);
  border: 1px solid var(--tcx-border, #e2e8f0);
  border-radius: 9px;
  padding: 2.5px;
  gap: 2px;
}

.proto-seg button {
  height: 28px;
  border-radius: 7px;
  padding: 0 12px;
  font-weight: 500;
  font-size: 13px;
  color: var(--tcx-muted, #64748b);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.proto-seg button:hover:not([aria-selected='true']) {
  color: var(--tcx-text, #0f172a);
}

.proto-seg button[aria-selected='true'] {
  background: var(--tcx-surface, #ffffff);
  color: var(--tcx-text, #0f172a) !important;
  font-weight: 600;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 0 0 1px var(--tcx-border, #e2e8f0);
}

:root.dark .proto-seg button[aria-selected='true'] {
  background: var(--tcx-surface, #1e293b);
  color: #ffffff !important;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

.proto-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--tcx-border, #e2e8f0);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}

.proto-tab {
  position: relative;
  font-weight: 500;
  font-size: 13.5px;
  padding: 10px 16px 12px;
  color: var(--tcx-muted, #64748b);
  border: none;
  outline: none;
  transition: color 0.15s;
  cursor: pointer;
  background: transparent;
  white-space: nowrap;
  flex-shrink: 0;
}

.proto-tab:hover {
  color: var(--tcx-text, #0f172a);
}

.proto-tab[aria-selected='true'] {
  color: var(--tcx-primary, #c91c00);
  font-weight: 600;
}

.proto-tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--tcx-primary, #c91c00);
  z-index: 10;
}

/* Prototype Native Animations */
@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes grow-x {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

@keyframes grow-y {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes fade {
  to {
    opacity: 1;
  }
}

.anim-view-in {
  animation: viewIn 0.32s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.anim-grow-x {
  animation: grow-x 0.75s cubic-bezier(0.16, 1, 0.3, 1) both;
  transform-origin: left;
}

.anim-grow-center {
  animation: grow-x 0.75s cubic-bezier(0.16, 1, 0.3, 1) both;
  transform-origin: center;
}

.anim-grow-y {
  transform-box: fill-box;
  transform-origin: bottom;
  animation: grow-y 0.65s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.proto-hbar-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.proto-hbar-track {
  height: 8px;
  border-radius: 999px;
  background: #f1f5f9;
  overflow: hidden;
}
:where(.dark) .proto-hbar-track {
  background: #1e293b;
}

.proto-hbar-track i {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.proto-task-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid #cbd5e1;
  background: transparent;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  transition: all 0.18s;
}
:where(.dark) .proto-task-check {
  border-color: #475569;
}
.proto-task-check:hover {
  border-color: var(--tcx-primary, #c91c00);
}
.proto-task-check.checked {
  background: var(--tcx-primary, #c91c00);
  border-color: var(--tcx-primary, #c91c00);
}

/* Modal Viewport Fit & Sticky Footer Protection */
.ant-modal {
  top: 24px !important;
  padding-bottom: 24px !important;
  max-width: calc(100vw - 32px) !important;
}

.ant-modal .ant-modal-content {
  display: flex !important;
  flex-direction: column !important;
  max-height: calc(100vh - 48px) !important;
  overflow: hidden !important;
}

.ant-modal .ant-modal-header {
  flex-shrink: 0 !important;
  margin-bottom: 12px !important;
}

.ant-modal .ant-modal-body {
  flex: 1 1 auto !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  max-height: calc(100vh - 170px) !important;
  padding-right: 6px !important;
}

.ant-modal .ant-modal-footer {
  flex-shrink: 0 !important;
  margin-top: 14px !important;
  padding-top: 12px !important;
  border-top: 1px solid var(--tcx-border, #e2e8f0) !important;
}
