/* ==========================================================================
   KPI Control — dark (default) + light SaaS theme
   Sits on top of UIkit3's default CSS; only the pieces we actually use
   are restyled here. Variables first, then layout, then components.
   Theme is picked server-side (settings.theme, see api/theme_toggle.php)
   and applied as data-theme="dark|light" on <html> — no flash, no JS.
   Everything below the variable blocks reads only var(--kpi-*), so a
   theme switch never needs touching component rules again.
   ========================================================================== */

:root,
:root[data-theme="dark"] {
  --kpi-bg: #0d0e14;
  --kpi-bg-elevated: #12141d;
  --kpi-sidebar-bg: #10111a;
  --kpi-card-bg: #161924;
  --kpi-card-bg-soft: #1b1f2d;
  --kpi-border: rgba(255, 255, 255, 0.07);
  --kpi-border-strong: rgba(255, 255, 255, 0.12);
  --kpi-text: #e8eaf2;
  --kpi-text-secondary: #969bb3;
  --kpi-text-muted: #5e6178;
  --kpi-blue: #4e7cff;
  --kpi-blue-soft: rgba(78, 124, 255, 0.15);
  --kpi-green: #2ecc71;
  --kpi-green-soft: rgba(46, 204, 113, 0.15);
  --kpi-yellow: #f5b94d;
  --kpi-yellow-soft: rgba(245, 185, 77, 0.15);
  --kpi-red: #ef5a5a;
  --kpi-red-soft: rgba(239, 90, 90, 0.15);
  --kpi-purple: #9b6cff;
  --kpi-purple-soft: rgba(155, 108, 255, 0.15);
  --kpi-radius-lg: 18px;
  --kpi-radius-md: 14px;
  --kpi-radius-sm: 10px;
  --kpi-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --kpi-row-hover: #20243480;
}

:root[data-theme="light"] {
  --kpi-bg: #f3f4f8;
  --kpi-bg-elevated: #ffffff;
  --kpi-sidebar-bg: #ffffff;
  --kpi-card-bg: #ffffff;
  --kpi-card-bg-soft: #eef0f5;
  --kpi-border: rgba(15, 23, 42, 0.09);
  --kpi-border-strong: rgba(15, 23, 42, 0.16);
  --kpi-text: #1a1d29;
  --kpi-text-secondary: #5b6072;
  --kpi-text-muted: #9298ab;
  /* Accents deepened vs. the dark theme's neon variants — the same hex
     read at low contrast against white, so light mode uses darker,
     more saturated tones for the same visual "color family". */
  --kpi-blue: #3763e0;
  --kpi-blue-soft: rgba(55, 99, 224, 0.12);
  --kpi-green: #1f9d54;
  --kpi-green-soft: rgba(31, 157, 84, 0.12);
  --kpi-yellow: #b8790a;
  --kpi-yellow-soft: rgba(184, 121, 10, 0.14);
  --kpi-red: #d8433f;
  --kpi-red-soft: rgba(216, 67, 63, 0.12);
  --kpi-purple: #7c4fd6;
  --kpi-purple-soft: rgba(124, 79, 214, 0.12);
  --kpi-radius-lg: 18px;
  --kpi-radius-md: 14px;
  --kpi-radius-sm: 10px;
  --kpi-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --kpi-row-hover: rgba(15, 23, 42, 0.045);
}

* { box-sizing: border-box; }

html, body {
  background: var(--kpi-bg);
  color: var(--kpi-text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--kpi-blue); }
a:hover { color: var(--kpi-blue); opacity: 0.85; }

/* ---------- shell layout ---------- */

.kpi-shell { display: flex; min-height: 100vh; }

.kpi-sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--kpi-sidebar-bg);
  border-right: 1px solid var(--kpi-border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.kpi-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  font-weight: 700;
  font-size: 17px;
  color: var(--kpi-text);
}
.kpi-logo .kpi-logo-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--kpi-blue), var(--kpi-purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff;
}

