/* ============================================================
   KALBANORGE · KELIAS — PRODUCTION DESIGN SYSTEM
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap&subset=latin-ext');

/* ── CSS TOKENS ───────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:           #efe7d8;
  --surface:      #fbf6eb;
  --surface-2:    #e5d9c0;
  --surface-3:    #d9ca9e;

  /* Text */
  --ink:    #1a1410;
  --ink-2:  #4a3a2a;
  --ink-3:  #7a6a5a;
  --ink-4:  #a59580;

  /* Lines */
  --line:   #d4c4a8;
  --line-2: #c4b28a;

  /* Brand */
  --accent:       #1c3b80;
  --accent-soft:  #e6ecf8;
  --accent-2:     #b91c3a;
  --accent-2-soft:#fbe5ea;
  --accent-3:     #d99b26;
  --accent-3-soft:#fbefd2;

  /* Status */
  --ok:      #3f6b3a;
  --ok-soft: #e4ecdb;
  --err:     #b91c3a;
  --err-soft:#fbe5ea;

  /* Shape */
  --radius:    14px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  /* Typography */
  --font-sans:    'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  /* Lithuanian diacritics render reliably with Inter; keep display text on the same safe font. */
  --font-display: var(--font-sans);
  --font-head:    var(--font-display);
  --font-mono:    'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;

  /* Layout */
  --nav-bottom-h: 76px;
  --sidebar-w:    240px;
  --content-max:  680px;
}

/* ── DARK THEME ───────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #17130d;
  --surface:      #1f1a12;
  --surface-2:    #2b241a;
  --surface-3:    #3a3023;
  --ink:    #fbf6eb;
  --ink-2:  #d4c4a8;
  --ink-3:  #a59580;
  --ink-4:  #7a6a5a;
  --line:   #2f2718;
  --line-2: #3a3023;
  --accent:       #5f83d1;
  --accent-soft:  rgba(95,131,209,0.15);
  --accent-2:     #e04b6b;
  --accent-2-soft:rgba(224,75,107,0.15);
  --accent-3:     #e8b04a;
  --accent-3-soft:rgba(232,176,74,0.15);
  --ok:      #6fa469;
  --ok-soft: rgba(111,164,105,0.15);
  --err:     #e04b6b;
  --err-soft:rgba(224,75,107,0.15);
}

/* ── BASE RESET ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
}

body.app-page {
  /* Push content above bottom nav on mobile */
  padding-bottom: calc(var(--nav-bottom-h) + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 768px) {
  body.app-page {
    padding-bottom: 0;
    padding-left: var(--sidebar-w);
  }
}

h1, h2, h3, h4, h5, h6 { margin: 0; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; height: auto; display: block; }

/* ── LAYOUT CONTAINERS ────────────────────────────────────── */
.kn-page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 20px 32px;
}

.kn-page--wide {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px 32px;
}

/* ── TYPOGRAPHY ───────────────────────────────────────────── */
.kn-display {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

.kn-heading {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.kn-subheading {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.kn-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.kn-body  { font-size: 14px; line-height: 1.5; }
.kn-small { font-size: 12px; line-height: 1.4; }
.kn-field { display: flex; flex-direction: column; gap: 4px; }

/* ── COLORS ───────────────────────────────────────────── */
.kn-text-accent  { color: var(--accent); }
.kn-text-accent2 { color: var(--accent-2); }
.kn-text-accent3 { color: var(--accent-3); }
.kn-text-muted   { color: var(--ink-3); }
.kn-text-ok      { color: var(--ok); }
.kn-text-err     { color: var(--err); }

/* ── BUTTONS ──────────────────────────────────────────────── */
.kn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  transition: transform 0.1s, filter 0.1s, background 0.1s;
  cursor: pointer;
  text-decoration: none;
}

.kn-btn-primary {
  background: #24458f;
  color: #ffffff;
  border: 1.5px solid #24458f;
  opacity: 1;
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(36, 69, 143, 0.25);
}

.kn-btn-primary:hover {
  background: #1d3774;
  color: #ffffff;
  border-color: #1d3774;
  filter: none;
  text-decoration: none;
}

.kn-btn-primary:active {
  transform: scale(0.97);
}

.kn-btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}


.kn-btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.kn-btn-secondary:hover { background: var(--surface-2); text-decoration: none; }

.kn-btn-danger {
  background: var(--err-soft);
  color: var(--err);
  border: none;
}
.kn-btn-danger:hover { filter: brightness(0.95); }

.kn-btn-sm {
  padding: 9px 16px;
  font-size: 13px;
}

.kn-btn-lg {
  padding: 18px 32px;
  font-size: 16px;
}

.kn-btn-block {
  width: 100%;
  display: flex;
}

/* ── CARDS ────────────────────────────────────────────────── */
.kn-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--line);
}

