/* =============================================
   NowyCRM – Main Styles
   ============================================= */
:root {
  --sidebar-w:     240px;
  --topbar-h:      56px;
  --sidebar-bg:    #1a1d23;
  --sidebar-text:  #9ca3af;
  --sidebar-hover: #2d3139;
  --sidebar-active:#0d6efd;
  --border:        #e5e7eb;
  --bg-app:        #f3f4f6;
}

/* ---- Login ---- */
.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; overflow: hidden;
}
#login-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 2.5rem;
  width: 100%; max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.5);
}

/* ---- Layout ---- */
body { overflow-x: hidden; background: var(--bg-app); }

.sidebar {
  position: fixed; top: 0; left: 0;
  height: 100vh; width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 1000;
  transition: transform .25s ease;
}
.sidebar-header {
  padding: .9rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--topbar-h);
}
.sidebar-brand { color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.sidebar-close-btn { color: rgba(255,255,255,.5); }

.sidebar-nav {
  flex: 1; overflow-y: auto; padding: .5rem 0;
  list-style: none; margin: 0;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar-nav .nav-section {
  font-size: .68rem; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: rgba(255,255,255,.3);
  padding: .9rem 1.2rem .25rem;
}
.sidebar-nav li a {
  display: flex; align-items: center; gap: .65rem;
  padding: .5rem 1.2rem; margin: 1px .5rem; border-radius: 6px;
  color: var(--sidebar-text); text-decoration: none;
  font-size: .875rem; transition: background .15s, color .15s;
}
.sidebar-nav li a i { font-size: .95rem; width: 18px; flex-shrink: 0; }
.sidebar-nav li a:hover  { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav li a.active { background: var(--sidebar-active); color: #fff; }

.sidebar-poweredby {
  padding: .4rem 1.2rem;
  display: flex; align-items: center; gap: .4rem;
  color: rgba(255,255,255,.3); font-size: .68rem; letter-spacing: .02em;
  border-top: 1px solid rgba(255,255,255,.05);
}
.sidebar-poweredby img { opacity: .45; filter: brightness(0) invert(1); }

.sidebar-footer {
  padding: .75rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: .5rem;
  color: var(--sidebar-text); font-size: .82rem; min-width: 0;
}
.sidebar-footer .btn-link { color: var(--sidebar-text); padding: 0; }
.sidebar-footer .btn-link:hover { color: #fff; }
.sidebar-footer .flex-grow-1 { min-width: 0; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 999;
}
.sidebar-overlay.show { display: block; }

.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh; display: flex; flex-direction: column;
  transition: margin-left .25s ease;
}
.topbar {
  height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1rem 0 1.25rem;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  gap: .75rem;
}
.topbar-right { flex-shrink: 0; }
.page-content { flex: 1; padding: 1.25rem; }

@media (max-width: 991px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
}

/* ---- Page header ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.1rem; flex-wrap: wrap; gap: .5rem;
}
.page-header h4 { margin: 0; font-weight: 700; font-size: 1.15rem; }

/* ---- Cards ---- */
.card { border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.05); }
.card-header { background: #fff; border-bottom: 1px solid var(--border); font-weight: 600; padding: .85rem 1.1rem; }

.stat-card { border: none; border-radius: 12px; }
.stat-icon {
  width: 48px; height: 48px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}

/* ---- Tables ---- */
.table-responsive { border-radius: 8px; }
.table th {
  background: #f9fafb; font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: #6b7280;
  border-bottom: 2px solid var(--border); white-space: nowrap;
  padding: .6rem .75rem;
}
.table td { vertical-align: middle; font-size: .875rem; padding: .6rem .75rem; }
.table-hover tbody tr:hover { background: #f0f6ff; }

/* ---- Filters bar ---- */
.filters-bar {
  background: #fff; border-radius: 8px;
  padding: .65rem .9rem; margin-bottom: 1rem;
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  border: 1px solid var(--border);
}
.filters-bar .form-control,
.filters-bar .form-select { font-size: .82rem; height: 32px; padding: .25rem .6rem; }
.filters-bar .btn { font-size: .82rem; padding: .25rem .7rem; height: 32px; }

/* ---- Pagination bar ---- */
.pagination-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: .9rem; font-size: .82rem; color: #6b7280; flex-wrap: wrap; gap: .5rem;
}

/* ---- Form sections ---- */
.form-section {
  background: #fff; border-radius: 10px; padding: 1.1rem;
  margin-bottom: .9rem; border: 1px solid var(--border);
}
.form-section-title {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: #6b7280;
  margin-bottom: .85rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.form-label { font-size: .83rem; font-weight: 600; margin-bottom: .25rem; }
.form-control, .form-select { font-size: .875rem; }

/* ---- Invoice items table ---- */
.items-editor { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.items-editor table { margin: 0; }
.items-editor thead th { padding: .45rem .5rem; }
.items-editor td { padding: .3rem .4rem; }
.items-editor input, .items-editor select {
  border: none; background: transparent; width: 100%;
  padding: .3rem .4rem; font-size: .82rem;
}
.items-editor input:focus, .items-editor select:focus {
  outline: 2px solid #0d6efd; border-radius: 3px; background: #fff;
}
.items-editor tfoot td { background: #f9fafb; font-weight: 600; font-size: .82rem; }
.items-editor .btn-remove-row { color: #ef4444; padding: 0 4px; font-size: 1rem; }

/* =============================================
   Calendar — Professional Rebuild
   ============================================= */

/* Toolbar */
.cal-toolbar {
  display: flex; align-items: center; gap: .35rem; flex-wrap: wrap;
}

/* ── Day-of-week header row ── */
.cal-dow-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: #f8faff; border-bottom: 1px solid var(--border);
}
.cal-dow-cell {
  text-align: center; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: #6b7280; padding: .45rem 0;
}
.cal-dow-cell.cal-sat { color: #3b82f6; }
.cal-dow-cell.cal-sun { color: #ef4444; }

/* ── Month grid ── */
.cal-month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 0;
}
.cal-month-cell {
  min-height: 110px; padding: .35rem .4rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
  background: #fff; overflow: hidden;
}
.cal-month-cell:nth-child(7n) { border-right: none; }
.cal-month-grid .cal-month-cell:nth-last-child(-n+7) { border-bottom: none; }
.cal-month-cell:hover { background: #f5f8ff; }
.cal-month-cell.is-other-month { background: #fafafa; }
.cal-month-cell.is-other-month .cal-cell-day-num { color: #c9d0d9; }
.cal-month-cell.is-today { background: #eff6ff; }

/* Day number */
.cal-cell-day-num {
  font-size: .78rem; font-weight: 600; color: #374151;
  line-height: 1; margin-bottom: .3rem; display: inline-block;
}

/* Today circle */
.today-circle {
  width: 22px; height: 22px; border-radius: 50%;
  background: #0d6efd; color: #fff !important;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700;
}
.today-circle-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: #0d6efd; color: #fff !important;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* Weekend tinting */
.cal-month-cell[data-dow="5"] { background: #fdfcff; }
.cal-month-cell[data-dow="6"] { background: #fff9f9; }
.cal-month-cell[data-dow="5"]:hover { background: #f3f0ff; }
.cal-month-cell[data-dow="6"]:hover { background: #fff0f0; }

/* Event list in month cell */
.cal-ev-list { display: flex; flex-direction: column; gap: 2px; }

/* Event bar */
.cal-ev-bar {
  font-size: .68rem; padding: 2px 5px; border-radius: 4px;
  color: #fff; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; cursor: pointer;
  transition: filter .12s, opacity .12s;
  user-select: none;
}
.cal-ev-bar:hover { filter: brightness(1.1); }
.cal-ev-bar.ev-done { opacity: .5; text-decoration: line-through; }
.cal-ev-bar.dragging { opacity: .35; }
.cal-ev-bar.dragging-ghost { outline: 2px dashed rgba(255,255,255,.5); }

.cal-ev-time { font-size: .62rem; opacity: .85; margin-right: 2px; }

/* "+N więcej" link */
.cal-more-btn {
  font-size: .65rem; color: #0d6efd; cursor: pointer;
  padding: 1px 4px; border-radius: 3px;
  white-space: nowrap;
}
.cal-more-btn:hover { background: #dbeafe; }

/* Drag-over highlight */
.cal-month-cell.drag-over,
.cal-week-slot.drag-over {
  outline: 2px solid #0d6efd;
  background: #eff6ff !important;
}

/* ── Popover ("+" more events) ── */
.cal-popover {
  z-index: 9990; background: #fff;
  border: 1px solid var(--border); border-radius: 10px;
  padding: .75rem; min-width: 220px; max-width: 280px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15);
}
.cal-pop-ev {
  padding: .35rem .5rem; border-radius: 6px;
  cursor: pointer; margin-bottom: 4px;
  transition: background .1s;
}
.cal-pop-ev:hover { background: #f0f6ff; }

/* ── Week view ── */
.cal-week-scroll {
  overflow-y: auto;
  max-height: calc(100vh - 260px);
}
.cal-week-header {
  display: grid; grid-template-columns: 44px repeat(7, 1fr);
  border-bottom: 2px solid var(--border);
  background: #f8faff;
  position: sticky; top: 0; z-index: 10;
}
.cal-week-time-pad { /* left spacer */ }
.cal-week-day-hdr {
  text-align: center; padding: .5rem .25rem;
  border-left: 1px solid var(--border);
  cursor: default;
}
.cal-week-day-hdr.is-today { background: #eff6ff; }
.cal-week-day-hdr.cal-sat { color: #3b82f6; }
.cal-week-day-hdr.cal-sun { color: #ef4444; }

/* All-day row */
.cal-week-allday-row {
  display: grid; grid-template-columns: 44px repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  min-height: 32px;
  position: sticky; top: var(--cal-hdr-h, 57px); z-index: 9;
  background: #fff;
}
.cal-week-allday-cell {
  border-left: 1px solid var(--border);
  padding: 2px 3px;
}

/* Time grid */
.cal-week-row {
  display: grid; grid-template-columns: 44px repeat(7, 1fr);
  height: 60px; /* 1 hour = 60px */
  border-bottom: 1px solid #f0f0f0;
}
.cal-week-row:hover { background: rgba(0,0,0,.01); }
.cal-time-label {
  font-size: .65rem; color: #9ca3af;
  text-align: right; padding: 3px 6px 0 0;
  white-space: nowrap; flex-shrink: 0;
  line-height: 1;
}
.cal-week-slot {
  border-left: 1px solid #f0f0f0;
  height: 60px; position: relative;
  cursor: pointer; transition: background .1s;
}
.cal-week-slot:hover { background: #f5f8ff; }

/* Positioned timed event in week */
.cal-week-event {
  position: absolute; left: 2px; right: 2px;
  border-radius: 4px; overflow: hidden;
  color: #fff; font-size: .72rem; padding: 2px 5px;
  cursor: pointer; z-index: 2;
  transition: filter .12s;
  white-space: nowrap; text-overflow: ellipsis;
  min-height: 20px;
}
.cal-week-event:hover { filter: brightness(1.1); }

/* ── Side panel (day events) ── */
.side-event-item {
  display: flex; align-items: stretch; gap: 0;
  padding: .55rem .75rem;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer; transition: background .1s;
}
.side-event-item:hover { background: #f8faff; }
.side-event-item:last-child { border-bottom: none; }

.side-ev-stripe {
  width: 3px; border-radius: 2px;
  flex-shrink: 0; margin-right: .6rem;
  align-self: stretch;
}
.side-ev-body { flex: 1; min-width: 0; }
.side-ev-title {
  font-size: .82rem; font-weight: 600; color: #111827;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-ev-meta {
  font-size: .72rem; color: #6b7280; margin-top: 1px;
  display: flex; gap: .4rem; flex-wrap: wrap;
}
.side-ev-actions {
  flex-shrink: 0; display: flex; align-items: center;
  gap: 0; margin-left: .4rem;
}

/* ── Upcoming panel ── */
.upcoming-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .75rem;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer; transition: background .1s;
}
.upcoming-item:hover { background: #f8faff; }
.upcoming-item:last-child { border-bottom: none; }
.upcoming-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}

/* ── Event form: color dots ── */
.color-dot {
  width: 20px; height: 20px; border-radius: 50%;
  cursor: pointer; flex-shrink: 0;
  border: 2px solid transparent;
  transition: transform .15s, border-color .15s;
}
.color-dot:hover { transform: scale(1.2); }
.color-dot.active {
  border-color: #1e293b;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #1e293b;
}
.color-picker-input {
  width: 28px; height: 28px; border: 1px solid #d1d5db;
  border-radius: 6px; padding: 1px; cursor: pointer;
  background: none;
}

/* =============================================
   Global Search / Command Palette
   ============================================= */

/* Topbar search trigger */
.search-trigger-btn {
  display: flex; align-items: center; gap: .4rem;
  background: #f3f4f6; border: 1px solid #e5e7eb;
  border-radius: 8px; padding: .3rem .75rem;
  cursor: pointer; font-size: .83rem; color: #6b7280;
  flex-grow: 1; max-width: 360px;
  transition: border-color .15s, box-shadow .15s;
}
.search-trigger-btn:hover {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13,110,253,.1);
}
.search-trigger-btn kbd {
  margin-left: auto; font-size: .7rem;
  background: #e5e7eb; color: #9ca3af;
  border-radius: 4px; padding: 1px 5px;
  border: 1px solid #d1d5db;
}

/* Overlay backdrop */
.search-overlay {
  position: fixed; inset: 0; z-index: 99998;
  background: rgba(15,23,42,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 10vh;
  backdrop-filter: blur(4px);
  animation: searchFadeIn .15s ease;
}
@keyframes searchFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Dialog box */
.search-dialog {
  width: 100%; max-width: 640px;
  background: #fff; border-radius: 14px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
  overflow: hidden;
  animation: searchSlideIn .15s ease;
}
@keyframes searchSlideIn {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

/* Input row */
.search-input-wrap {
  display: flex; align-items: center; gap: .75rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid #f3f4f6;
}
.search-icon { color: #9ca3af; font-size: 1rem; flex-shrink: 0; }
.search-input {
  flex: 1; border: none; outline: none;
  font-size: 1.05rem; color: #111827;
  background: transparent;
}
.search-esc-hint {
  font-size: .7rem; background: #f3f4f6; color: #9ca3af;
  border-radius: 5px; padding: 2px 6px;
  border: 1px solid #e5e7eb; flex-shrink: 0;
}

/* Results list */
.search-results {
  max-height: 460px; overflow-y: auto;
}

.search-group-label {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: #9ca3af;
  padding: .6rem 1rem .2rem;
}

.search-result-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem 1rem; cursor: pointer;
  transition: background .1s;
}
.search-result-item:hover,
.search-result-item.active { background: #f0f6ff; }

.search-res-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: #eff6ff; display: flex; align-items: center; justify-content: center;
  font-size: .85rem; color: #3b82f6; flex-shrink: 0;
}
.search-res-body { flex: 1; min-width: 0; }
.search-res-label { font-size: .88rem; font-weight: 600; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-res-sub   { font-size: .72rem; color: #9ca3af; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-res-type  { font-size: .68rem; color: #c4c9d4; white-space: nowrap; flex-shrink: 0; }

/* Empty state */
.search-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: .5rem; padding: 2rem;
  font-size: .85rem; color: #9ca3af; text-align: center;
}
.search-empty i { font-size: 2rem; }
.search-hints {
  display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; margin-top: .25rem;
}
.search-hints span {
  background: #f3f4f6; border-radius: 20px;
  padding: .2rem .65rem; font-size: .72rem;
}
.search-hints i { margin-right: .25rem; color: #6b7280; }

/* Footer */
.search-footer {
  display: flex; gap: 1.2rem; padding: .5rem 1rem;
  border-top: 1px solid #f3f4f6;
  font-size: .72rem; color: #9ca3af;
}
.search-footer kbd {
  background: #f3f4f6; color: #6b7280;
  border-radius: 4px; padding: 1px 5px;
  border: 1px solid #e5e7eb; font-size: .68rem; margin-right: 3px;
}

/* =============================================
   Topbar search + notification upgrades
   ============================================= */

/* Notification bell */
.notif-badge {
  position: absolute; top: 1px; right: 1px;
  background: #ef4444; color: #fff;
  font-size: .58rem; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px; line-height: 1;
}

.notif-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 320px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.15);
  z-index: 1050; overflow: hidden;
}

.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
}
.notif-link { font-size: .8rem; color: #0d6efd; text-decoration: none; }
.notif-link:hover { text-decoration: underline; }

.notif-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .9rem; cursor: pointer;
  border-bottom: 1px solid #f8f9fa;
  transition: background .1s;
}
.notif-item:hover { background: #f0f6ff; }
.notif-item:last-child { border-bottom: none; }

.notif-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-meta  { font-size: .7rem; color: #9ca3af; }
.notif-today-badge { background: #dbeafe; color: #1d4ed8; font-size: .65rem; font-weight: 700; border-radius: 4px; padding: 1px 5px; }
.notif-empty { padding: 1rem; text-align: center; color: #9ca3af; font-size: .82rem; }
.notif-section-header { padding: .35rem .85rem; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #6b7280; background: #f8fafc; border-top: 1px solid #f1f5f9; border-bottom: 1px solid #f1f5f9; }
.notif-item-danger { background: #fff8f8; }
.notif-item-danger:hover { background: #fee2e2; }
.notif-item-warn { background: #fffbeb; }
.notif-item-warn:hover { background: #fef3c7; }
.notif-more { padding: .35rem .85rem; font-size: .75rem; color: #3b82f6; cursor: pointer; text-align: center; border-top: 1px solid #f1f5f9; }
.notif-more:hover { background: #eff6ff; }

/* =============================================
   Dashboard — KPI + widgets
   ============================================= */

.dash-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .75rem;
}
@media (max-width: 1399px) { .dash-kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 767px)  { .dash-kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.dash-kpi-card {
  border-radius: 12px; padding: .9rem 1rem;
  display: flex; align-items: center; gap: .75rem;
  border: 1px solid rgba(0,0,0,.06);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  background: #fff;
}

.dash-kpi-icon {
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
}

.dash-kpi-blue   .dash-kpi-icon { background: #dbeafe; color: #1d4ed8; }
.dash-kpi-green  .dash-kpi-icon { background: #d1fae5; color: #065f46; }
.dash-kpi-orange .dash-kpi-icon { background: #ffedd5; color: #c2410c; }
.dash-kpi-red    .dash-kpi-icon { background: #fee2e2; color: #991b1b; }
.dash-kpi-purple .dash-kpi-icon { background: #ede9fe; color: #5b21b6; }
.dash-kpi-teal   .dash-kpi-icon { background: #ccfbf1; color: #0f766e; }

.dash-kpi-value  { font-size: 1.2rem; font-weight: 800; color: #111827; line-height: 1.15; }
.dash-kpi-label  { font-size: .72rem; color: #6b7280; font-weight: 500; }
.dash-kpi-sub    { font-size: .68rem; color: #9ca3af; margin-top: 1px; min-height: 14px; }
.dash-trend      { font-size: .72rem; font-weight: 700; display: inline-flex; align-items: center; }

/* Bootstrap extension — orange */
.bg-orange   { background-color: #f97316 !important; color: #fff; }
.text-orange { color: #f97316 !important; }

/* Analysis KPI row — horizontal flex of dash-kpi-card items */
.an-kpi-row {
  display: flex; gap: .75rem; flex-wrap: wrap;
}
.an-kpi-row .dash-kpi-card {
  flex: 1 1 180px; min-width: 160px;
}

/* Dashboard event items */
.dash-event-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .85rem;
  border-bottom: 1px solid #f3f4f6;
}
.dash-event-item:last-child { border-bottom: none; }
.dash-event-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Dashboard top clients */
.dash-top-client {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .85rem;
  border-bottom: 1px solid #f3f4f6;
}
.dash-top-client:last-child { border-bottom: none; }
.dash-top-rank {
  width: 20px; height: 20px; border-radius: 50%;
  background: #f3f4f6; color: #6b7280;
  font-size: .65rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Misc helpers */
.letter-spacing { letter-spacing: .05em; }
.min-width-0    { min-width: 0; }

/* ---- Badges ---- */
.badge-paid   { background: #d1fae5; color: #065f46; }
.badge-unpaid { background: #fee2e2; color: #991b1b; }
.badge-draft  { background: #f3f4f6; color: #374151; }
.badge-ksef-sent { background: #dbeafe; color: #1e40af; }
.badge-ksef-none { background: #f3f4f6; color: #6b7280; }

/* ---- Typeahead dropdown ---- */
.typeahead-dropdown {
  position: absolute; z-index: 1050; background: #fff;
  border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  max-height: 200px; overflow-y: auto; min-width: 220px;
}
.typeahead-dropdown .td-item {
  padding: .4rem .75rem; cursor: pointer; font-size: .85rem;
}
.typeahead-dropdown .td-item:hover { background: #f0f6ff; }
.typeahead-wrap { position: relative; }

/* ---- Loading / Empty ---- */
.loading-spinner { display: flex; justify-content: center; align-items: center; padding: 3rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: #9ca3af; }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .75rem; }

/* ---- Misc ---- */
.text-money-pos { color: #059669; font-weight: 600; }
.text-money-neg { color: #dc2626; font-weight: 600; }
.cursor-pointer { cursor: pointer; }
.table-actions { white-space: nowrap; }
.table-actions .btn { padding: .2rem .45rem; font-size: .78rem; }

/* =============================================
   Invoice Module – Enterprise styles
   ============================================= */

/* KPI bar */
.inv-kpi-bar { display: grid; grid-template-columns: repeat(4,1fr); gap: .75rem; margin-bottom: 1.1rem; }
@media (max-width: 991px) { .inv-kpi-bar { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 575px)  { .inv-kpi-bar { grid-template-columns: 1fr 1fr; } }

.inv-kpi-card {
  background: #fff; border-radius: 12px; padding: .9rem 1.1rem;
  border: 1px solid var(--border); display: flex; align-items: center; gap: .85rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.inv-kpi-icon {
  width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.inv-kpi-icon.blue   { background: #dbeafe; color: #1d4ed8; }
.inv-kpi-icon.green  { background: #d1fae5; color: #065f46; }
.inv-kpi-icon.orange { background: #ffedd5; color: #c2410c; }
.inv-kpi-icon.red    { background: #fee2e2; color: #991b1b; }
.inv-kpi-val  { font-size: 1.35rem; font-weight: 700; line-height: 1.1; color: #111827; }
.inv-kpi-label{ font-size: .73rem; color: #6b7280; margin-top: 1px; }
.inv-kpi-sub  { font-size: .7rem; color: #9ca3af; margin-top: 2px; }

/* Row status tinting */
tr.inv-row-overdue   { background: #fff5f5 !important; }
tr.inv-row-due-soon  { background: #fffbeb !important; }
tr.inv-row-paid      { opacity: .82; }
tr.inv-row-overdue:hover  { background: #fee2e2 !important; }
tr.inv-row-due-soon:hover { background: #fef3c7 !important; }

/* Smart status badges */
.inv-status {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .22rem .55rem; border-radius: 20px;
  font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.inv-status.paid      { background: #d1fae5; color: #065f46; }
.inv-status.pending   { background: #dbeafe; color: #1e3a8a; }
.inv-status.due-soon  { background: #ffedd5; color: #9a3412; }
.inv-status.overdue   { background: #fee2e2; color: #991b1b; }
.inv-status.today     { background: #fef9c3; color: #713f12; }

/* Form: items editor enterprise */
.inv-items-table { font-size: .82rem; }
.inv-items-table thead th { font-size: .7rem; padding: .45rem .5rem; }
.inv-items-table td { padding: .25rem .35rem; vertical-align: middle; }
.inv-items-table input, .inv-items-table select {
  border: 1px solid transparent; border-radius: 4px; padding: .25rem .4rem;
  font-size: .82rem; width: 100%; background: transparent; transition: border-color .15s;
}
.inv-items-table input:hover, .inv-items-table select:hover { border-color: #d1d5db; }
.inv-items-table input:focus, .inv-items-table select:focus {
  border-color: #0d6efd; outline: none; background: #fff; box-shadow: 0 0 0 2px rgba(13,110,253,.15);
}
.inv-items-table .cell-readonly { background: #f9fafb !important; color: #374151; }
.inv-items-table tr.item-row:hover td { background: #f8faff; }
.inv-lp-cell { text-align: center; color: #9ca3af; font-size: .75rem; width: 30px; }

/* Form: deadline badge */
.deadline-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  background: #f0f9ff; border: 1px solid #bae6fd;
  border-radius: 6px; padding: .2rem .55rem;
  font-size: .78rem; color: #0369a1; margin-top: .3rem;
}

/* Form: client info panel */
.client-info-panel {
  background: #f8faff; border: 1px solid #bfdbfe; border-radius: 8px;
  padding: .65rem .9rem; font-size: .8rem; color: #374151;
  margin-top: .4rem;
}
.client-info-panel strong { color: #1e40af; }

/* Detail: status banner */
.inv-detail-banner {
  border-radius: 10px; padding: .75rem 1.1rem;
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 1.25rem; font-size: .9rem;
}
.inv-detail-banner.paid     { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.inv-detail-banner.pending  { background: #dbeafe; color: #1e3a8a; border: 1px solid #93c5fd; }
.inv-detail-banner.overdue  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.inv-detail-banner.due-soon { background: #ffedd5; color: #9a3412; border: 1px solid #fdba74; }

/* VAT summary table in form */
.vat-summary-wrap { background: #f9fafb; border-radius: 8px; padding: .75rem; }
.vat-summary-wrap table { margin: 0; }
.vat-summary-wrap td, .vat-summary-wrap th { font-size: .78rem; padding: .25rem .5rem; }

/* Total big */
.inv-total-big { font-size: 1.6rem; font-weight: 800; color: #1d4ed8; }
.inv-total-netto { font-size: .85rem; color: #6b7280; }

/* ── Admin Companies ────────────────────────────────── */
.company-card { transition: box-shadow .15s; border-radius: 12px; }
.company-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.1); }
.company-icon { width: 52px; height: 52px; background: #eff6ff; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-mini { background: #f8fafc; border-radius: 8px; padding: 8px 10px; text-align: center; }
.stat-mini-value { font-size: 1.3rem; font-weight: 700; color: #1e40af; }
.stat-mini-label { font-size: .7rem; text-transform: uppercase; color: #6b7280; letter-spacing: .05em; }
.btn-xs { padding: .15rem .4rem; font-size: .75rem; }

/* Impersonation banner */
#impersonate-banner { display: flex !important; }
#impersonate-banner.d-none { display: none !important; }

/* ---- Custom Tooltip ---- */
#crm-tooltip {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  max-width: 260px;
  padding: .45rem .8rem;
  background: #1e2330;
  color: #f1f5f9;
  font-size: .8rem;
  font-weight: 400;
  line-height: 1.55;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  white-space: pre-line;
  word-break: break-word;
  opacity: 0;
  transition: opacity .16s ease;
}
#crm-tooltip.tt-visible { opacity: 1; }
#crm-tooltip::before {
  content: '';
  position: absolute;
  left: var(--tt-arrow-left, 50%);
  transform: translateX(-50%);
  border: 6px solid transparent;
}
#crm-tooltip.tt-above::before {
  top: 100%;
  border-top-color: #1e2330;
}
#crm-tooltip.tt-below::before {
  bottom: 100%;
  border-bottom-color: #1e2330;
}

/* ---- Refresh button spin ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin .6s linear; }

/* =============================================
   Dark mode
   ============================================= */
[data-theme="dark"] {
  --bg-app: #0f172a;
  --border: #1e293b;
}
[data-theme="dark"] body { background: #0f172a; color: #e2e8f0; }
[data-theme="dark"] .card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .card-header { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .topbar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .main-wrapper { background: #0f172a; }
[data-theme="dark"] .table { color: #e2e8f0; }
[data-theme="dark"] .table th { background: #1e293b; color: #94a3b8; border-color: #334155; }
[data-theme="dark"] .table td { border-color: #1e293b; }
[data-theme="dark"] .table-hover tbody tr:hover { background: #1e3a5f; }
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .form-control::placeholder { color: #64748b; }
[data-theme="dark"] .filters-bar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .search-trigger-btn { background: #1e293b; border-color: #334155; color: #94a3b8; }
[data-theme="dark"] .modal-content { background: #1e293b; color: #e2e8f0; }
[data-theme="dark"] .modal-header { border-color: #334155; }
[data-theme="dark"] .modal-footer { border-color: #334155; }
[data-theme="dark"] .form-section { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .page-content { background: #0f172a; }
[data-theme="dark"] .inv-kpi-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .dash-kpi-card { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .typeahead-dropdown { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .typeahead-dropdown .td-item:hover { background: #1e3a5f; }
[data-theme="dark"] .stat-card { background: #1e293b !important; color: #e2e8f0; }
[data-theme="dark"] .login-card { background: #1e293b; color: #e2e8f0; }
[data-theme="dark"] .dropdown-menu { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .dropdown-item { color: #e2e8f0; }
[data-theme="dark"] .dropdown-item:hover { background: #334155; color: #fff; }
[data-theme="dark"] .dropdown-header { color: #94a3b8; }
[data-theme="dark"] .dropdown-divider { border-color: #334155; }
[data-theme="dark"] .text-muted { color: #94a3b8 !important; }
[data-theme="dark"] .border { border-color: #334155 !important; }
[data-theme="dark"] .border-bottom { border-color: #334155 !important; }
[data-theme="dark"] .input-group-text { background: #334155; border-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .btn-outline-secondary { border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .btn-outline-secondary:hover { background: #334155; border-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .btn-link { color: #94a3b8; }
[data-theme="dark"] .table-hover tbody tr.inv-row-overdue { background: #3b1010 !important; }
[data-theme="dark"] .table-hover tbody tr.inv-row-overdue:hover { background: #4a1a1a !important; }
[data-theme="dark"] .table-hover tbody tr.inv-row-due-soon { background: #2d2000 !important; }
[data-theme="dark"] .table-hover tbody tr.inv-row-due-soon:hover { background: #3a2a00 !important; }
[data-theme="dark"] .pagination-bar { color: #94a3b8; }
[data-theme="dark"] .notif-dropdown { background: #1e293b; border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .notif-header { border-color: #334155; }
[data-theme="dark"] .notif-item:hover { background: #1e3a5f; }
[data-theme="dark"] .search-dialog { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .search-input { background: transparent; color: #e2e8f0; }
[data-theme="dark"] .search-input::placeholder { color: #64748b; }
[data-theme="dark"] .search-input-wrap { border-color: #334155; }
[data-theme="dark"] .search-group-label { color: #64748b; }
[data-theme="dark"] .search-result-item:hover,
[data-theme="dark"] .search-result-item.active { background: #1e3a5f; }
[data-theme="dark"] .search-footer { border-color: #334155; color: #64748b; }
[data-theme="dark"] kbd { background: #334155; color: #e2e8f0; border-color: #475569; }
[data-theme="dark"] .cal-month-cell { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .cal-month-cell:hover { background: #243447; }
[data-theme="dark"] .cal-month-cell.is-today { background: #1e3a5f; }
[data-theme="dark"] .cal-month-cell.is-other-month { background: #161f2e; }
[data-theme="dark"] .cal-dow-row { background: #161f2e; border-color: #334155; }
[data-theme="dark"] .cal-dow-cell { color: #64748b; }
[data-theme="dark"] .cal-popover { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .cal-pop-ev:hover { background: #243447; }
[data-theme="dark"] .items-editor { border-color: #334155; }
[data-theme="dark"] .items-editor tfoot td { background: #161f2e; }
[data-theme="dark"] .form-section-title { color: #94a3b8; border-color: #334155; }
[data-theme="dark"] .vat-summary-wrap { background: #161f2e; }
[data-theme="dark"] .client-info-panel { background: #162032; border-color: #1e3a5f; color: #94a3b8; }
[data-theme="dark"] .badge.bg-light { background: #334155 !important; color: #e2e8f0 !important; }
[data-theme="dark"] .alert-danger { background: #3b1010; border-color: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .alert-warning { background: #2d2000; border-color: #78350f; color: #fcd34d; }
[data-theme="dark"] .alert-success { background: #052e16; border-color: #14532d; color: #86efac; }
[data-theme="dark"] .alert-info { background: #0c1a2e; border-color: #1e3a5f; color: #7dd3fc; }

/* ── Pipeline / Kanban ──────────────────────────────── */
.kanban-col { user-select: none; }
.kanban-card { border-radius: 8px; border: 1px solid #e2e8f0; transition: box-shadow .15s, transform .1s; }
.kanban-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.kanban-card[draggable="true"] { cursor: grab; }
.kanban-card[draggable="true"]:active { cursor: grabbing; }
.kanban-drop-zone.drag-over { background: rgba(99,102,241,.08) !important; border: 2px dashed #6366f1; border-radius: 6px; }
[data-theme="dark"] .kanban-card { background: #1e2330; border-color: #334155; }
[data-theme="dark"] .kanban-col .card { background: #131825; border-color: #1e2a3a; }

/* ── Bulk actions bar ───────────────────────────────── */
.bulk-bar {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  animation: slideDown .15s ease;
}
[data-theme="dark"] .bulk-bar { background: #1e3a5f; border-color: #2563eb; color: #e2e8f0; }
@keyframes slideDown { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }

/* ── Activity Timeline ──────────────────────────────── */
.timeline { padding: .5rem 0; }
.timeline-item { display: flex; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid #f1f5f9; }
.timeline-item:last-child { border-bottom: none; }
.timeline-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: .9rem; }
.timeline-body { flex: 1; min-width: 0; }
[data-theme="dark"] .timeline-item { border-color: #1e2a3a; }