.kpi-btn-new-task {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--kpi-blue);
  color: #fff;
  border: none;
  border-radius: var(--kpi-radius-sm);
  padding: 11px 14px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 18px;
  cursor: pointer;
  transition: opacity .15s ease;
}
.kpi-btn-new-task:hover { opacity: 0.88; color: #fff; }

.kpi-nav { list-style: none; margin: 0; padding: 0; flex: 1; }
.kpi-nav-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--kpi-text-muted);
  padding: 14px 10px 6px;
}
.kpi-nav li { margin-bottom: 2px; }
.kpi-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--kpi-radius-sm);
  color: var(--kpi-text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.kpi-nav a:hover { background: var(--kpi-card-bg); color: var(--kpi-text); }
.kpi-nav a.active { background: var(--kpi-blue-soft); color: var(--kpi-blue); }
.kpi-nav a .kpi-nav-badge {
  margin-left: auto;
  font-size: 11px;
  background: var(--kpi-red-soft);
  color: var(--kpi-red);
  padding: 1px 7px;
  border-radius: 8px;
  font-weight: 700;
}
.kpi-nav a.disabled { opacity: 0.45; cursor: default; pointer-events: none; }
.kpi-nav a .kpi-soon {
  margin-left: auto;
  font-size: 10px;
  color: var(--kpi-text-muted);
  border: 1px solid var(--kpi-border-strong);
  padding: 1px 6px;
  border-radius: 8px;
}

.kpi-sidebar-idea-bank {
  padding-top: 14px;
  border-top: 1px solid var(--kpi-border);
}
.kpi-sidebar-idea-bank a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--kpi-radius-sm);
  color: var(--kpi-text-muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.kpi-sidebar-idea-bank a:hover { background: var(--kpi-card-bg); color: var(--kpi-text-secondary); }
.kpi-sidebar-idea-bank a.active { background: var(--kpi-blue-soft); color: var(--kpi-blue); }

.kpi-sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--kpi-border);
  font-size: 12px;
  color: var(--kpi-text-muted);
}

/* ---------- main / topbar ---------- */

.kpi-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.kpi-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--kpi-border);
  background: var(--kpi-bg-elevated);
  position: sticky;
  top: 0;
  z-index: 20;
}

.kpi-search {
  flex: 1;
  min-width: 0;
  max-width: 420px;
  position: relative;
}
.kpi-search input {
  width: 100%;
  background: var(--kpi-card-bg);
  border: 1px solid var(--kpi-border);
  border-radius: var(--kpi-radius-sm);
  padding: 9px 14px 9px 36px;
  color: var(--kpi-text);
  font-size: 13px;
}
.kpi-search input::placeholder { color: var(--kpi-text-muted); }
.kpi-search .kpi-search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--kpi-text-muted);
}

.kpi-topbar-right { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.kpi-icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--kpi-radius-sm);
  background: var(--kpi-card-bg);
  border: 1px solid var(--kpi-border);
  color: var(--kpi-text-secondary);
  font-size: 16px;
  cursor: pointer;
}
.kpi-profile { display: flex; align-items: center; gap: 10px; }
.kpi-profile-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--kpi-purple), var(--kpi-blue));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff;
}
.kpi-profile-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.kpi-profile-role { font-size: 11px; color: var(--kpi-text-muted); }

.kpi-content { padding: 24px 28px 40px; flex: 1; }

.kpi-mobile-menu-btn { display: none; }
.kpi-sidebar-backdrop { display: none; }

/* ---------- responsive: tablet / mobile ---------- */

@media (max-width: 900px) {
  .kpi-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 24px 0 48px rgba(0, 0, 0, 0.5);
  }
  .kpi-sidebar.is-open { transform: translateX(0); }

  .kpi-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 90;
  }
  .kpi-sidebar-backdrop.is-open { display: block; }

  .kpi-mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--kpi-radius-sm);
    background: var(--kpi-card-bg);
    border: 1px solid var(--kpi-border);
    color: var(--kpi-text);
    flex-shrink: 0;
  }

  .kpi-topbar { padding: 12px 16px; gap: 10px; }
  .kpi-content { padding: 16px; }
  .kpi-profile-name, .kpi-profile-role { display: none; }
  .kpi-search { max-width: none; }
}

