/* ============================================================
   NIKNEL CRM — Light Theme
   Font: Figtree (Google Fonts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@300;400;500;600;700&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:           #F0F4F8;
  --surface:      #FFFFFF;
  --surface-2:    #F8FAFC;
  --border:       #E2E8F0;
  --border-focus: #3B82F6;

  --text:         #0F172A;
  --text-2:       #475569;
  --text-3:       #94A3B8;
  --text-inv:     #FFFFFF;

  --primary:      #2563EB;
  --primary-h:    #1D4ED8;
  --primary-light:#EFF6FF;

  --success:      #10B981;
  --success-light:#ECFDF5;
  --success-glow: rgba(16,185,129,.28);
  --warning:      #F59E0B;
  --warning-light:#FFFBEB;
  --warning-glow: rgba(245,158,11,.28);
  --danger:       #EF4444;
  --danger-light: #FEF2F2;
  --danger-glow:  rgba(239,68,68,.28);
  --info:         #6366F1;
  --info-light:   #EEF2FF;

  --sidebar-w:    240px;
  --topbar-h:     60px;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:       0 4px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-lg:    0 10px 30px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.06);

  --transition:   0.18s ease;
  --font:         'Figtree', system-ui, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-h); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Layout ─────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow: hidden;                 /* zīmols un lietotāja kartiņa fiksēti — ritinās tikai nav */
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand .brand-logo {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.5px;
}
.sidebar-brand .brand-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.3px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
  min-height: 0;                    /* lai flex-bērns drīkst sarukt un ritināties */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  /* Diskrēts, pats paslēpjas — parādās tikai virzot peli virsū */
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.sidebar-nav:hover { scrollbar-color: var(--border) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 7px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
  transition: background-color .2s;
}
.sidebar-nav:hover::-webkit-scrollbar-thumb { background: var(--border); background-clip: content-box; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

.nav-section {
  padding: 0 12px;
  margin-bottom: 4px;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 10px 8px 4px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-item svg { transition: transform .18s ease; }
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-item:hover svg { transform: translateX(2px); }
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
/* Plūstoša aktīvā indikatora josla kreisajā malā */
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.sidebar-user:hover { background: var(--surface-2); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--text-3);
  text-transform: capitalize;
}

/* ── Main ──────────────────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Content ─────────────────────────────────────────────────── */
.content {
  padding: 24px;
  flex: 1;
}
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}
.content-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 20px; }

/* ── Stat cards ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-sub {
  font-size: 12px;
  color: var(--text-3);
}
.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  align-self: flex-end;
  margin-top: auto;
}

/* Kvalitātes luksafors — lēna, mīksta mirgošana statusa krāsā (Dashboard) */
@keyframes quality-blink {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50%      { box-shadow: 0 0 16px 3px currentColor; opacity: .5; }
}
.quality-pulse {
  animation: quality-blink 3s ease-in-out infinite;
}

/* Visas kartītes fons mirgo statusa krāsā — spēcīgāka, pamanāmāka versija.
   --q-glow jānorāda uz elementa (piem. style="--q-glow:var(--danger-glow)"). */
@keyframes quality-blink-card {
  0%, 100%   { background-color: var(--surface); box-shadow: var(--shadow-sm); }
  50%        { background-color: var(--q-glow, var(--surface)); box-shadow: 0 0 32px 6px var(--q-glow, transparent); }
}
.quality-pulse-card {
  animation: quality-blink-card 3s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .quality-pulse,
  .quality-pulse-card { animation: none; }
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }

.btn-primary   { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }

.btn-danger    { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #DC2626; }

.btn-success   { background: var(--success); color: white; }
.btn-ghost     { background: transparent; color: var(--text-2); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { padding: 8px; }
.btn-icon.btn-sm { padding: 6px; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-full   { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.form-control::placeholder { color: var(--text-3); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }

.input-group {
  display: flex;
}
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-left: none; }

.form-hint { font-size: 12px; color: var(--text-3); }
.form-error { font-size: 12px; color: var(--danger); }

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* Тип клиента переключатель */
.type-switch {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
}
.type-switch label {
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
  border-right: 1px solid var(--border);
}
.type-switch label:last-child { border-right: none; }
.type-switch input[type=radio] { display: none; }
.type-switch input[type=radio]:checked + label {
  background: var(--primary);
  color: white;
}

/* ── Table ──────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
thead th {
  background: var(--surface-2);
  padding: 11px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th a {
  color: var(--text-3);
  display: inline-flex; align-items: center; gap: 4px;
}
thead th a:hover { color: var(--text-2); }
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td {
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text);
  vertical-align: middle;
}
td .td-sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.td-actions { display: flex; align-items: center; gap: 4px; }

/* ── Badge ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: color-mix(in srgb, var(--badge-color) 12%, white);
  color: var(--badge-color);
  white-space: nowrap;
}

/* ── Search & Filter bar ─────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 380px;
}
.search-input-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input-wrap .form-control { padding-left: 34px; }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
  gap: 12px;
  flex-wrap: wrap;
}
.pagination-info { font-size: 13px; color: var(--text-3); }
.pagination-pages { display: flex; gap: 4px; }
.page-btn {
  min-width: 32px; height: 32px;
  padding: 0 6px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  background: none;
}
.page-btn:hover { background: var(--surface-2); border-color: var(--border); }
.page-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.page-btn:disabled { opacity: .4; cursor: default; }

/* ── Alert / Flash ──────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-light); color: #065F46; }
.alert-danger   { background: var(--danger-light);  color: #991B1B; }
.alert-warning  { background: var(--warning-light); color: #92400E; }
.alert-info     { background: var(--info-light);    color: #3730A3; }

/* ── Tabs ────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  gap: 0;
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-3);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Detail page ─────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  align-items: start; /* важно для sticky */
}
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.info-list { display: flex; flex-direction: column; gap: 0; }
.info-row {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row dt {
  width: 160px;
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text-3);
  font-size: 13px;
}
.info-row dd { flex: 1; color: var(--text); }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
}
.empty-state svg {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  opacity: .4;
}
.empty-state p { font-size: 15px; color: var(--text-2); margin-bottom: 16px; }

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  z-index: 200;
  padding: 6px 0;
  display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--transition);
}
.dropdown-item:hover { background: var(--surface-2); color: var(--text); }
.dropdown-item svg { width: 15px; height: 15px; }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 500;
  display: none;
  place-items: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: grid; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  margin: 16px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modal-in .18s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none;
  cursor: pointer; padding: 4px;
  color: var(--text-3); border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
/* Ja modal-body/modal-footer ir ietverti <form> iekšā (biežs paraugs šajā
   projektā) — pašai <form> jāpiedalās .modal flex-izkārtojumā, citādi tā
   neierobežojas augstumā un modal-body iekšējais scroll nestrādā, saturs
   vienkārši izstiepjas ārpus ekrāna (piem. "Pievienot iekārtu" ar daudziem
   laukiem — poga "Saglabāt" paliek ārpus redzamās daļas). */
.modal > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ── Notification bell ──────────────────────────────────────── */
.notif-btn {
  position: relative;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  cursor: pointer;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all var(--transition);
}
.notif-btn:hover { background: var(--surface-2); color: var(--text); }
.notif-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid white;
}

/* ── Login page ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.login-logo .brand-logo {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: white;
  font-weight: 800;
  font-size: 16px;
}
.login-logo .brand-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}
.login-sub {
  font-size: 14px;
  color: var(--text-3);
  margin-bottom: 28px;
}

/* ── Dashboard ───────────────────────────────────────────────── */
.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

