/* Kreditpartner stats dashboard — self-contained, does not import or
   share anything with the main site's CSS. */

:root {
  --deep-green: #1E5C4F;
  --ivory: #F2F1EA;
  --line: #DEDCD2;
  --light-green: #E6EFEA;
  --ink: #202521;
  --muted: #5B6360;
  --white: #FFFFFF;
  --danger: #B3402C;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(32, 37, 33, 0.06), 0 4px 16px rgba(32, 37, 33, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

/* Numbers everywhere use tabular figures + Swedish grouping (see
   formatNumber()/formatSEK() in assets/js/dashboard.js). */
.num, .big-number, table td.num {
  font-feature-settings: "tnum" 1;
  font-variant-numeric: tabular-nums;
}

a { color: var(--deep-green); }

/* ---------- top nav ---------- */

.kk-nav {
  background: var(--deep-green);
  color: var(--ivory);
}
.kk-nav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.kk-nav-title {
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-right: auto;
}
.kk-nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.kk-nav-links a {
  color: var(--ivory);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0.82;
}
.kk-nav-links a:hover { opacity: 1; }
.kk-nav-links a.is-active {
  background: rgba(255, 255, 255, 0.14);
  opacity: 1;
}
.kk-nav-logout {
  color: var(--ivory);
  opacity: 0.7;
  text-decoration: none;
  font-size: 13px;
}
.kk-nav-logout:hover { opacity: 1; }

/* ---------- layout ---------- */

.kk-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.kk-subtitle { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.kk-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.kk-section { margin-top: 20px; }

/* ---------- filter bar (date range + test data toggle) ---------- */

.kk-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.kk-preset {
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}
.kk-preset:hover { border-color: var(--deep-green); }
.kk-preset.is-active {
  background: var(--deep-green);
  border-color: var(--deep-green);
  color: var(--ivory);
}
.kk-custom-range {
  display: none;
  align-items: center;
  gap: 6px;
}
.kk-custom-range.is-visible { display: inline-flex; }
.kk-custom-range input[type="date"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
}
.kk-toggle {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.kk-toggle input { accent-color: var(--deep-green); }
.kk-loading { font-size: 13px; color: var(--muted); }

/* ---------- key numbers grid ---------- */

.kk-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.kk-kpi {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kk-kpi-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.kk-kpi-value { font-size: 24px; font-weight: 700; color: var(--deep-green); }

/* ---------- bar charts (hand-rolled, no chart library) ---------- */

.kk-bars { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.kk-bar-col { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; justify-content: flex-end; }
.kk-bar-value { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kk-bar {
  width: 100%;
  max-width: 48px;
  background: var(--light-green);
  border: 1px solid var(--deep-green);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
}
.kk-bar-label { font-size: 12px; color: var(--muted); margin-top: 6px; }

.kk-daily-chart { overflow-x: auto; }
.kk-daily-bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; min-width: 100%; }
.kk-daily-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 10px; flex: 1; position: relative; }
.kk-daily-bar { width: 100%; max-width: 14px; border-radius: 2px 2px 0 0; min-height: 1px; }
.kk-daily-bar.is-applications { background: var(--deep-green); }
.kk-daily-bar.is-revenue { background: var(--light-green); border: 1px solid var(--deep-green); }
.kk-daily-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.kk-daily-legend span { display: inline-flex; align-items: center; gap: 6px; }
.kk-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.kk-dot.is-applications { background: var(--deep-green); }
.kk-dot.is-revenue { background: var(--light-green); border: 1px solid var(--deep-green); }

/* ---------- tables ---------- */

.kk-table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table.kk-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  font-size: 13.5px;
}
table.kk-table th, table.kk-table td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.kk-table th:first-child, table.kk-table td:first-child,
table.kk-table th.text, table.kk-table td.text {
  text-align: left;
}
table.kk-table thead th {
  background: var(--light-green);
  color: var(--deep-green);
  font-weight: 600;
  position: sticky;
  top: 0;
  cursor: pointer;
}
table.kk-table thead th.is-sorted::after { content: " ▾"; font-size: 10px; }
table.kk-table thead th.is-sorted.is-asc::after { content: " ▴"; }
table.kk-table tbody tr:hover { background: var(--ivory); }
table.kk-table tr.is-test-row { opacity: 0.6; }

.kk-group-row { cursor: pointer; font-weight: 600; background: var(--ivory); }
.kk-group-toggle { display: inline-block; width: 14px; }
.kk-row-level-1 td:first-child { padding-left: 28px; }
.kk-row-level-2 td:first-child { padding-left: 44px; }
.kk-row-hidden { display: none; }

.kk-table-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.kk-btn {
  background: var(--deep-green);
  color: var(--ivory);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.kk-btn:hover { background: #164A40; }
.kk-btn.is-secondary {
  background: var(--white);
  color: var(--deep-green);
  border: 1px solid var(--deep-green);
}

/* ---------- login page ---------- */

.kk-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.kk-login-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
}
.kk-login-card h1 { font-size: 18px; margin-bottom: 18px; }
.kk-login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.kk-login-card input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  margin-bottom: 14px;
}
.kk-login-card button {
  width: 100%;
  background: var(--deep-green);
  color: var(--ivory);
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.kk-login-error {
  color: var(--danger);
  font-size: 13px;
  margin: -4px 0 14px;
  min-height: 16px;
}

/* ---------- misc ---------- */

.kk-empty { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }
.kk-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* Hidden until auth-guard.js confirms a session, to avoid flashing
   dashboard chrome before the redirect-to-login check completes. */
html.kk-auth-pending body { visibility: hidden; }

@media (max-width: 640px) {
  .kk-nav-inner { gap: 10px; }
  .kk-kpis { grid-template-columns: repeat(2, 1fr); }
  .kk-kpi-value { font-size: 20px; }
  .kk-main { padding: 16px 14px 48px; }
}
