/*
 * kainet-ui.css — ONE shared component + motion layer for the dev templates.
 *
 * Tokens and components are the Mint SaaS design kit (templates/design_kit.md)
 * as CSS: tonal surfaces instead of 1px borders, gradient primary CTA, system
 * font stack, soft ambient shadows. Motion is native and cheap: cross-document
 * view transitions, one entrance animation, hover lifts — all killed by
 * prefers-reduced-motion.
 * WHY: 48 templates carry drifting copies of these tokens; a page that
 * imports this file instead stays cohesive with every other adopter for free.
 * Adoption rule: any template you touch imports this + the unified shell in
 * the same change (see design_kit.md §9).
 */

:root {
  --k-primary: #006B55;
  --k-mint: #2BB391;
  --k-surface: #F9F9FF;
  --k-surface-low: #F0F3FF;
  --k-surface-high: #DDE2F1;
  --k-sheet: #FFFFFF;
  --k-text: #161C26;
  --k-text-2: #3D4A5C;
  --k-text-3: #64748B;
  --k-success: #059669;
  --k-success-bg: #DCFCE7;
  --k-warning: #B45309;
  --k-warning-bg: #FEF3C7;
  --k-error: #B91C1C;
  --k-error-bg: #FEE2E2;
  --k-shadow: 0 12px 40px rgba(22, 28, 38, 0.06);
  --k-shadow-lift: 0 16px 48px rgba(22, 28, 38, 0.10);
  --k-radius-lg: 1rem;
  --k-radius-md: 0.75rem;
  --k-radius-sm: 0.5rem;
  --k-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --k-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --k-ease: cubic-bezier(0.22, 1, 0.36, 1);
  /* 8-pt spacing scale — every gap/pad below is one of these. */
  --k-sp-1: 4px;
  --k-sp-2: 8px;
  --k-sp-3: 16px;
  --k-sp-4: 24px;
  --k-sp-5: 32px;
  --k-sp-6: 48px;
}

html[data-theme="dark"] {
  --k-surface: #0F1418;
  --k-surface-low: #151B21;
  --k-surface-high: #232C34;
  --k-sheet: #1A2128;
  --k-text: #E7EAEE;
  --k-text-2: #B9C2CC;
  --k-text-3: #8A96A3;
  --k-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --k-shadow-lift: 0 16px 48px rgba(0, 0, 0, 0.45);
}

/* ── Page ground ─────────────────────────────────────────────────────── */

.k-page {
  font-family: var(--k-font);
  background: var(--k-surface);
  color: var(--k-text);
  margin: 0;
  min-height: 100vh;
}

.k-container { max-width: 1080px; margin: 0 auto; padding: var(--k-sp-5) var(--k-sp-4) var(--k-sp-6); display: grid; gap: var(--k-sp-4); }

.k-h1 { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 var(--k-sp-2); color: var(--k-primary); }
.k-h2 { font-size: 1rem; font-weight: 600; margin: 0 0 var(--k-sp-3); color: var(--k-text); }
.k-sub { color: var(--k-text-3); font-size: 0.85rem; line-height: 1.55; max-width: 720px; }

/* ── Cards — tonal depth, no border lines ────────────────────────────── */

.k-card {
  background: var(--k-sheet);
  border-radius: var(--k-radius-lg);
  padding: var(--k-sp-4);
  box-shadow: var(--k-shadow);
  transition: box-shadow 0.25s var(--k-ease), transform 0.25s var(--k-ease);
}

.k-card--lift:hover { box-shadow: var(--k-shadow-lift); transform: translateY(-2px); }

/* Entrance: cards rise in with a slight stagger set by inline order. */
.k-rise { animation: k-rise 0.45s var(--k-ease) both; }
.k-rise:nth-child(2) { animation-delay: 0.05s; }
.k-rise:nth-child(3) { animation-delay: 0.10s; }
.k-rise:nth-child(4) { animation-delay: 0.15s; }
.k-rise:nth-child(5) { animation-delay: 0.20s; }

@keyframes k-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ── Rows (label/value lists) — separation by tone, not lines ────────── */

.k-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--k-sp-3);
  padding: 12px var(--k-sp-3); font-size: 0.875rem; border-radius: var(--k-radius-sm);
}
.k-row:nth-child(even) { background: var(--k-surface-low); }