/* ── Utility ─────────────────────────────────────────────────── */
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.gap-1          { gap: 4px; }
.gap-2          { gap: 8px; }
.gap-3          { gap: 12px; }
.gap-4          { gap: 16px; }
.mt-1           { margin-top: 4px; }
.mt-2           { margin-top: 8px; }
.mt-3           { margin-top: 12px; }
.mt-4           { margin-top: 16px; }
.mb-1           { margin-bottom: 4px; }
.mb-2           { margin-bottom: 8px; }
.mb-3           { margin-bottom: 12px; }
.mb-4           { margin-bottom: 16px; }
.text-sm        { font-size: 13px; }
.text-xs        { font-size: 12px; }
.text-muted     { color: var(--text-3); }
.text-right     { text-align: right; }
.font-bold      { font-weight: 700; }
.font-semibold  { font-weight: 600; }
.w-full         { width: 100%; }
.hidden         { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-100%); width: 240px; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .content { padding: 16px; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Мобильная навигация: гамбургер, шторка, нижнее меню ─────── */
/* Разметка нижнего меню — templates/partials/bottom_nav.php,
   используется одинаково и на /mobile, и на остальных страницах. */
/* По умолчанию (десктоп) — всё скрыто */
.menu-toggle-btn { display: none; }
.sidebar-overlay { display: none; }
.app-bottom-nav  { display: none; }

@media (max-width: 768px) {
  /* Кнопка-гамбургер в топбаре */
  .menu-toggle-btn { display: inline-flex; }

  /* Затемнение под выдвижным боковым меню */
  .sidebar-overlay {
    display: block;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 96;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
  }
  .sidebar-overlay.show { opacity: 1; pointer-events: auto; }
  .sidebar { z-index: 100; }

  /* Контент не должен прятаться под нижним меню */
  .content { padding-bottom: 78px; }

  /* Постоянное нижнее меню */
  .app-bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    height: 60px; z-index: 95;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(15, 23, 42, .06);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .app-bottom-nav a,
  .app-bottom-nav button {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    font-family: var(--font);
    font-size: 10px; font-weight: 600;
    color: var(--text-3);
    background: none; border: none; cursor: pointer;
    text-decoration: none; position: relative;
  }
  .app-bottom-nav a.active,
  .app-bottom-nav button.active { color: var(--primary); }
  .app-bottom-nav svg { width: 22px; height: 22px; }
  .app-bottom-nav .abn-badge {
    position: absolute; top: 5px; left: 50%; transform: translateX(6px);
    background: var(--danger); color: #fff;
    font-size: 9px; font-weight: 700;
    min-width: 15px; height: 15px; padding: 0 3px;
    border-radius: 99px;
    display: flex; align-items: center; justify-content: center;
  }
}

/* ── Адаптивные таблицы: на телефоне строки → карточки ──────── */
@media (max-width: 768px) {
  .table-wrap {
    overflow-x: visible;
    border: none;
    box-shadow: none;
    background: transparent;
  }
  .table-wrap table { background: transparent; }
  .table-wrap thead { display: none; }               /* шапку прячем */
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }

  .table-wrap tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 10px;
    padding: 4px 2px;
  }
  .table-wrap tbody tr:hover { background: var(--surface); }

  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border: none;
    border-bottom: 1px solid var(--border);
    text-align: right;
    min-height: 20px;
  }
  .table-wrap tbody tr td:last-child { border-bottom: none; }

  /* Подпись колонки слева (из data-label, который проставляет JS) */
  .table-wrap tbody td[data-label]::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    text-align: left;
    flex-shrink: 0;
    white-space: nowrap;
  }
  /* Пустые ячейки-действия без подписи не занимают место */
  .table-wrap tbody td:empty { display: none; }
}

/* ── Vienots mobilais Header — tāds pats visās mobilās versijas lapās ──
   Uz telefona virsraksts+versija paslēpti, vietā "NIKNEL + lietotājs"
   uz tumša fona (tāpat kā /mobile sākumlapā). Apakšējā josla jau ir vienota
   (templates/partials/bottom_nav.php). */
.topbar-brand-m { display: none; }
.topbar-search-m { display: none; }

@media (max-width: 768px) {
  /* Neļaujam platam saturam (piem. desktop tabulām) izstiept lapu — citādi
     uz telefona horizontālais scroll "aizvāc" fiksēto apakšējo joslu (footer). */
  html, body { overflow-x: hidden; }
  .content { overflow-x: hidden; }

  .topbar {
    background: #1E293B;
    color: #fff;
    border-bottom: none;
    gap: 8px;
    padding: 0 12px;
  }
  .topbar-search-m {
    display: grid;
    place-items: center;
    width: 36px; height: 36px;
    color: #fff;
    border-radius: var(--radius-sm);
  }
  .topbar-search-m:hover { background: rgba(255,255,255,.12); }
  .topbar .menu-toggle-btn { display: none; }        /* navigācija — apakšējā "Izvēlne" */
  .topbar .topbar-title,
  .topbar .topbar-version { display: none; }
  .topbar-brand-m {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.15;
    text-decoration: none;
    padding: 8px 0;
  }
  .topbar-brand-m .tbm-name {
    font-size: 16px; font-weight: 700; letter-spacing: .3px; color: #fff;
  }
  .topbar-brand-m .tbm-sub {
    font-size: 11px; color: #94A3B8; margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar .notif-btn {
    border-color: rgba(255,255,255,.18);
    color: #fff;
  }
  .topbar .notif-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
  .topbar .notif-dot { border-color: #1E293B; }
}
