/* KPI Architect — Design System
   Light theme, Happy Job inspired:
   - фон #ffffff / #f4f6f8
   - тёмные акценты #0f2c4a (navy)
   - CTA-зелёный #2ECC71 (с hover #25A55A)
   - серая рамка #e3e8ee
   - скруглённые радиусы 12-16px
   - карточки с тонкой рамкой + очень лёгкая тень
*/
:root {
  /* Telegram-theme overrides (светлая) */
  --bg-primary: #ffffff;
  --bg-secondary: #f4f6f8;
  --bg-tertiary: #eef1f5;
  --text-primary: #0f2c4a;
  --text-secondary: #5b6b7d;
  --text-muted: #8b96a4;
  --accent: #2ECC71;
  --accent-hover: #25A55A;
  --accent-soft: #E8FAF0;
  --accent-text: #ffffff;
  --navy: #0f2c4a;
  --navy-soft: #f4f6f8;
  --success: #2ECC71;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #e3e8ee;
  --border-strong: #cbd5e1;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15,44,74,0.04);
  --shadow: 0 1px 3px rgba(15,44,74,0.06);
  --shadow-md: 0 4px 12px rgba(15,44,74,0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body {
  padding-top: var(--safe-top);
  padding-bottom: calc(96px + var(--safe-bottom));
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

button, a, input, select, textarea { touch-action: manipulation; }
button, [role="button"], input, select { min-height: 44px; }
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #0b76d1;
  outline-offset: 2px;
}

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

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

.page { max-width: 720px; margin: 0 auto; padding: 12px; }

/* ---------- Header ---------- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0 16px; gap: 12px;
}
.page-header h1 {
  margin: 0; font-size: 22px; font-weight: 700;
  color: var(--navy); letter-spacing: -0.01em;
}
.page-header .sub { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 14px 16px; border-radius: var(--radius);
  border: 0; background: var(--accent); color: var(--accent-text);
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .15s, transform .05s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(46,204,113,0.2);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.99); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.secondary {
  background: var(--bg-primary); color: var(--navy);
  border: 1px solid var(--border-strong); box-shadow: none;
}
.btn.secondary:hover { background: var(--bg-tertiary); }
.btn.navy { background: var(--navy); color: #fff; box-shadow: 0 1px 2px rgba(15,44,74,0.2); }
.btn.navy:hover { background: #0a2240; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn.small { width: auto; padding: 8px 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; }

/* ---------- Card ---------- */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 16px; font-weight: 700; color: var(--navy); }
.card .meta { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }
.card .score { font-size: 28px; font-weight: 700; color: var(--navy); letter-spacing: -0.02em; }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label {
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.input, .textarea, .select {
  width: 100%; padding: 12px 14px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--bg-primary); color: var(--text-primary);
  font-size: 15px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 100px; resize: vertical; }

/* ---------- Grids ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.tile {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .15s, transform .05s, box-shadow .15s;
  min-height: 116px;
  text-decoration: none; color: var(--text-primary);
}
.tile:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.tile:active { transform: scale(0.99); }
.tile .ico { font-size: 28px; line-height: 1; }
.tile .lbl { font-weight: 700; margin-top: 8px; font-size: 14px; color: var(--navy); }
.tile .hint {
  color: var(--text-secondary); font-size: 11px; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 30px; line-height: 1.35;
}

.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* ---------- Stats row ---------- */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.stat {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 12px 6px; text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.stat .v { font-size: 20px; font-weight: 700; color: var(--navy); letter-spacing: -0.02em; }
.stat .l { color: var(--text-secondary); font-size: 10px; margin-top: 2px;
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

/* ---------- KPI block ---------- */
.kpi-block {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.kpi-block .name { font-weight: 700; color: var(--navy); font-size: 15px; }
.kpi-block .meta { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs .tab {
  flex: 1; text-align: center; padding: 10px;
  background: var(--bg-primary); color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.tabs .tab.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}

.progress { background: var(--bg-tertiary); height: 8px; border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; border-radius: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(100px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff;
  padding: 10px 18px; border-radius: 24px;
  font-size: 14px; font-weight: 600;
  z-index: 1000; box-shadow: var(--shadow-md);
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--accent); }

/* ---------- Bottom Tab Bar ---------- */
.app-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 50;
  box-shadow: 0 -1px 3px rgba(15,44,74,0.04);
}
.app-tab {
  flex: 1; text-align: center; font-size: 11px;
  text-decoration: none; color: var(--text-secondary);
  padding: 4px; font-weight: 600;
  transition: color .15s;
}
.app-tab.active { color: var(--accent); }
.app-tab::before { display: block; font-size: 20px; margin-bottom: 2px; }
.app-tab[href="index.html"]::before { content: "🏠"; }
.app-tab[href="kpis.html"]::before { content: "📈"; }
.app-tab[href="audit-text.html"]::before { content: "🔍"; }
.app-tab[href="cases.html"]::before { content: "📚"; }
.app-tab[href="profile.html"]::before { content: "👤"; }

/* ---------- Result footer ---------- */
.result-footer {
  position: fixed; left: 0; right: 0;
  bottom: calc(56px + var(--safe-bottom));
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  padding: 6px; z-index: 40;
}
.rf-btn {
  background: var(--bg-secondary);
  border: 0; border-radius: var(--radius-sm);
  padding: 8px 4px; font-size: 10px;
  color: var(--text-primary); font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.rf-btn:active { background: var(--bg-tertiary); }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, #f8fafc 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%; animation: skel 1.2s infinite;
  border-radius: 6px; height: 14px; margin: 4px 0;
}
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
  background: var(--bg-tertiary); color: var(--text-secondary);
}
.badge.active { background: var(--accent-soft); color: var(--accent-hover); }
.badge.draft { background: #fef3c7; color: #b45309; }
.badge.audit { background: #dbeafe; color: #1e40af; }
.badge.danger { background: #fee2e2; color: #b91c1c; }