/* JS-rendered entity lists: every row tinted, separated by gap — zebra made
   the untinted rows' buttons look adrift. */
.k-rows { display: flex; flex-direction: column; gap: var(--k-sp-2); }
.k-rows .k-row { background: var(--k-surface-low); }
.k-rows .k-row:nth-child(even) { background: var(--k-surface-low); }
.k-row .k-label { color: var(--k-text-2); font-weight: 500; }
.k-row .k-value { font-family: var(--k-mono); font-size: 0.8rem; overflow-wrap: anywhere; text-align: right; }

/* ── Buttons ─────────────────────────────────────────────────────────── */

.k-btn {
  background: linear-gradient(135deg, var(--k-primary), var(--k-mint));
  color: #fff; border: 0; padding: 0 var(--k-sp-3); height: 40px; border-radius: var(--k-radius-sm);
  font: 600 0.9rem var(--k-font); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.15s var(--k-ease), box-shadow 0.15s var(--k-ease), opacity 0.15s;
}
.k-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0, 107, 85, 0.25); }
.k-btn:active { transform: none; }
.k-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.k-btn--secondary { background: var(--k-surface-high); color: var(--k-text); }
.k-btn--secondary:hover { box-shadow: 0 6px 18px rgba(22, 28, 38, 0.12); }
.k-btn--danger { background: var(--k-error); }
.k-btn--danger:hover { box-shadow: 0 6px 18px rgba(185, 28, 28, 0.25); }

:where(.k-btn, .k-input):focus-visible {
  outline: 2px solid var(--k-mint); outline-offset: 2px;
}

/* ── Inputs ──────────────────────────────────────────────────────────── */

.k-input {
  padding: 0 var(--k-sp-3); height: 40px; border: 0; border-radius: var(--k-radius-sm);
  background: var(--k-surface-low); color: var(--k-text);
  font: 0.9rem var(--k-mono); flex: 1; min-width: 0;
  transition: background 0.15s, box-shadow 0.15s;
}
.k-input:focus { background: var(--k-sheet); box-shadow: 0 0 0 2px var(--k-mint); outline: none; }
.k-input::placeholder { color: var(--k-text-3); }

.k-inline { display: flex; gap: var(--k-sp-2); align-items: center; }

/* ── Pills / messages / notes ────────────────────────────────────────── */

.k-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font: 600 0.7rem var(--k-font); }
.k-pill--ok { background: var(--k-success-bg); color: var(--k-success); }
.k-pill--err { background: var(--k-error-bg); color: var(--k-error); }
.k-pill--warn { background: var(--k-warning-bg); color: var(--k-warning); }

.k-msg { font-size: 0.85rem; margin-top: var(--k-sp-3); padding: 12px var(--k-sp-3); border-radius: var(--k-radius-sm);
         display: none; animation: k-rise 0.3s var(--k-ease) both; }
.k-msg--ok { display: block; background: var(--k-success-bg); color: var(--k-success); }
.k-msg--warn { display: block; background: var(--k-warning-bg); color: var(--k-warning); }
.k-msg--err { display: block; background: var(--k-error-bg); color: var(--k-error); }

.k-note { font-size: 0.8rem; color: var(--k-text-3); margin-top: var(--k-sp-3); line-height: 1.5; }
.k-empty { color: var(--k-text-3); font-size: 0.85rem; padding: var(--k-sp-2) 0; }

/* ── Card header (title + action on one line, spaced from content) ───── */

.k-card-head { display: flex; justify-content: space-between; align-items: center;
               margin-bottom: var(--k-sp-3); }
.k-card-head .k-h2 { margin: 0; }

/* ── Entity rows: name/id/chips/detail left, state + actions right ───── */

.k-entity { display: flex; flex-direction: column; gap: var(--k-sp-1); min-width: 0; }
.k-entity-title { font-weight: 600; color: var(--k-text); line-height: 1.45; overflow-wrap: anywhere; }
.k-entity-id { font-family: var(--k-mono); font-size: 0.75rem; color: var(--k-text-3); }
.k-chips { display: flex; gap: var(--k-sp-1); flex-wrap: wrap; align-items: center; }
.k-entity-actions { display: flex; align-items: center; gap: var(--k-sp-2); flex: none; }

