/* ══════════════════════════════════════════════════════════════════════════
   KADILI CLOUD — design system
   White + Blue (light, default) · Dark + Blue (dark) · Inter · WiFi mark only.

   The signature device is the signal arc: three concentric arcs taken from the
   WiFi mark, reused as section markers, empty-state art, and the loading
   indicator. It is the only decorative element in the system — everything
   else stays quiet so it reads as deliberate rather than busy.
   ══════════════════════════════════════════════════════════════════════════ */

@layer reset, tokens, base, components, utilities;

/* ── tokens ─────────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Blue ramp. 600 is the action colour; it is intentionally a colder,
       more saturated blue than the framework defaults so buttons read as
       Kadili rather than as Bootstrap. */
    --blue-50:  #EDF3FF;
    --blue-100: #DCE7FF;
    --blue-200: #B9CEFF;
    --blue-400: #5A8CFF;
    --blue-500: #3B78FF;
    --blue-600: #1D63FF;
    --blue-700: #0B47D6;
    --blue-800: #0A38A6;

    /* Neutrals lean blue so white surfaces sit next to the accent cleanly. */
    --slate-0:   #FFFFFF;
    --slate-25:  #FAFBFD;
    --slate-50:  #F4F7FB;
    --slate-100: #E9EEF6;
    --slate-200: #DAE2ED;
    --slate-300: #BCC8D9;
    --slate-500: #64789A;
    --slate-600: #4A5D7C;
    --slate-800: #1B2C47;
    --slate-900: #0F1F36;
    --slate-950: #0A1628;

    --green-500: #12A150;
    --amber-500: #D97706;
    --red-500:   #DC2626;

    /* Type */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    --text-2xs: 0.6875rem;
    --text-xs:  0.75rem;
    --text-sm:  0.8125rem;
    --text-base:0.9375rem;
    --text-md:  1.0625rem;
    --text-lg:  1.25rem;
    --text-xl:  1.5rem;
    --text-2xl: 2rem;
    --text-3xl: 2.75rem;
    --text-4xl: clamp(2.5rem, 6vw, 4.25rem);

    --tracking-tight: -0.022em;
    --tracking-flat:  -0.011em;
    --tracking-wide:  0.08em;

    /* Space — 4px base, named by use rather than by number */
    --sp-1: 0.25rem; --sp-2: 0.5rem;  --sp-3: 0.75rem; --sp-4: 1rem;
    --sp-5: 1.5rem; --sp-6: 2rem;    --sp-7: 3rem;    --sp-8: 4rem;
    --sp-9: 6rem;   --sp-10: 8rem;

    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 18px;
    --radius-xl: 26px;
    --radius-pill: 999px;

    --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);

    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --dur-fast: 130ms;
    --dur: 220ms;
    --dur-slow: 520ms;

    --header-h: 64px;
    --sidebar-w: 256px;
    --content-max: 1180px;
  }

  /* Light — the default. */
  :root,
  [data-theme='light'] {
    color-scheme: light;

    --bg:          var(--slate-0);
    --bg-sunken:   var(--slate-50);
    --surface:     var(--slate-0);
    --surface-2:   var(--slate-25);
    --surface-alt: var(--slate-50);
    --border:      var(--slate-200);
    --border-soft: var(--slate-100);

    --fg:          var(--slate-950);
    --fg-strong:   #05101F;
    --fg-muted:    var(--slate-500);
    --fg-subtle:   var(--slate-300);
    --fg-on-accent:#FFFFFF;

    --accent:       var(--blue-600);
    --accent-hover: var(--blue-700);
    --accent-soft:  var(--blue-50);
    --accent-line:  var(--blue-200);

    --ok:    var(--green-500);
    --warn:  var(--amber-500);
    --alert: var(--red-500);

    --shadow-xs: 0 1px 2px rgba(11, 31, 54, 0.05);
    --shadow-sm: 0 1px 3px rgba(11, 31, 54, 0.07), 0 1px 2px rgba(11, 31, 54, 0.04);
    --shadow:    0 4px 16px rgba(11, 31, 54, 0.07), 0 1px 3px rgba(11, 31, 54, 0.05);
    --shadow-lg: 0 16px 44px rgba(11, 31, 54, 0.11), 0 3px 10px rgba(11, 31, 54, 0.05);
    --shadow-accent: 0 6px 22px rgba(29, 99, 255, 0.24);

    --skeleton-base:  var(--slate-100);
    --skeleton-sheen: var(--slate-0);
  }

  [data-theme='dark'] {
    color-scheme: dark;

    --bg:          var(--slate-950);
    --bg-sunken:   #071120;
    --surface:     #101F35;
    --surface-2:   #16273F;
    --surface-alt: #16273F;
    --border:      #22364F;
    --border-soft: #1A2B43;

    --fg:          #E8F0FA;
    --fg-strong:   #FFFFFF;
    --fg-muted:    #8DA4C2;
    --fg-subtle:   #55688A;
    --fg-on-accent:#FFFFFF;

    --accent:       #4E8BFF;
    --accent-hover: #6E9FFF;
    --accent-soft:  rgba(78, 139, 255, 0.14);
    --accent-line:  rgba(78, 139, 255, 0.34);

    --ok:    #2BC46F;
    --warn:  #F0A83C;
    --alert: #FF5A5A;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.42);
    --shadow:    0 8px 26px rgba(0, 0, 0, 0.48);
    --shadow-lg: 0 22px 56px rgba(0, 0, 0, 0.56);
    --shadow-accent: 0 6px 26px rgba(29, 99, 255, 0.36);

    --skeleton-base:  #16273F;
    --skeleton-sheen: #1F3350;
  }
}