.kn-card-hover {
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.kn-card-hover:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(28,59,128,0.1);
}

.kn-card-shadow {
  box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  border: none;
}

/* ── PILLS / BADGES ───────────────────────────────────────── */
.kn-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.kn-pill-accent  { background: var(--accent-soft);  color: var(--accent); }
.kn-pill-accent2 { background: var(--accent-2-soft); color: var(--accent-2); }
.kn-pill-accent3 { background: var(--accent-3-soft); color: var(--accent-3); }
.kn-pill-ok      { background: var(--ok-soft);  color: var(--ok); }
.kn-pill-err     { background: var(--err-soft);  color: var(--err); }
.kn-pill-dark    { background: var(--ink); color: var(--surface); }
.kn-pill-muted   { background: var(--surface-2); color: var(--ink-3); }

/* ── FORM ELEMENTS ────────────────────────────────────────── */
.kn-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.kn-label-field {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.kn-input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.kn-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.kn-input::placeholder { color: var(--ink-4); }

.kn-input-error { border-color: var(--err) !important; }

.kn-field-error {
  font-size: 12px;
  color: var(--err);
  margin-top: 4px;
}

/* ── PROGRESS BAR ─────────────────────────────────────────── */
.kn-progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.kn-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.kn-progress-fill--ok { background: var(--ok); }
.kn-progress-fill--accent3 { background: var(--accent-3); }

/* ── DIVIDER ──────────────────────────────────────────────── */
.kn-divider {
  height: 1px;
  background: var(--line);
  margin: 20px 0;
}

/* ── SECTION HEADER ───────────────────────────────────────── */
.kn-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.kn-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.kn-section-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

/* ── FLASH MESSAGES ───────────────────────────────────────── */
.kn-flash {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.kn-flash-ok  { background: var(--ok-soft);   color: var(--ok); }
.kn-flash-err { background: var(--err-soft);  color: var(--err); }
.kn-flash-info { background: var(--accent-soft); color: var(--accent); }
.kn-flash-warn { background: var(--accent-3-soft); color: #7a4800; }

/* ── SCROLL HELPERS ───────────────────────────────────────── */
.kn-scroll { scrollbar-width: none; -ms-overflow-style: none; }
.kn-scroll::-webkit-scrollbar { display: none; }

.kn-scroll-x {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.kn-scroll-x::-webkit-scrollbar { display: none; }

/* ── FAB (floating action) ────────────────────────────────── */
.kn-fab {
  transition: transform 0.15s, box-shadow 0.15s;
}
.kn-fab:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.15); }
.kn-fab:active { transform: translateY(0); }

/* ── SKELETON LOADER ──────────────────────────────────────── */
@keyframes kn-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.kn-skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 800px 100%;
  animation: kn-shimmer 1.4s infinite;
  border-radius: 6px;
}

/* ── ANIMATIONS ───────────────────────────────────────────── */
@keyframes kn-fadeIn  { from{opacity:0;transform:translateY(6px)}  to{opacity:1;transform:none} }
@keyframes kn-slideUp { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:none} }
@keyframes kn-pop     { 0%{transform:scale(0.5);opacity:0} 60%{transform:scale(1.12)} 100%{transform:scale(1);opacity:1} }
@keyframes kn-pulse   { 0%,100%{box-shadow:0 0 0 0 rgba(28,59,128,0.3)} 50%{box-shadow:0 0 0 10px rgba(28,59,128,0)} }
@keyframes kn-wave    { 0%,100%{transform:scaleY(0.4)} 50%{transform:scaleY(1)} }
@keyframes kn-spin    { to{transform:rotate(360deg)} }
@keyframes kn-blink   { 0%,50%{opacity:1} 51%,100%{opacity:0} }
@keyframes kn-confetti {
  0%   { transform: translateY(0) rotate(0);    opacity: 1 }
  100% { transform: translateY(200px) rotate(720deg); opacity: 0 }
}