@media (max-width: 540px) {
  /* Purely decorative today (no click handler, nothing ever populates it) —
     the first thing to drop when the topbar runs out of room on a phone.
     Confirmed by direct measurement that the topbar overflows (search box,
     avatar and logout icon pushed past the edge) at 500px content width
     with all 5 icon buttons present — 540 leaves a safety margin above that. */
  .kpi-notif-btn { display: none; }
  /* Still tight even with the icon dropped (confirmed by measurement) —
     claw back a bit more from every button/gap in the row. */
  .kpi-topbar-right { gap: 6px; }
  .kpi-topbar-right .kpi-icon-btn,
  .kpi-topbar-right .kpi-profile-avatar { width: 32px; height: 32px; }
  /* The icon buttons are fixed-width and must win the space fight — give
     the search box a firm cap instead of trusting flex-shrink math against
     an <input>'s own intrinsic minimum width. */
  .kpi-search { flex: 0 1 120px; }
  /* Single-owner app — the avatar only ever shows one letter and there's
     no name/role next to it here already (hidden since 900px). Logout
     (next to it) must stay reachable, so this is the one left to drop. */
  .kpi-profile-avatar { display: none; }
  /* Force onto its own line instead of squeezing/clipping next to the
     other filter controls at phone width. */
  .kpi-view-toggle { width: 100%; margin-left: 0; justify-content: flex-end; }
}

@media (max-width: 480px) {
  .kpi-page-title { font-size: 19px; }
  .kpi-topbar-right { gap: 8px; }
  .kpi-card { padding: 14px; }
}

.kpi-page-header { margin-bottom: 20px; }
/* Title + action button (or date-nav buttons) sharing one header row —
 * wraps the action onto its own line instead of clipping it once the
 * title can't shrink any further (confirmed by screenshot: the "+"
 * button ran off the right edge on payments.php/projects.php/etc.
 * without this). Use alongside kpi-page-header, not instead of it. */
.kpi-header-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.kpi-page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.kpi-page-subtitle { color: var(--kpi-text-secondary); font-size: 13px; margin: 0; }

/* ---------- layout grid for dashboard-like pages ---------- */

.kpi-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
}
@media (max-width: 1100px) {
  .kpi-layout { grid-template-columns: 1fr; }
}

/* ---------- cards ---------- */

