/* ==========================================================================
   Foundation — loaded by EVERY page (public + app + admin).
   Contains: design tokens (light + dark themes), the base reset, fonts,
   icon sizing helper, shared chrome (theme toggle, snackbar), keyframes,
   and the canonical components (.btn / .input / .card).
   Page/section layout lives in global.css (public), dashboard.css (app) and
   admin.css (admin). Keep this file free of page-specific styling.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design tokens — the styling vocabulary (style.md). Reference these, never
   hardcode. Light theme is the default; dark theme overrides on
   :root[data-theme="dark"]. Accent default #1a73e8.
   -------------------------------------------------------------------------- */
:root {
  /* Surfaces / text / borders */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #1c1e21;
  --text-2: #5f6571;
  --text-3: #8a909b;
  --border: #e6e8ec;
  --border-2: #d7dade;

  /* Accent — set --accent-seed to rebrand; light/dark/hover all derive from it. */
  --accent-seed: #e8590c;
  --accent: var(--accent-seed);
  --accent-weak: color-mix(in srgb, var(--accent), white 88%);
  --accent-strong: color-mix(in srgb, var(--accent), black 14%);
  /* hover/active accent */
  --on-accent: #ffffff;

  /* Depth */
  --shadow: rgba(60, 64, 67, 0.18);
  --scrim: rgba(20, 22, 28, 0.45);
  --elev-1: 0 1px 2px var(--shadow);
  --elev-2: 0 1px 3px var(--shadow);
  --elev-3: 0 2px 8px var(--shadow);
  --elev-4: 0 14px 44px var(--shadow);
  --elev-5: 0 18px 50px var(--shadow);

  /* Semantic status — foreground + weak background */
  --success: #1e8e3e;
  --success-weak: rgba(30, 142, 62, 0.13);
  --error: #d93025;
  --error-weak: rgba(217, 48, 37, 0.13);
  --warning: #e8710a;
  --warning-weak: rgba(232, 113, 10, 0.15);
  --neutral: #7c828b;
  --neutral-weak: rgba(124, 130, 139, 0.16);

  /* Focus ring — derived from accent */
  --focus-ring: color-mix(in srgb, var(--accent), transparent 72%);

  /* Typography */
  --font-family-base: "Roboto", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-family-mono: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-size-base: 1rem;
  --font-size-xs: 0.8125rem;
  --font-size-sm: 0.875rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 2rem;
  --font-size-hero: clamp(2rem, 5vw, 3.5rem);
  --font-weight-light: 300;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 500;
  --font-weight-bold: 700;
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.6;

  /* Spacing scale — use these for padding / margin / gap. */
  --space-3xs: 0.25rem;
  --space-2xs: 0.375rem;
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.25rem;
  --space-xl: 1.5rem;
  --space-2xl: 2rem;
  --space-3xl: 3rem;
  --section-padding-y: clamp(2.5rem, 5vw, 6rem);
  --section-padding-x: clamp(1.25rem, 4vw, 3rem);
  --content-max: 1200px;

  /* Row density (style.md density prop, fixed to comfortable). */
  --row-py: 18px;

  /* Radius */
  --radius: 10px;
  /* buttons, inputs, selects */
  --radius-lg: 16px;
  /* cards, panels */
  --radius-pill: 99px;
  /* badges, chips, pills */

  /* Focus ring — shared outline width/offset and the input glow spread. */
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  --focus-ring-spread: 3px;
}

/* Dark theme — overrides only the colour tokens (style.md dark palette). */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a1f;
  --surface-2: #21262e;
  --text: #e6e8eb;
  --text-2: #9aa0a6;
  --text-3: #6b7178;
  --border: #272c34;
  --border-2: #363c45;

  --accent: color-mix(in srgb, var(--accent-seed), white 42%);
  --accent-weak: color-mix(in srgb, var(--accent), #0f1115 78%);
  --accent-strong: color-mix(in srgb, var(--accent), white 22%);
  --on-accent: #0a1020;

  --shadow: rgba(0, 0, 0, 0.55);
  --scrim: rgba(0, 0, 0, 0.6);
}

.icon {
  display: inline-flex;
  width: 1em;
  height: 1em;
  font-size: var(--font-size-xl);
  fill: currentColor;
  vertical-align: middle;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Base reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The hidden attribute must always win, even over component display rules
   (.btn / .stack-form / .detected set display, which would otherwise show). */
[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-relaxed);
  color: var(--text);
  background: var(--bg);
  margin: 0;
  min-height: 100vh;
  transition: background 0.35s ease, color 0.35s ease;
}

h1,
h2,
h3 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin: 0 0 0.5em;
}

h1 {
  font-size: var(--font-size-3xl);
}

h2 {
  font-size: var(--font-size-2xl);
}

h3 {
  font-size: var(--font-size-xl);
}

p {
  margin: 0 0 1em;
}