.kn-anim-fadein  { animation: kn-fadeIn  0.3s ease both; }
.kn-anim-slideup { animation: kn-slideUp 0.35s ease both; }
.kn-anim-pop     { animation: kn-pop     0.5s ease both; }
.kn-anim-spin    { animation: kn-spin    1s linear infinite; }

.kn-wave-bar { animation: kn-wave 0.8s ease-in-out infinite; }

/* ── UTILITY ──────────────────────────────────────────────── */
.kn-flex   { display: flex; }
.kn-flex-col { display: flex; flex-direction: column; }
.kn-center { display: flex; align-items: center; justify-content: center; }
.kn-between { display: flex; align-items: center; justify-content: space-between; }
.kn-gap-4  { gap: 4px; }
.kn-gap-6  { gap: 6px; }
.kn-gap-8  { gap: 8px; }
.kn-gap-10 { gap: 10px; }
.kn-gap-12 { gap: 12px; }
.kn-gap-16 { gap: 16px; }
.kn-gap-20 { gap: 20px; }
.kn-mt-4   { margin-top: 4px; }
.kn-mt-8   { margin-top: 8px; }
.kn-mt-12  { margin-top: 12px; }
.kn-mt-16  { margin-top: 16px; }
.kn-mt-20  { margin-top: 20px; }
.kn-mt-24  { margin-top: 24px; }
.kn-mt-32  { margin-top: 32px; }
.kn-mt-40  { margin-top: 40px; }
.kn-mb-4   { margin-bottom: 4px; }
.kn-mb-8   { margin-bottom: 8px; }
.kn-mb-12  { margin-bottom: 12px; }
.kn-mb-16  { margin-bottom: 16px; }
.kn-mb-20  { margin-bottom: 20px; }
.kn-mb-24  { margin-bottom: 24px; }
.kn-w-full { width: 100%; }
.kn-text-center { text-align: center; }

/* ── AVATAR ───────────────────────────────────────────────── */
.kn-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-sans);
  flex-shrink: 0;
}

.kn-avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.kn-avatar-lg { width: 56px; height: 56px; font-size: 22px; }

/* ── ICON WRAPPER ─────────────────────────────────────────── */
.kn-icon-box {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kn-icon-box-sm { width: 32px; height: 32px; border-radius: 10px; }
.kn-icon-box-lg { width: 48px; height: 48px; border-radius: 16px; }

/* ── PAGE HEADER (app) ────────────────────────────────────── */
.kn-app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

/* ── OVERLAY / MODAL ──────────────────────────────────────── */
.kn-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 480px) {
  .kn-overlay { align-items: center; }
}

.kn-modal {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 24px 24px calc(32px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: kn-slideUp 0.3s ease both;
}

@media (min-width: 480px) {
  .kn-modal {
    border-radius: var(--radius-xl);
    max-width: 480px;
  }
}

/* ── GRID HELPERS ─────────────────────────────────────────── */
.kn-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kn-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }

@media (max-width: 479px) {
  .kn-page,
  .kn-page--wide {
    padding-left: 16px;
    padding-right: 16px;
  }

  .kn-grid-2,
  .kn-grid-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .kn-input,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .kn-tab-bar {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .kn-tab-bar::-webkit-scrollbar {
    display: none;
  }

  .kn-tab {
    min-height: 44px;
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media (max-width: 359px) {
  .kn-page,
  .kn-page--wide {
    padding-left: 12px;
    padding-right: 12px;
  }

  .kn-card {
    padding: 16px;
  }

  .kn-btn {
    min-height: 46px;
    padding-left: 16px;
    padding-right: 16px;
    white-space: normal;
    line-height: 1.2;
    text-align: center;
  }
}

/* ── STREAK PILL ──────────────────────────────────────────── */
.kn-streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-3-soft);
  color: #7a4800;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

/* ── LEVEL BADGE ──────────────────────────────────────────── */
.kn-level-a1 { background: var(--ok-soft);      color: var(--ok); }
.kn-level-a2 { background: var(--accent-soft);  color: var(--accent); }
.kn-level-b1 { background: var(--accent-2-soft);color: var(--accent-2); }
.kn-level-b2 { background: var(--accent-3-soft);color: #7a4800; }

/* ── TAB BAR ──────────────────────────────────────────────── */
.kn-tab-bar {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 4px;
}
.kn-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius) - 2px);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.kn-tab:hover { background: var(--surface); color: var(--ink-2); }
.kn-tab.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ── CHAT WINDOW (inline chat container) ─────────────────── */
.kn-chat-window {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-height: 280px;
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
