/* ==========================================================================
   Kami — Stone Garden
   A quiet, organic interface. Pastel moss, warm salmon, serif ink.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght,SOFT@0,9..144,300..700,0..100;1,9..144,300..700,0..100&family=Newsreader:ital,opsz,wght@0,6..72,300..700;1,6..72,300..600&display=swap');

:root {
  /* Paper & Ink */
  --paper:        #F4EFE4;
  --paper-warm:   #EFE8D8;
  --ink:          #2A2E26;
  --ink-soft:     #545849;
  --ink-mute:     #8B8E7F;

  /* Moss (primary) */
  --moss-50:      #EDF1E3;
  --moss-100:    #DCE5C9;
  --moss-200:    #C4D3A8;
  --moss-300:    #A8BD86;
  --moss-400:    #8BA467;
  --moss-500:    #6F884E;
  --moss-ink:    #3F4A2C;

  /* Salmon / Terracotta (highlight) */
  --salmon-100: #FBD9C7;
  --salmon-200: #F6B89E;
  --salmon-300: #EF9574;
  --salmon-400: #E57551;
  --terracotta: #C45A34;

  /* Semantic */
  --success:     #6F884E;
  --warn:        #D99152;
  --error:       #B94A2B;

  /* Geometry */
  --radius-sm:   10px;
  --radius-md:   18px;
  --radius-lg:   26px;
  --radius-xl:   36px;
  --radius-stone: 42% 58% 55% 45% / 48% 42% 58% 52%;

  /* Shadows — warm, diffuse */
  --shadow-soft: 0 2px 6px rgba(60, 46, 30, 0.04), 0 14px 40px -18px rgba(60, 46, 30, 0.18);
  --shadow-card: 0 1px 2px rgba(60, 46, 30, 0.04), 0 20px 60px -32px rgba(60, 46, 30, 0.25);
  --shadow-lift: 0 2px 4px rgba(60, 46, 30, 0.05), 0 36px 80px -28px rgba(60, 46, 30, 0.28);

  /* Motion */
  --ease-soft:   cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-calm:   cubic-bezier(0.4, 0.0, 0.2, 1);

  /* Type */
  --display:     'Fraunces', 'Iowan Old Style', 'Apple Garamond', Georgia, serif;
  --body:        'Newsreader', 'Iowan Old Style', Georgia, serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--body);
  font-weight: 400;
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  overflow-x: hidden;
}

/* Atmospheric gradient mesh — drifts very slowly behind everything */
body::before {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -2;
  background:
    radial-gradient(40% 35% at 15% 20%,  rgba(168, 189, 134, 0.55) 0%, transparent 60%),
    radial-gradient(35% 30% at 85% 15%,  rgba(246, 184, 158, 0.50) 0%, transparent 65%),
    radial-gradient(45% 40% at 75% 80%,  rgba(220, 229, 201, 0.70) 0%, transparent 70%),
    radial-gradient(30% 25% at 20% 85%,  rgba(239, 149, 116, 0.35) 0%, transparent 70%);
  filter: blur(40px) saturate(1.05);
  animation: drift 38s var(--ease-calm) infinite alternate;
}

/* Paper grain overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.16 0 0 0 0 0.18 0 0 0 0 0.15 0 0 0 0.14 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
  opacity: 0.35;
}

@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { transform: translate3d(-3%, 2%, 0) rotate(4deg); }
}

/* --------------------------------------------------------- Header / logo */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.4rem 2.2rem;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244, 239, 228, 0.72);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid rgba(84, 88, 73, 0.08);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.8rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 34px;
  height: 40px;
  flex-shrink: 0;
  transition: transform 600ms var(--ease-soft);
}
.brand:hover .brand-mark { transform: translateY(-2px) rotate(-2deg); }
.brand-mark .stone { transition: transform 500ms var(--ease-soft); }
.brand:hover .brand-mark .stone-top { transform: translateY(-1.2px) rotate(-3deg); }
.brand:hover .brand-mark .stone-mid { transform: translateY(-0.4px) rotate(1.5deg); }

.wordmark {
  font-family: var(--display);
  font-weight: 360;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
  font-variation-settings: "SOFT" 80, "opsz" 48;
  color: var(--ink);
  line-height: 1;
  padding-top: 2px;
}
.wordmark em {
  font-style: italic;
  color: var(--moss-500);
  font-weight: 320;
}

nav { display: flex; align-items: center; gap: 1.6rem; }
nav a {
  font-family: var(--body);
  font-size: 0.98rem;
  color: var(--ink-soft);
  text-decoration: none;
  position: relative;
  transition: color 200ms var(--ease-soft);
  padding: 0.3rem 0;
}
nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -2px;
  height: 1px;
  background: var(--moss-400);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 260ms var(--ease-soft);
}
nav a:hover { color: var(--moss-ink); }
nav a:hover::after { transform: scaleX(1); }
nav a.logout { color: var(--ink-mute); font-style: italic; }