code {
  font-family: var(--font-family-mono);
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

/* --------------------------------------------------------------------------
   Canonical components — ONE style per object type.
   Reuse these everywhere. A new component class is only justified when it is
   visually distinct; if it looks like a button/card/input that already exists,
   use the base class + a modifier instead of copying the rule.
   -------------------------------------------------------------------------- */

/* Button — base + variants (.btn--primary, .btn--secondary, .btn--full) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 2.75rem;
  padding: 0 var(--space-lg);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--elev-1);
}

.btn--primary:hover {
  filter: brightness(1.06);
  box-shadow: var(--elev-3);
  color: var(--on-accent);
  text-decoration: none;
}

.btn--secondary {
  background: transparent;
  border-color: var(--border-2);
  color: var(--text);
}

.btn--secondary:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  color: var(--text);
  text-decoration: none;
}

.btn--full {
  width: 100%;
}

.btn--danger {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

.btn--danger:hover {
  filter: brightness(1.06);
  color: #fff;
  text-decoration: none;
}

.btn--danger-outline {
  background: transparent;
  border-color: color-mix(in srgb, var(--error), transparent 60%);
  color: var(--error);
}

.btn--danger-outline:hover {
  background: color-mix(in srgb, var(--error), transparent 92%);
  color: var(--error);
  text-decoration: none;
}

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

.btn--icon {
  padding: 0;
  width: 2.75rem;
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn--icon:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

/* Small rounded-square icon button (table row actions). */
.btn--icon-square {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 9px;
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn--icon-square:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}

/* Text input — base + .input--error */
.input {
  width: 100%;
  min-height: 2.75rem;
  padding: 0 var(--space-md);
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder {
  color: var(--text-3);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 var(--focus-ring-spread) var(--focus-ring);
}

.input--error {
  border-color: var(--error);
}

.input--error:focus {
  box-shadow: 0 0 0 var(--focus-ring-spread) var(--error-weak);
}

/* Card — the one elevated surface. Add .card--pad for default padding. */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-2);
}

.card--pad {
  padding: var(--space-xl);
}

/* Platform logo badge — brand-coloured square initials. Default 40px (table /
   modal); --lg for the landing hero, --sm for inline chip previews. */
.platform-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  font-weight: var(--font-weight-bold);
  font-size: 13px;
  color: #fff;
  box-shadow: var(--elev-3);
}

.platform-badge--lg {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  font-size: 19px;
}

.platform-badge--sm {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  font-size: 10px;
  box-shadow: none;
}

.platform-badge--telegram {
  background: #229ed9;
}

.platform-badge--threads {
  background: #101114;
}

.platform-badge--instagram {
  background: linear-gradient(135deg, #f9ce34, #ee2a7b, #6228d7);
}

.platform-badge--linkedin {
  background: #0a66c2;
}

.platform-badge--youtube {
  background: #ff0000;
}

.platform-badge--neutral {
  background: var(--text-3);
}

.platform-badge__icon {
  width: 52%;
  height: 52%;
  object-fit: contain;
}

/* Feature icon tile — accent-tinted rounded square holding a Material Symbol. */
.feature-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-weak);
  color: var(--accent);
}

.feature-tile .icon {
  font-size: 23px;
}

/* --------------------------------------------------------------------------
   Shared chrome — theme toggle + snackbar. Defined here so both the public
   marketing chrome and the app shell reuse one definition.
   -------------------------------------------------------------------------- */

/* Circular icon button used for the light/dark theme switch. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

/* The toggle shows one glyph per theme; the other is hidden via [data-theme]. */
.theme-toggle__dark {
  display: none;
}

:root[data-theme="dark"] .theme-toggle__light {
  display: none;
}

:root[data-theme="dark"] .theme-toggle__dark {
  display: inline-flex;
}

/* Snackbar — transient confirmation toast (created by global.js). */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 80;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  max-width: calc(100vw - 2 * var(--space-lg));
  padding: 13px 18px;
  background: #23262c;
  color: #fff;
  border-radius: 11px;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.42);
  animation: snackIn 0.26s ease;
}

.snackbar__icon {
  color: #7fb3ff;
}

/* --------------------------------------------------------------------------
   Shared app header — sticky logo + theme toggle + avatar/account menu.
   Used by both the public marketing chrome and the authenticated app shell
   (see templates/components/_header.html), so it lives here rather than in
   global.css or dashboard.css.
   -------------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  height: 62px;
  padding: 0 var(--section-padding-x);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header__left {
  display: flex;
  align-items: center;
  gap: var(--space-2xl);
  min-width: 0;
}

.app-header__wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  letter-spacing: -0.015em;
  color: var(--text);
}

.app-header__wordmark:hover {
  text-decoration: none;
}

.app-header__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.app-header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-header__nav-link {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-2);
}

.app-header__nav-link:hover {
  color: var(--text);
  text-decoration: none;
}

@media (max-width: 600px) {
  .app-header__nav {
    display: none;
  }
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: filter 0.15s;
}

.avatar:hover {
  filter: brightness(1.06);
}

.avatar:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

/* Account dropdown menu, opened by the avatar. Default-closed (display:
   none); global.js toggles .is-open. */
.header-menu {
  position: relative;
}

.header-menu__panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  flex-direction: column;
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-4);
}

.header-menu.is-open .header-menu__panel {
  display: flex;
}

.header-menu__item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: none;
  font: inherit;
  font-size: var(--font-size-sm);
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.header-menu__item:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.header-menu__panel form {
  display: flex;
}

.header-menu__divider {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

@media (max-width: 600px) {
  .app-header__left {
    gap: var(--space-md);
  }
}

/* --------------------------------------------------------------------------
   Keyframes (style.md animations)
   -------------------------------------------------------------------------- */
@keyframes scrimIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes snackIn {
  from {
    opacity: 0;
    transform: translate(-50%, 14px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   Accessibility
   -------------------------------------------------------------------------- */
button:focus-visible,
input:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}