/* ── reset ──────────────────────────────────────────────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }

  html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

  body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--fg);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'cv05' 1, 'cv08' 1, 'ss01' 1, 'tnum' 0;
  }

  img, svg, video, canvas { display: block; max-width: 100%; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { background: none; border: 0; cursor: pointer; }
  a { color: inherit; text-decoration: none; }
  table { border-collapse: collapse; width: 100%; }

  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ── base typography ────────────────────────────────────────────────────── */
@layer base {
  h1, h2, h3, h4 {
    font-weight: 640;
    letter-spacing: var(--tracking-tight);
    line-height: 1.14;
    color: var(--fg-strong);
    text-wrap: balance;
  }

  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-lg); letter-spacing: var(--tracking-flat); }
  h4 { font-size: var(--text-md); letter-spacing: var(--tracking-flat); }

  p { text-wrap: pretty; }

  .eyebrow {
    font-size: var(--text-2xs);
    font-weight: 620;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: var(--accent);
  }

  .lede {
    font-size: var(--text-md);
    color: var(--fg-muted);
    max-width: 58ch;
  }

  .num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
  }

  .mono { font-family: var(--font-mono); font-size: 0.92em; }
}

/* ── components ─────────────────────────────────────────────────────────── */
@layer components {

  /* The mark. Always the WiFi glyph, never a wordmark. */
  .mark {
    display: inline-grid;
    place-items: center;
    width: 38px; height: 38px;
    border-radius: var(--radius);
    background: linear-gradient(150deg, var(--blue-500), var(--blue-700));
    box-shadow: var(--shadow-accent);
    color: #fff;
    flex: none;
  }
  .mark svg { width: 21px; height: 21px; }
  .mark--sm { width: 30px; height: 30px; border-radius: var(--radius-sm); }
  .mark--sm svg { width: 17px; height: 17px; }
  .mark--lg { width: 56px; height: 56px; border-radius: var(--radius-lg); }
  .mark--lg svg { width: 30px; height: 30px; }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.6875rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: var(--text-sm);
    font-weight: 580;
    letter-spacing: var(--tracking-flat);
    white-space: nowrap;
    border: 1px solid transparent;
    transition: background var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease),
                box-shadow var(--dur) var(--ease),
                transform var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease);
  }
  .btn:active { transform: translateY(1px); }
  .btn:disabled, .btn[aria-disabled='true'] { opacity: 0.5; pointer-events: none; }

  .btn--primary {
    background: var(--accent);
    color: var(--fg-on-accent);
    box-shadow: var(--shadow-accent);
  }
  .btn--primary:hover { background: var(--accent-hover); }

  .btn--secondary {
    background: var(--surface);
    color: var(--fg);
    border-color: var(--border);
    box-shadow: var(--shadow-xs);
  }
  .btn--secondary:hover { border-color: var(--accent-line); color: var(--accent); }

  .btn--ghost { color: var(--fg-muted); }
  .btn--ghost:hover { color: var(--fg); background: var(--surface-alt); }

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

  .btn--lg { padding: 0.875rem 1.75rem; font-size: var(--text-base); }
  .btn--sm { padding: 0.4375rem 0.875rem; font-size: var(--text-xs); }
  .btn--block { width: 100%; }

  /* Cards */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }
  .card__body { padding: var(--sp-5); }
  .card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border-soft);
  }
  .card__title { font-size: var(--text-base); font-weight: 600; }
  .card--hover { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
  .card--hover:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

  /* Stat tile */
  .stat { padding: var(--sp-5); }
  .stat__label {
    font-size: var(--text-xs);
    font-weight: 560;
    color: var(--fg-muted);
    letter-spacing: 0.01em;
  }
  .stat__value {
    font-size: var(--text-2xl);
    font-weight: 680;
    letter-spacing: var(--tracking-tight);
    font-variant-numeric: tabular-nums;
    margin-top: var(--sp-2);
  }
  .stat__delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: 560; margin-top: var(--sp-2); }
  .stat__delta--up   { color: var(--ok); }
  .stat__delta--down { color: var(--alert); }

  /* Form */
  .field { display: grid; gap: var(--sp-2); }
  .field__label { font-size: var(--text-sm); font-weight: 560; }
  .field__hint  { font-size: var(--text-xs); color: var(--fg-muted); }
  .field__error { font-size: var(--text-xs); color: var(--alert); }

  .input, .select, .textarea {
    width: 100%;
    padding: 0.6875rem 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  }
  .input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
  .input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
  }
  .input[aria-invalid='true'] { border-color: var(--alert); }
  .textarea { min-height: 108px; resize: vertical; }

  /* Badges */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0.1875rem 0.625rem;
    border-radius: var(--radius-pill);
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: 0.015em;
    background: var(--surface-alt);
    color: var(--fg-muted);
    border: 1px solid var(--border-soft);
  }
  .badge::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
  }
  .badge--ok    { color: var(--ok);     background: color-mix(in srgb, var(--ok) 11%, transparent);     border-color: color-mix(in srgb, var(--ok) 26%, transparent); }
  .badge--warn  { color: var(--warn);   background: color-mix(in srgb, var(--warn) 12%, transparent);   border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
  .badge--alert { color: var(--alert);  background: color-mix(in srgb, var(--alert) 11%, transparent);  border-color: color-mix(in srgb, var(--alert) 26%, transparent); }
  .badge--info  { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }

  /* Table */
  .table { font-size: var(--text-sm); }
  .table th {
    text-align: left;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--fg-muted);
    letter-spacing: 0.02em;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
  }
  .table td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
  }
  .table tbody tr { transition: background var(--dur-fast) var(--ease); }
  .table tbody tr:hover { background: var(--surface-alt); }
  .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

  /* Skeletons — one shimmer definition, reused by shape */
  .skel {
    position: relative;
    overflow: hidden;
    background: var(--skeleton-base);
    border-radius: var(--radius-sm);
  }
  .skel::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg,
      transparent,
      color-mix(in srgb, var(--skeleton-sheen) 70%, transparent),
      transparent);
    animation: skel-sweep 1.4s var(--ease-in-out) infinite;
  }
  .skel--text  { height: 0.75rem; }
  .skel--title { height: 1.375rem; width: 42%; }
  .skel--line  { height: 0.75rem; width: 100%; }
  .skel--line-short { height: 0.75rem; width: 62%; }
  .skel--stat  { height: 2rem; width: 55%; }
  .skel--chip  { height: 1.25rem; width: 4.5rem; border-radius: var(--radius-pill); }
  .skel--avatar{ height: 38px; width: 38px; border-radius: var(--radius); }
  .skel--block { height: 200px; border-radius: var(--radius-lg); }
  .skel-stack > * + * { margin-top: var(--sp-3); }

  @keyframes skel-sweep { to { transform: translateX(100%); } }

  /* Signal arcs — the signature. Used for loading and as section markers. */
  .signal { display: inline-flex; align-items: flex-end; gap: 3px; height: 16px; }
  .signal span {
    width: 3px;
    border-radius: 2px;
    background: currentColor;
    opacity: 0.28;
    animation: signal-pulse 1.25s var(--ease-in-out) infinite;
  }
  .signal span:nth-child(1) { height: 5px;  animation-delay: 0ms; }
  .signal span:nth-child(2) { height: 9px;  animation-delay: 140ms; }
  .signal span:nth-child(3) { height: 13px; animation-delay: 280ms; }
  .signal span:nth-child(4) { height: 16px; animation-delay: 420ms; }

  @keyframes signal-pulse {
    0%, 100% { opacity: 0.28; }
    45%      { opacity: 1; }
  }

  /* Empty state */
  .empty { display: grid; place-items: center; gap: var(--sp-3); padding: var(--sp-8) var(--sp-5); text-align: center; }
  .empty__title { font-size: var(--text-md); font-weight: 600; }
  .empty__body { font-size: var(--text-sm); color: var(--fg-muted); max-width: 42ch; }

  /* Toast */
  .toast {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: toast-in var(--dur) var(--ease);
  }
  .toast--ok    { border-left-color: var(--ok); }
  .toast--warn  { border-left-color: var(--warn); }
  .toast--alert { border-left-color: var(--alert); }

  @keyframes toast-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: none; }
  }
}

/* ── utilities ──────────────────────────────────────────────────────────── */
@layer utilities {
  .wrap { width: min(100% - 2.5rem, var(--content-max)); margin-inline: auto; }
  .stack > * + * { margin-top: var(--gap, var(--sp-4)); }
  .row { display: flex; align-items: center; gap: var(--sp-3); }
  .row--between { justify-content: space-between; }
  .row--wrap { flex-wrap: wrap; }
  .grid { display: grid; gap: var(--sp-4); }
  .grid--2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
  .grid--3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
  .grid--4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

  .muted { color: var(--fg-muted); }
  .subtle { color: var(--fg-subtle); }
  .accent { color: var(--accent); }
  .small { font-size: var(--text-sm); }
  .xs { font-size: var(--text-xs); }
  .center { text-align: center; }
  .hidden { display: none !important; }

  .sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }

  /* Scroll-triggered reveal, driven by IntersectionObserver in kadili.js */
  .reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
  }
  .reveal.is-in { opacity: 1; transform: none; }
}