/* User chip — right-aligned, initials front and center */
.user-chip {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background:
    radial-gradient(circle at 30% 30%, var(--salmon-200), var(--moss-300) 85%);
  box-shadow:
    0 0 0 2px var(--paper),
    0 0 0 3px rgba(168, 189, 134, 0.35),
    0 6px 16px -6px rgba(60, 46, 30, 0.35);
  cursor: default;
}
.user-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  display: block;
}
.user-chip .initials {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-weight: 500;
  font-variation-settings: "SOFT" 100, "opsz" 24;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--paper);
  text-shadow: 0 1px 2px rgba(60, 46, 30, 0.35);
}

/* --------------------------------------------------------- Layout & type */

main {
  max-width: 1180px;
  margin: 3.2rem auto 5rem;
  padding: 0 2.2rem;
  animation: rise 700ms var(--ease-soft) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

h1, h2, h3 {
  font-family: var(--display);
  color: var(--ink);
  font-weight: 360;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
  font-variation-settings: "SOFT" 50, "opsz" 72;
}
h1 { font-size: 3.4rem; line-height: 1.02; }
h2 { font-size: 2.1rem; line-height: 1.1; margin-bottom: 1.6rem; }
h3 { font-size: 1.4rem; line-height: 1.2; }
h2 em, h3 em { font-style: italic; color: var(--moss-500); font-weight: 320; }

p { margin: 0 0 1rem; color: var(--ink-soft); }

a { color: var(--moss-500); }
a:hover { color: var(--terracotta); }

/* --------------------------------------------------------- Buttons */

button, .btn {
  font-family: var(--body);
  font-size: 0.98rem;
  font-weight: 500;
  letter-spacing: 0.005em;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
  border: none;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition:
    transform 180ms var(--ease-soft),
    background 200ms var(--ease-soft),
    box-shadow 200ms var(--ease-soft);
  box-shadow: 0 1px 2px rgba(60, 46, 30, 0.1), 0 8px 24px -12px rgba(60, 46, 30, 0.45);
}
button:hover, .btn:hover {
  background: var(--moss-ink);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(60, 46, 30, 0.1), 0 14px 32px -10px rgba(60, 46, 30, 0.5);
}
button:active, .btn:active { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

button.secondary, .btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(84, 88, 73, 0.25);
  box-shadow: none;
}
button.secondary:hover, .btn.secondary:hover {
  background: rgba(168, 189, 134, 0.15);
  border-color: var(--moss-400);
  color: var(--moss-ink);
}

.btn.accent {
  background: var(--salmon-400);
  color: var(--paper);
}
.btn.accent:hover { background: var(--terracotta); }

/* --------------------------------------------------------- Cards & grid */

.card {
  background: rgba(255, 252, 245, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(168, 189, 134, 0.25);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.9rem;
  box-shadow: var(--shadow-soft);
  transition: transform 320ms var(--ease-soft),
              box-shadow 320ms var(--ease-soft),
              border-color 320ms var(--ease-soft);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.6rem;
}
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 2.4rem; }
@media (max-width: 760px) {
  .grid-2col { grid-template-columns: 1fr; }
}

/* App cards (formerly profile cards) */
.app-card {
  position: relative;
  display: block;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  isolation: isolate;
}
.app-card::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(80% 60% at 100% 0%, rgba(246, 184, 158, 0.28) 0%, transparent 55%),
    radial-gradient(90% 80% at 0% 100%, rgba(168, 189, 134, 0.24) 0%, transparent 60%);
  opacity: 0.9;
  transition: opacity 320ms var(--ease-soft);
}
.app-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
  border-color: var(--moss-300);
}
.app-card:hover::before { opacity: 1; }
.app-card h3 {
  margin-top: 0;
  margin-bottom: 0.4rem;
  font-variation-settings: "SOFT" 70, "opsz" 36;
}
.app-card p {
  color: var(--ink-soft);
  font-size: 0.98rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

/* Decorative app-card sigil (small stone mark top-right) */
.app-card .sigil {
  position: absolute;
  top: 1.1rem;
  right: 1.1rem;
  width: 22px;
  height: 26px;
  opacity: 0.5;
  transition: opacity 320ms var(--ease-soft), transform 320ms var(--ease-soft);
}
.app-card:hover .sigil {
  opacity: 1;
  transform: rotate(6deg) translateY(-1px);
}

.tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }
.tag {
  background: rgba(168, 189, 134, 0.22);
  color: var(--moss-ink);
  padding: 0.22rem 0.75rem;
  border-radius: 999px;
  font-family: var(--body);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  font-style: italic;
}

/* --------------------------------------------------------- Forms */