.kpi-card {
  background: var(--kpi-card-bg);
  border: 1px solid var(--kpi-border);
  border-radius: var(--kpi-radius-lg);
  box-shadow: var(--kpi-shadow);
  padding: 18px 20px;
}
.kpi-card-title {
  font-size: 14px; font-weight: 700; margin: 0 0 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.kpi-card-title small { color: var(--kpi-text-muted); font-weight: 500; font-size: 12px; }

/*
 * Self-adapting: as many columns as fit at >=150px each, always at
 * least 1. This row is reused with anywhere from 2 to 6 cards (see
 * index.php/payments.php/reports.php) — a per-page inline
 * grid-template-columns override used to hardcode the desktop column
 * count and would silently defeat this responsiveness (confirmed by
 * screenshot: cards clipped past the viewport edge on a phone). Don't
 * reintroduce a hardcoded repeat(N, ...) here or inline on a page.
 */
.kpi-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi-stat-card {
  background: var(--kpi-card-bg);
  border: 1px solid var(--kpi-border);
  border-radius: var(--kpi-radius-lg);
  padding: 16px 18px;
  box-shadow: var(--kpi-shadow);
}
.kpi-stat-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.kpi-stat-icon.is-blue { background: var(--kpi-blue-soft); color: var(--kpi-blue); }
.kpi-stat-icon.is-green { background: var(--kpi-green-soft); color: var(--kpi-green); }
.kpi-stat-icon.is-yellow { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.kpi-stat-icon.is-red { background: var(--kpi-red-soft); color: var(--kpi-red); }
.kpi-stat-icon.is-purple { background: var(--kpi-purple-soft); color: var(--kpi-purple); }

.kpi-stat-value { font-size: 22px; font-weight: 700; line-height: 1.1; }
.kpi-stat-label { font-size: 12.5px; color: var(--kpi-text-secondary); margin-top: 4px; }

/* ---------- quick add ---------- */

.kpi-quick-add {
  margin-bottom: 22px;
}
.kpi-quick-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.kpi-quick-add-form input[type="text"] {
  flex: 1;
  min-width: 220px;
}
.kpi-quick-add-form .uk-select,
.kpi-quick-add-form .uk-input {
  background: var(--kpi-card-bg-soft);
  border: 1px solid var(--kpi-border);
  color: var(--kpi-text);
  border-radius: var(--kpi-radius-sm);
}
.kpi-quick-add-form .uk-select:focus,
.kpi-quick-add-form .uk-input:focus { border-color: var(--kpi-blue); background: var(--kpi-card-bg-soft); color: var(--kpi-text); }
.kpi-quick-add-form button[type="submit"] {
  background: var(--kpi-blue);
  border: none;
  color: #fff;
  border-radius: var(--kpi-radius-sm);
  padding: 0 18px;
  height: 38px;
  font-weight: 600;
}

/* ---------- tables ---------- */

.kpi-table-wrap { overflow-x: auto; }
table.kpi-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
}
table.kpi-table thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--kpi-text-muted);
  font-weight: 600;
  padding: 0 14px 8px;
  border: none;
}
table.kpi-table tbody tr {
  background: var(--kpi-card-bg-soft);
}
table.kpi-table tbody tr:hover { background: var(--kpi-row-hover); }
table.kpi-table tbody td {
  padding: 12px 14px;
  font-size: 13.5px;
  border-top: 1px solid var(--kpi-border);
  border-bottom: 1px solid var(--kpi-border);
  vertical-align: middle;
}
table.kpi-table tbody td:first-child { border-left: 1px solid var(--kpi-border); border-radius: var(--kpi-radius-sm) 0 0 var(--kpi-radius-sm); }
table.kpi-table tbody td:last-child { border-right: 1px solid var(--kpi-border); border-radius: 0 var(--kpi-radius-sm) var(--kpi-radius-sm) 0; }
table.kpi-table .kpi-row-title { font-weight: 600; color: var(--kpi-text); }
table.kpi-table .kpi-row-meta { font-size: 12px; color: var(--kpi-text-muted); }
.kpi-table-empty { padding: 30px; text-align: center; color: var(--kpi-text-muted); }

/* ---------- badges ---------- */

.kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-status-inbox { background: var(--kpi-purple-soft); color: var(--kpi-purple); }
.badge-status-planned { background: var(--kpi-blue-soft); color: var(--kpi-blue); }
.badge-status-in_progress { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.badge-status-waiting { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.badge-status-done { background: var(--kpi-green-soft); color: var(--kpi-green); }
.badge-status-cancelled { background: var(--kpi-red-soft); color: var(--kpi-red); }

.badge-priority-low { background: rgba(255,255,255,0.07); color: var(--kpi-text-secondary); }
.badge-priority-normal { background: var(--kpi-blue-soft); color: var(--kpi-blue); }
.badge-priority-high { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.badge-priority-critical { background: var(--kpi-red-soft); color: var(--kpi-red); }

.badge-type { background: rgba(255,255,255,0.06); color: var(--kpi-text-secondary); }
.badge-no-link { background: rgba(255,255,255,0.06); color: var(--kpi-text-muted); border: 1px dashed var(--kpi-border-strong); }

.kpi-priority-score.is-high { background: var(--kpi-red-soft); color: var(--kpi-red); }
.kpi-priority-score.is-mid { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.kpi-priority-score.is-low { background: rgba(255,255,255,0.06); color: var(--kpi-text-muted); }

.kpi-day-load {
  font-size: 12.5px; font-weight: 600; padding: 6px 10px; border-radius: var(--kpi-radius-sm);
  margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.kpi-day-load.is-low { background: rgba(255,255,255,0.05); color: var(--kpi-text-muted); }
.kpi-day-load.is-mid { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.kpi-day-load.is-high { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.kpi-day-load.is-over { background: var(--kpi-red-soft); color: var(--kpi-red); }

.kpi-overload-box {
  background: var(--kpi-red-soft); border-radius: var(--kpi-radius-sm);
  padding: 10px 12px; margin-bottom: 14px;
}
.kpi-overload-title { font-size: 12.5px; font-weight: 600; color: var(--kpi-red); margin-bottom: 8px; }
.kpi-overload-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 0;
}
.kpi-overload-row-title { font-size: 13px; color: var(--kpi-text); }

.badge-period-planned { background: rgba(255,255,255,0.08); color: var(--kpi-text-secondary); }
.badge-period-active { background: var(--kpi-blue-soft); color: var(--kpi-blue); }
.badge-period-closed { background: var(--kpi-green-soft); color: var(--kpi-green); }

.badge-idea-new { background: rgba(255,255,255,0.08); color: var(--kpi-text-secondary); }
.badge-idea-queued { background: var(--kpi-purple-soft); color: var(--kpi-purple); }
.badge-idea-in_progress { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.badge-idea-done { background: var(--kpi-green-soft); color: var(--kpi-green); }
.badge-idea-rejected { background: rgba(255,255,255,0.08); color: var(--kpi-text-secondary); }

.badge-payment-status-planned { background: rgba(255,255,255,0.08); color: var(--kpi-text-secondary); }
.badge-payment-status-to_pay { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.badge-payment-status-paid { background: var(--kpi-green-soft); color: var(--kpi-green); }
.badge-payment-status-cancelled { background: var(--kpi-red-soft); color: var(--kpi-red); }

.kpi-overdue-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--kpi-red); display: inline-block; margin-right: 6px; }

.kpi-focus-star {
  background: none; border: none; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 4px;
  color: var(--kpi-text-muted);
}
.kpi-focus-star:hover { color: var(--kpi-yellow); }
.kpi-focus-star.is-active { color: var(--kpi-yellow); }
/* First column in task tables — kept narrow and leftmost so it's visible
   without horizontal scroll on a phone, the main place a star gets tapped. */
table.kpi-table th.kpi-col-focus, table.kpi-table td:has(.kpi-focus-star) { width: 1%; white-space: nowrap; }

/* ---------- right column widgets ---------- */

.kpi-side-stack { display: flex; flex-direction: column; gap: 18px; }

.kpi-mini-calendar table { width: 100%; border-collapse: collapse; }
.kpi-mini-calendar th { font-size: 10.5px; color: var(--kpi-text-muted); padding-bottom: 6px; font-weight: 600; }
.kpi-mini-calendar td { text-align: center; padding: 5px 0; font-size: 12.5px; color: var(--kpi-text-secondary); }
.kpi-mini-calendar td.kpi-cal-today { position: relative; }
.kpi-mini-calendar td.kpi-cal-today span {
  background: var(--kpi-blue); color: #fff; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
}
.kpi-mini-calendar td.kpi-cal-muted { color: var(--kpi-text-muted); opacity: 0.4; }
.kpi-mini-calendar td.kpi-cal-has-deadline { color: var(--kpi-yellow); font-weight: 700; }

table.kpi-full-calendar { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.kpi-full-calendar th { font-size: 11px; color: var(--kpi-text-muted); padding: 8px 4px; font-weight: 600; text-align: left; }
table.kpi-full-calendar td.kpi-cal-pad { background: transparent; border: none; }
table.kpi-full-calendar td.kpi-cal-day {
  vertical-align: top; height: 90px; padding: 6px 8px; border-radius: var(--kpi-radius-sm);
  border: 1px solid var(--kpi-border);
}
table.kpi-full-calendar td.kpi-cal-day.is-today { border-color: var(--kpi-blue); }
table.kpi-full-calendar td.kpi-cal-day.is-empty { background: transparent; }
table.kpi-full-calendar td.kpi-cal-day.is-low { background: var(--kpi-yellow-soft); opacity: 0.5; }
table.kpi-full-calendar td.kpi-cal-day.is-mid { background: var(--kpi-yellow-soft); }
table.kpi-full-calendar td.kpi-cal-day.is-over { background: var(--kpi-red-soft); }
.kpi-cal-day-num { font-weight: 700; font-size: 13px; display:flex; align-items:center; gap:4px; }
.kpi-cal-day-meta { font-size: 11px; color: var(--kpi-text-secondary); margin-top: 6px; display:flex; align-items:center; gap:4px; }
.kpi-cal-meeting-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--kpi-purple); display:inline-block; }
@media (max-width: 700px) {
  table.kpi-full-calendar td.kpi-cal-day { height: auto; min-height: 46px; font-size: 11px; }
}

.kpi-timer-widget { text-align: center; }
.kpi-timer-clock {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 4px;
}
.kpi-timer-task {
  font-size: 12.5px;
  color: var(--kpi-text-secondary);
  margin-bottom: 14px;
  min-height: 18px;
}
.kpi-timer-actions { display: flex; gap: 8px; justify-content: center; }
.kpi-timer-actions button {
  border-radius: var(--kpi-radius-sm);
  border: none;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.kpi-timer-stop { background: var(--kpi-red); color: #fff; }
.kpi-timer-empty { color: var(--kpi-text-muted); font-size: 13px; padding: 10px 0; }

.kpi-donut-wrap { display: flex; align-items: center; gap: 16px; }
.kpi-donut {
  width: 92px; height: 92px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--kpi-blue) calc(var(--kpi-donut-pct, 0) * 1%), var(--kpi-card-bg-soft) 0);
}
.kpi-donut-inner {
  width: 66px; height: 66px; border-radius: 50%;
  background: var(--kpi-card-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}
.kpi-week-stats-list { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.kpi-week-stats-list li { display: flex; justify-content: space-between; list-style: none; color: var(--kpi-text-secondary); }
.kpi-week-stats-list li b { color: var(--kpi-text); font-weight: 600; }

.kpi-margin-list { display: flex; flex-direction: column; gap: 12px; }
.kpi-margin-row { font-size: 12.5px; }
.kpi-margin-row-top { display: flex; justify-content: space-between; margin-bottom: 5px; }
.kpi-margin-row-name { font-weight: 600; color: var(--kpi-text); }
.kpi-margin-row-value { font-weight: 700; }
.kpi-margin-bar { height: 6px; border-radius: 6px; background: var(--kpi-card-bg-soft); overflow: hidden; }
.kpi-margin-bar-fill { height: 100%; border-radius: 6px; }

/* ---------- profit colors ---------- */
.kpi-profit-positive { color: var(--kpi-green); }
.kpi-profit-negative { color: var(--kpi-red); }
.kpi-profit-neutral { color: var(--kpi-text-muted); }

/* ---------- forms / item card ---------- */

.kpi-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
@media (max-width: 800px) { .kpi-form-grid { grid-template-columns: 1fr; } }
.kpi-form-grid label { font-size: 12.5px; color: var(--kpi-text-secondary); margin-bottom: 5px; display: block; }
.kpi-form-full { grid-column: 1 / -1; }

/* Section headers grouping a long form (e.g. item.php) into scannable
   chunks, and a collapsible variant for the least-often-edited group. */
.kpi-form-section-title {
  font-size: 12px; font-weight: 700; color: var(--kpi-text-secondary);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 18px 0 10px;
}
.kpi-form-section-title:first-of-type { margin-top: 0; }
details.kpi-form-details > summary.kpi-form-section-title {
  cursor: pointer; list-style: none;
}
details.kpi-form-details > summary.kpi-form-section-title::-webkit-details-marker { display: none; }
details.kpi-form-details > summary.kpi-form-section-title::before { content: '▸ '; }
details.kpi-form-details[open] > summary.kpi-form-section-title::before { content: '▾ '; }

/* Every UIkit form control and button is re-skinned globally — this is
   a single-theme dark app, there's no light-mode UIkit anywhere in it. */
.uk-select,
.uk-input,
.uk-textarea {
  background: var(--kpi-card-bg-soft);
  border: 1px solid var(--kpi-border);
  color: var(--kpi-text);
  border-radius: var(--kpi-radius-sm);
}
.uk-select:focus,
.uk-input:focus,
.uk-textarea:focus {
  background: var(--kpi-card-bg-soft);
  color: var(--kpi-text);
  border-color: var(--kpi-blue);
}
.uk-select option { background: var(--kpi-card-bg); color: var(--kpi-text); }
.uk-input::placeholder,
.uk-textarea::placeholder { color: var(--kpi-text-muted); }

.uk-button {
  border-radius: var(--kpi-radius-sm);
  font-weight: 600;
  text-transform: none;
}
.uk-button-default {
  background: var(--kpi-card-bg-soft);
  color: var(--kpi-text);
  border: 1px solid var(--kpi-border-strong);
}
.uk-button-default:hover { background: var(--kpi-card-bg); color: var(--kpi-text); }
.uk-button-primary {
  background: var(--kpi-blue);
  color: #fff;
  border: 1px solid var(--kpi-blue);
}
.uk-button-primary:hover { background: var(--kpi-blue); opacity: 0.9; color: #fff; }
.uk-button-small { font-size: 12px; padding: 0 12px; line-height: 28px; }
.uk-button-danger {
  background: var(--kpi-red);
  color: #fff;
  border: 1px solid var(--kpi-red);
}
.uk-button-danger:hover { background: var(--kpi-red); opacity: 0.9; color: #fff; }
.kpi-button-approve {
  background: var(--kpi-yellow);
  color: #1a1a1a;
  border: 1px solid var(--kpi-yellow);
  border-radius: var(--kpi-radius-sm);
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  line-height: 28px;
  padding: 0 12px;
  font-size: 12px;
}
.kpi-button-approve:hover { opacity: 0.9; }

.uk-alert { border-radius: var(--kpi-radius-md); }
.uk-alert-success {
  background: var(--kpi-green-soft) !important;
  color: var(--kpi-green) !important;
}
.uk-alert-close { color: inherit; opacity: 0.7; }

.kpi-margin-box {
  background: var(--kpi-card-bg-soft);
  border: 1px solid var(--kpi-border);
  border-radius: var(--kpi-radius-md);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
}
.kpi-margin-box .kpi-stat-label { margin-top: 2px; }

/* ---------- checklist (item.php) ---------- */

.kpi-checklist-progressbar {
  height: 5px;
  border-radius: 4px;
  background: var(--kpi-card-bg-soft);
  overflow: hidden;
  margin: 10px 0 14px;
}
.kpi-checklist-progressbar-fill {
  height: 100%;
  background: var(--kpi-green);
  border-radius: 4px;
  transition: width 0.25s ease;
}
.kpi-checklist-progressbar-fill.is-over-budget { background: var(--kpi-red); }

.kpi-checklist-list { list-style: none; margin: 0; padding: 0; }

.kpi-checklist-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--kpi-radius-sm);
  transition: background 0.15s ease;
}
.kpi-checklist-row:hover { background: var(--kpi-card-bg-soft); }
.kpi-checklist-row + .kpi-checklist-row { margin-top: 1px; }

.kpi-checkbox {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.kpi-checkbox input[type="checkbox"] {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.kpi-checkbox-box {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1.5px solid var(--kpi-border-strong);
  background: var(--kpi-card-bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.kpi-checkbox input:checked + .kpi-checkbox-box {
  background: var(--kpi-green);
  border-color: var(--kpi-green);
  color: #fff;
}
.kpi-checkbox input:focus-visible + .kpi-checkbox-box {
  outline: 2px solid var(--kpi-blue);
  outline-offset: 2px;
}
.kpi-checkbox-placeholder .kpi-checkbox-box { opacity: 0.45; cursor: default; }

.kpi-checklist-text {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--kpi-text);
  cursor: text;
  word-break: break-word;
  border-radius: 4px;
}
.kpi-checklist-row.is-done .kpi-checklist-text {
  color: var(--kpi-text-muted);
  text-decoration: line-through;
}

.kpi-checklist-edit-input {
  flex: 1;
  background: var(--kpi-card-bg);
  border: 1px solid var(--kpi-blue);
  border-radius: var(--kpi-radius-sm);
  color: var(--kpi-text);
  font-size: 13.5px;
  padding: 4px 8px;
}

.kpi-checklist-row-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.kpi-checklist-row:hover .kpi-checklist-row-actions,
.kpi-checklist-row-actions:focus-within { opacity: 1; }

.kpi-checklist-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--kpi-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.kpi-checklist-action-btn:hover { background: var(--kpi-border-strong); color: var(--kpi-text); }
.kpi-checklist-delete-btn:hover { color: var(--kpi-red); }

.kpi-row-action-btn {
  width: 26px; height: 26px; border-radius: 7px; border: none;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; margin-left: 4px;
}
.kpi-row-action-btn.is-complete { background: var(--kpi-red-soft); color: var(--kpi-red); }
.kpi-row-action-btn.is-complete:hover { background: var(--kpi-red); color: #fff; }
.kpi-row-action-btn.is-approve { background: var(--kpi-yellow-soft); color: var(--kpi-yellow); }
.kpi-row-action-btn.is-approve:hover { background: var(--kpi-yellow); color: #1a1a1a; }

.kpi-checklist-empty {
  color: var(--kpi-text-muted);
  font-size: 13px;
  padding: 10px 8px;
  margin: 0;
}

.kpi-checklist-add-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  margin-top: 4px;
  border-top: 1px solid var(--kpi-border);
}
.kpi-checklist-add-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--kpi-text);
  font-size: 13.5px;
  padding: 0;
}
.kpi-checklist-add-input:focus { outline: none; }
.kpi-checklist-add-input::placeholder { color: var(--kpi-text-muted); }
.kpi-checklist-add-btn { color: var(--kpi-text-muted); opacity: 0.7; }
.kpi-checklist-add-input:not(:placeholder-shown) ~ .kpi-checklist-add-btn,
.kpi-checklist-add-btn:hover { opacity: 1; color: var(--kpi-blue); }

/* Touch screens have no hover — always show row actions, with bigger tap targets. */
@media (max-width: 900px) {
  .kpi-checklist-row-actions { opacity: 1; }
  .kpi-checklist-action-btn { width: 32px; height: 32px; }
  .kpi-checkbox { width: 24px; height: 24px; }
  .kpi-checkbox-box { width: 22px; height: 22px; }
}

/* ---------- compact checklist indicator (items table) ---------- */

.kpi-row-checklist {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 8px;
}
.kpi-row-checklist-count { font-size: 11px; color: var(--kpi-text-muted); }
.kpi-row-checklist-bar {
  display: inline-block;
  width: 32px;
  height: 4px;
  border-radius: 3px;
  background: var(--kpi-card-bg-soft);
  overflow: hidden;
}
.kpi-row-checklist-bar span { display: block; height: 100%; background: var(--kpi-green); border-radius: 3px; }

.kpi-filters-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; align-items: center; }
.kpi-filters-bar select, .kpi-filters-bar input {
  background: var(--kpi-card-bg);
  border: 1px solid var(--kpi-border);
  color: var(--kpi-text);
  border-radius: var(--kpi-radius-sm);
}
.kpi-view-toggle { display: inline-flex; border: 1px solid var(--kpi-border); border-radius: var(--kpi-radius-sm); overflow: hidden; margin-left: auto; }
.kpi-view-toggle a, .kpi-view-toggle button {
  padding: 7px 14px; font-size: 12.5px; color: var(--kpi-text-secondary); background: var(--kpi-card-bg); border: none; cursor: pointer; text-decoration: none;
}
.kpi-view-toggle a.active { background: var(--kpi-blue); color: #fff; }
.kpi-view-toggle button[disabled] { opacity: 0.4; cursor: not-allowed; }

.kpi-view-compact table.kpi-table { border-spacing: 0 4px; }
.kpi-view-compact table.kpi-table tbody td { padding: 6px 14px; font-size: 12.5px; }
.kpi-view-compact table.kpi-table .kpi-row-meta { display: none; }

/* ---------- misc ---------- */

.uk-modal-dialog {
  background: var(--kpi-card-bg);
  color: var(--kpi-text);
  border-radius: var(--kpi-radius-lg);
  border: 1px solid var(--kpi-border);
}
.uk-modal-title { color: var(--kpi-text); }
.uk-modal-body label { color: var(--kpi-text-secondary); font-size: 12.5px; }

.kpi-empty-state { text-align: center; padding: 50px 20px; color: var(--kpi-text-muted); }

.kpi-section-title {
  font-size: 13px; font-weight: 700; color: var(--kpi-text-secondary);
  text-transform: uppercase; letter-spacing: .04em; margin: 26px 0 12px;
}
.kpi-section-title:first-child { margin-top: 0; }
