/**
 * Komtas Design System — portable visual primitives.
 * Scope: .app-root with data-theme="light"|"dark"
 * No layout-specific styles (nav, topbar, chat, drawer).
 */

@import url("https://fonts.googleapis.com/css2?family=Geist+Mono:wght@400;500;600&family=Geist:wght@400;500;600&display=swap");

/* ── Root & theme tokens ─────────────────────────────────────────────── */

.app-root {
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Spacing / layout tokens */
  --nav-w: 232px;
  --topbar-h: 52px;
  --content-max: 1280px;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 999px;

  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.45;
  font-feature-settings: "ss01", "cv11";
  color: var(--fg);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Light theme (default) ───────────────────────────────────────────── */

.app-root,
.app-root[data-theme="light"] {
  /* Background hierarchy */
  --bg-canvas: #f6f5f1;
  --bg-base: #faf9f6;
  --bg-surface: #ffffff;
  --bg-sunk: #f1efea;
  --bg-hover: #efede7;
  --bg-active: #e8e5dd;

  /* Foreground */
  --fg-strong: #16181a;
  --fg: #2a2c2f;
  --fg-soft: #5b5d61;
  --fg-muted: #8b8d91;
  --fg-faint: #b6b6b1;

  /* Borders */
  --border-soft: #ebe9e2;
  --border: #ddd9cf;
  --border-strong: #c4c0b4;

  /* Accent */
  --accent: #2a4f3f;
  --accent-hover: #1e3d31;
  --accent-soft: #e5ece7;
  --accent-fg: #ffffff;
  --accent-ring: rgba(42, 79, 63, 0.18);

  /* Status — neutral */
  --status-neutral-bg: #ecebe5;
  --status-neutral-fg: #4d4e4f;
  --status-neutral-dot: #8a8c8e;

  /* Status — progress */
  --status-progress-bg: #e2e8f2;
  --status-progress-fg: #2a4880;
  --status-progress-dot: #3c66b8;

  /* Status — waiting */
  --status-waiting-bg: #f5e9d2;
  --status-waiting-fg: #7c5310;
  --status-waiting-dot: #c08a1f;

  /* Status — complete */
  --status-complete-bg: #dfe9e0;
  --status-complete-fg: #2e5938;
  --status-complete-dot: #4a8556;

  /* Status — failed */
  --status-failed-bg: #f1dad3;
  --status-failed-fg: #893624;
  --status-failed-dot: #b14e36;

  /* Status — suspended */
  --status-suspended-bg: #ede8db;
  --status-suspended-fg: #6b5e2f;
  --status-suspended-dot: #9a8a4a;

  /* Shadows */
  --shadow-sm: 0 1px 0 rgba(20, 22, 25, 0.04), 0 1px 2px rgba(20, 22, 25, 0.04);
  --shadow-md: 0 2px 6px rgba(20, 22, 25, 0.06), 0 1px 0 rgba(20, 22, 25, 0.03);
  --shadow-lg: 0 12px 32px rgba(20, 22, 25, 0.10), 0 2px 6px rgba(20, 22, 25, 0.06);
  --shadow-popover: 0 8px 24px rgba(20, 22, 25, 0.12), 0 1px 0 rgba(20, 22, 25, 0.04);
}

/* ── Dark theme ──────────────────────────────────────────────────────── */

.app-root[data-theme="dark"] {
  /* Background hierarchy */
  --bg-canvas: #0e1012;
  --bg-base: #131518;
  --bg-surface: #181b1f;
  --bg-sunk: #101215;
  --bg-hover: #1f2328;
  --bg-active: #262b31;

  /* Foreground */
  --fg-strong: #f3f1ec;
  --fg: #d8d5cd;
  --fg-soft: #9c9a93;
  --fg-muted: #6f6e6a;
  --fg-faint: #4a4945;

  /* Borders */
  --border-soft: #23262b;
  --border: #2c3036;
  --border-strong: #3a3f47;

  /* Accent */
  --accent: #6fb495;
  --accent-hover: #84c2a6;
  --accent-soft: #1c2a25;
  --accent-fg: #0c1a14;
  --accent-ring: rgba(111, 180, 149, 0.22);

  /* Status — neutral */
  --status-neutral-bg: #21252a;
  --status-neutral-fg: #b8b8b4;
  --status-neutral-dot: #7d8085;

  /* Status — progress */
  --status-progress-bg: #1d2638;
  --status-progress-fg: #9bb4e2;
  --status-progress-dot: #6b8fd2;

  /* Status — waiting */
  --status-waiting-bg: #312613;
  --status-waiting-fg: #e2b66a;
  --status-waiting-dot: #d49a34;

  /* Status — complete */
  --status-complete-bg: #18271e;
  --status-complete-fg: #9bc5a7;
  --status-complete-dot: #5d9d6b;

  /* Status — failed */
  --status-failed-bg: #2c1612;
  --status-failed-fg: #e7a092;
  --status-failed-dot: #c6664c;

  /* Status — suspended */
  --status-suspended-bg: #28241a;
  --status-suspended-fg: #c8b87f;
  --status-suspended-dot: #aa9a5e;

  /* Shadows */
  --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.30), 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.35), 0 1px 0 rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-popover: 0 8px 24px rgba(0, 0, 0, 0.50), 0 1px 0 rgba(0, 0, 0, 0.30);
}