.form-field { margin-bottom: 1.4rem; }
.form-field label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--ink-soft);
  font-family: var(--body);
  font-size: 0.88rem;
  font-style: italic;
  letter-spacing: 0.01em;
}
.form-field input, .form-field textarea {
  width: 100%;
  padding: 0.75rem 0.95rem;
  background: rgba(255, 252, 245, 0.6);
  border: 1px solid rgba(84, 88, 73, 0.2);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  transition: border-color 200ms var(--ease-soft), background 200ms var(--ease-soft);
}
.form-field input:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--moss-400);
  background: rgba(255, 252, 245, 0.95);
  box-shadow: 0 0 0 3px rgba(168, 189, 134, 0.2);
}

/* --------------------------------------------------------- Status badges */

.status-badge {
  display: inline-block;
  padding: 0.18rem 0.7rem;
  border-radius: 999px;
  font-family: var(--body);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-left: 0.6rem;
  vertical-align: middle;
}
.status-pending   { background: rgba(84, 88, 73, 0.12);  color: var(--ink-soft); }
.status-running   { background: rgba(168, 189, 134, 0.28); color: var(--moss-ink); }
.status-completed { background: rgba(239, 149, 116, 0.22); color: var(--terracotta); }
.status-failed    { background: rgba(185, 74, 43, 0.15); color: var(--error); }

/* --------------------------------------------------------- Session rows */

.session-row {
  background: rgba(255, 252, 245, 0.72);
  border: 1px solid rgba(168, 189, 134, 0.22);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.5rem;
  margin-bottom: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  transition: border-color 240ms var(--ease-soft), background 240ms var(--ease-soft);
}
.session-row:hover {
  border-color: var(--moss-300);
  background: rgba(255, 252, 245, 0.92);
}
.session-row strong {
  font-family: var(--display);
  font-weight: 400;
  font-variation-settings: "SOFT" 60, "opsz" 20;
  font-size: 1.08rem;
  color: var(--ink);
}
.session-row .meta {
  color: var(--ink-mute);
  font-size: 0.86rem;
  margin-top: 4px;
  font-style: italic;
}
.session-row .run-id {
  color: var(--ink-mute);
  font-size: 0.74rem;
  margin-top: 2px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  opacity: 0.7;
}

/* --------------------------------------------------------- Alerts */

.alert {
  padding: 1rem 1.2rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.2rem;
  font-family: var(--body);
  border: 1px solid;
}
.alert-error { background: rgba(185, 74, 43, 0.08); border-color: rgba(185, 74, 43, 0.3); color: var(--error); }
.alert-success { background: rgba(168, 189, 134, 0.18); border-color: rgba(168, 189, 134, 0.45); color: var(--moss-ink); }

/* --------------------------------------------------------- Empty state */

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--ink-mute);
}
.empty-state p {
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink-mute);
}

/* --------------------------------------------------------- Login hero */

.login-hero {
  text-align: center;
  padding: 7rem 2rem 4rem;
  position: relative;
  max-width: 780px;
  margin: 0 auto;
}
.login-hero .hero-mark {
  width: 96px;
  height: 116px;
  margin: 0 auto 2.2rem;
  display: block;
  animation: breathe 6s var(--ease-calm) infinite;
}
@keyframes breathe {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-4px) rotate(-1deg); }
}
.login-hero h1 {
  font-size: clamp(3rem, 8vw, 5.2rem);
  font-weight: 340;
  letter-spacing: -0.03em;
  font-variation-settings: "SOFT" 100, "opsz" 144;
  margin-bottom: 0.6rem;
}
.login-hero h1 em {
  font-style: italic;
  color: var(--moss-500);
  font-weight: 300;
}
.login-hero .tagline {
  font-family: var(--body);
  font-size: 1.25rem;
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 2.6rem;
  line-height: 1.45;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

/* --------------------------------------------------------- Page header */

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.8rem;
}
.page-header h2 { margin-bottom: 0.4rem; }
.page-header .eyebrow {
  display: block;
  font-family: var(--body);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--moss-500);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

/* Column headings inside 2col layout */
.col-head {
  font-family: var(--body);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--moss-500);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1rem;
  padding-left: 0.2rem;
}

/* --------------------------------------------------------- Responsive */

@media (max-width: 640px) {
  header { padding: 1.1rem 1.4rem; }
  main { padding: 0 1.4rem; margin-top: 2.2rem; }
  .wordmark { font-size: 1.35rem; }
  h1 { font-size: 2.6rem; }
  h2 { font-size: 1.7rem; }
  nav { gap: 1rem; }
  nav a { font-size: 0.92rem; }
  .header-right { gap: 1rem; }
}

@media (max-width: 480px) {
  nav a:not(.logout) { display: none; }
  nav a.mobile-menu { display: inline; }
}

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