/* ── Chips + detail lines (entity rows with metadata) ────────────────── */

.k-chip {
  display: inline-block; padding: 2px var(--k-sp-2); border-radius: 999px;
  font: 500 0.7rem var(--k-font); background: var(--k-surface-high); color: var(--k-text-2);
}
.k-detail { font-size: 0.78rem; color: var(--k-text-3); margin-top: var(--k-sp-1);
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 52ch; }

/* ── Provider tiles + grid (cards view, progressive disclosure) ──────── */

.k-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
          gap: var(--k-sp-3); }
.k-tile { cursor: pointer; text-align: left; border: 0; font: inherit; color: inherit;
          display: flex; flex-direction: column; gap: var(--k-sp-2); }
.k-tile-head { display: flex; align-items: center; gap: var(--k-sp-2); }
.k-tile-dot { width: 36px; height: 36px; border-radius: var(--k-radius-md); flex: none;
              display: grid; place-items: center;
              background: var(--k-surface-low); }
.k-tile-dot img, .k-card-head img.k-logo { width: 20px; height: 20px; display: block; }
.k-card-head .k-head-title { display: flex; align-items: center; gap: var(--k-sp-2); }
.k-tile-title { font-weight: 700; }
.k-tile-sub { font-size: 0.8rem; color: var(--k-text-3); line-height: 1.45; }

/* ── Segmented toggle (view preference) ──────────────────────────────── */

.k-seg { display: inline-flex; background: var(--k-surface-high); border-radius: 999px;
         padding: 3px; gap: 2px; }
.k-seg button { border: 0; background: none; padding: 6px var(--k-sp-3); border-radius: 999px;
                font: 600 0.8rem var(--k-font); color: var(--k-text-2); cursor: pointer;
                transition: background 0.15s, color 0.15s; }
.k-seg button.active { background: var(--k-sheet); color: var(--k-text);
                       box-shadow: 0 2px 8px rgba(22, 28, 38, 0.10); }

/* ── Modal (detail disclosure) ───────────────────────────────────────── */

.k-modal-overlay { position: fixed; inset: 0; background: rgba(22, 28, 38, 0.40);
                   backdrop-filter: blur(3px); z-index: 90; display: flex;
                   align-items: center; justify-content: center;
                   padding: var(--k-sp-4) var(--k-sp-3);
                   animation: k-fade 0.18s var(--k-ease) both; }
.k-modal { background: var(--k-sheet); border-radius: var(--k-radius-lg);
           box-shadow: var(--k-shadow-lift); width: min(760px, 100%);
           max-height: 88vh; overflow-y: auto;
           padding: var(--k-sp-4); animation: k-rise 0.24s var(--k-ease) both; }
.k-modal .k-card { box-shadow: none; padding: 0; background: transparent; border-radius: 0; }
.k-modal-close { float: right; border: 0; background: var(--k-surface-low);
                 border-radius: 999px; width: 32px; height: 32px; cursor: pointer;
                 font-size: 1rem; color: var(--k-text-2); }
.k-modal-close:hover { background: var(--k-surface-high); }
[hidden] { display: none !important; }

@keyframes k-fade { from { opacity: 0; } }

/* ── Loading skeleton ────────────────────────────────────────────────── */

.k-skeleton {
  border-radius: var(--k-radius-sm); min-height: 14px;
  background: linear-gradient(90deg, var(--k-surface-low) 25%, var(--k-surface-high) 50%, var(--k-surface-low) 75%);
  background-size: 200% 100%;
  animation: k-shimmer 1.2s linear infinite;
}
@keyframes k-shimmer { to { background-position: -200% 0; } }

/* ── Cross-document transitions — pages fade/slide into each other ───── */

@view-transition { navigation: auto; }

::view-transition-old(root) { animation: k-vt-out 0.18s var(--k-ease) both; }
::view-transition-new(root) { animation: k-vt-in 0.24s var(--k-ease) both; }

@keyframes k-vt-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes k-vt-in { from { opacity: 0; transform: translateY(6px); } }

/* ── Reduced motion: everything above degrades to instant ────────────── */

@media (prefers-reduced-motion: reduce) {
  .k-rise, .k-msg, .k-modal, .k-modal-overlay { animation: none; }
  .k-card, .k-btn { transition: none; }
  .k-skeleton { animation: none; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