/* ── Typography utilities ────────────────────────────────────────────── */

.app-root .text-xs { font-size: 11px; }
.app-root .text-sm { font-size: 12px; }
.app-root .text-md { font-size: 13.5px; }
.app-root .text-lg { font-size: 15px; }
.app-root .text-xl { font-size: 18px; }
.app-root .text-2xl { font-size: 22px; }
.app-root .text-3xl { font-size: 28px; }

.app-root .fw-500 { font-weight: 500; }
.app-root .fw-600 { font-weight: 600; }

.app-root .text-strong { color: var(--fg-strong); }
.app-root .text-soft { color: var(--fg-soft); }
.app-root .text-muted { color: var(--fg-muted); }
.app-root .text-faint { color: var(--fg-faint); }

.app-root .mono {
  font-family: var(--font-mono);
}

.app-root .uppercase {
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Scrollbars (section 11) ─────────────────────────────────────────── */

.app-root * {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.app-root *::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.app-root *::-webkit-scrollbar-track {
  background: transparent;
}

.app-root *::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 999px;
  border: 2px solid var(--bg-canvas);
}

.app-root *::-webkit-scrollbar-thumb:hover {
  background-color: var(--border-strong);
}

/* ── Button (.btn) ───────────────────────────────────────────────────── */

.app-root .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  color: var(--fg-strong);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.app-root .btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.app-root .btn:active:not(:disabled) {
  background: var(--bg-active);
}

.app-root .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app-root .btn.is-sm,
.app-root .btn.sm {
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
}

.app-root .btn.is-lg {
  height: 36px;
  padding: 0 16px;
  font-size: 13.5px;
}

.app-root .btn.is-icon {
  width: 30px;
  padding: 0;
}

.app-root .btn.is-icon.is-sm,
.app-root .btn.is-icon.sm {
  width: 26px;
}

.app-root .btn.is-icon.is-lg {
  width: 36px;
}

.app-root .btn.is-primary,
.app-root .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.app-root .btn.is-primary:hover:not(:disabled),
.app-root .btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.app-root .btn.is-danger,
.app-root .btn.danger {
  color: var(--status-failed-fg);
}

.app-root .btn.is-danger:hover:not(:disabled),
.app-root .btn.danger:hover:not(:disabled) {
  background: var(--status-failed-bg);
  border-color: var(--status-failed-dot);
}

.app-root .btn.is-ghost,
.app-root .btn.ghost {
  background: transparent;
  border-color: transparent;
}

.app-root .btn.is-ghost:hover:not(:disabled),
.app-root .btn.ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: transparent;
}

/* ── Input / textarea / select ─────────────────────────────────────────── */

.app-root .input,
.app-root .textarea,
.app-root .select {
  display: block;
  width: 100%;
  padding: 7px 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--fg-strong);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.app-root .input::placeholder,
.app-root .textarea::placeholder {
  color: var(--fg-faint);
}

.app-root .input:focus,
.app-root .textarea:focus,
.app-root .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.app-root .textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

.app-root .select {
  appearance: none;
  cursor: pointer;
}

/* ── Card ──────────────────────────────────────────────────────────────── */

.app-root .card {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* ── Status pill (.pill) ─────────────────────────────────────────────── */

.app-root .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 7px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.6;
}

.app-root .pill::before {
  content: "";
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.app-root .pill.is-neutral {
  background: var(--status-neutral-bg);
  color: var(--status-neutral-fg);
}

.app-root .pill.is-neutral::before {
  background: var(--status-neutral-dot);
}

.app-root .pill.is-progress {
  background: var(--status-progress-bg);
  color: var(--status-progress-fg);
}

.app-root .pill.is-progress::before {
  background: var(--status-progress-dot);
}

.app-root .pill.is-waiting {
  background: var(--status-waiting-bg);
  color: var(--status-waiting-fg);
}

.app-root .pill.is-waiting::before {
  background: var(--status-waiting-dot);
}

.app-root .pill.is-complete {
  background: var(--status-complete-bg);
  color: var(--status-complete-fg);
}

.app-root .pill.is-complete::before {
  background: var(--status-complete-dot);
}

.app-root .pill.is-failed {
  background: var(--status-failed-bg);
  color: var(--status-failed-fg);
}

.app-root .pill.is-failed::before {
  background: var(--status-failed-dot);
}

.app-root .pill.is-suspended {
  background: var(--status-suspended-bg);
  color: var(--status-suspended-fg);
}

.app-root .pill.is-suspended::before {
  background: var(--status-suspended-dot);
}

.app-root .pill.is-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.app-root .pill.is-accent::before {
  background: var(--accent);
}

/* ── Tag ───────────────────────────────────────────────────────────────── */

.app-root .tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: var(--r-xs);
  background: var(--bg-sunk);
  color: var(--fg-soft);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.6;
}

/* ── Link ──────────────────────────────────────────────────────────────── */

.app-root .link {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  transition: color 120ms ease;
}

.app-root .link:hover {
  text-decoration: underline;
}

/* ── Spinner ───────────────────────────────────────────────────────────── */

.app-root .spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: komtas-spin 0.8s linear infinite;
}

@keyframes komtas-spin {
  to { transform: rotate(360deg); }
}

/* ── Divider ─────────────────────────────────────────────────────────── */

.app-root .hr {
  height: 1px;
  margin: 0;
  border: none;
  background: var(--border-soft);
}

/* ── Row hover ─────────────────────────────────────────────────────────── */

.app-root .row-hover {
  transition: background 120ms ease;
}

.app-root .row-hover:hover {
  background: var(--bg-hover);
}

/* ── Skeleton ──────────────────────────────────────────────────────────── */

.app-root .skel {
  background: linear-gradient(
    90deg,
    var(--bg-sunk) 0%,
    var(--bg-hover) 50%,
    var(--bg-sunk) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: komtas-skel-shimmer 1.6s ease-in-out infinite;
}

@keyframes komtas-skel-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Motion ────────────────────────────────────────────────────────────── */

.app-root .fade-in {
  animation: komtas-fade-in 180ms ease-out both;
}

@keyframes komtas-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.app-root .slide-up {
  animation: komtas-slide-up 260ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes komtas-slide-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-root .is-pulse,
.app-root .pill.is-pulse::before {
  animation: komtas-pulse 1.6s ease-in-out infinite;
}

@keyframes komtas-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(1.4);
  }
}
