:root {
  --brand-900: #311b92;
  --brand-800: #4527a0;
  --brand-700: #512da8;
  --brand-600: #5e35b1;
  --brand-500: #673ab7;
  --brand-400: #7e57c2;
  --brand-100: #ede7f6;
  --brand-50:  #f6f2fb;

  --green-600: #2e7d32;
  --green-400: #66bb6a;

  --amber-500: #f57c00;
  --blue-500: #1976d2;
  --brown-500: #6d4c41;
  --pink-500: #c2185b;
  --teal-500: #00897b;

  --bg: #faf8fd;
  --surface: #ffffff;
  --surface-2: #faf8fd;
  --text: #1a1033;
  --text-2: #4e4466;
  --muted: #8a83a0;
  --border: #eae4f2;
  --danger: #c62828;

  --shadow-1: 0 1px 2px rgba(60, 30, 130, .04), 0 2px 6px rgba(60, 30, 130, .04);
  --shadow-2: 0 4px 14px rgba(60, 30, 130, .08), 0 8px 24px rgba(60, 30, 130, .06);
  --shadow-3: 0 12px 32px rgba(60, 30, 130, .16), 0 8px 16px rgba(60, 30, 130, .08);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
}
@supports (font-variation-settings: normal) {
  html, body { font-family: "Inter var", -apple-system, "Segoe UI", Roboto, sans-serif; }
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: 0; cursor: pointer; background: transparent; }

/* =================== App bar =================== */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.appbar-left {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px; margin: -4px -8px;
  border-radius: 10px;
  transition: background .15s;
  min-width: 0;
}
.appbar-left:hover, .appbar-left:active { background: var(--brand-50); }
.appbar-logo {
  height: 32px; width: auto; display: block; flex-shrink: 1;
  max-width: 60vw; object-fit: contain;
}
.appbar-badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 999px;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
  color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase;
  white-space: nowrap;
}
/* Legacy styles kept in case other pages still reference them */
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: #fff;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(94, 53, 177, .15);
  overflow: hidden;
}
.logo img { width: 80%; height: 80%; object-fit: contain; display: block; }
.appbar-titles { line-height: 1.1; }
.appbar-title { font-weight: 700; font-size: 16px; }
.appbar-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.appbar-right { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; color: var(--text-2);
  transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--brand-100); color: var(--brand-700); }

/* =================== Screen layout =================== */
.screen {
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 1280px; margin: 0 auto;
}

/* =================== Hero =================== */
.hero {
  position: relative;
  padding: 22px 20px 20px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 100% at 100% 0%, rgba(126, 87, 194, .25) 0%, transparent 60%),
    linear-gradient(135deg, var(--brand-700) 0%, var(--brand-900) 100%);
  color: #fff;
  box-shadow: var(--shadow-2);
  overflow: hidden;
  margin-bottom: 16px;
}
.hero::after {
  content: ""; position: absolute; inset: auto -40px -40px auto;
  width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255,255,255,.14), transparent);
  pointer-events: none;
}
.hero-eyebrow {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px;
  opacity: .72; font-weight: 600;
}
.hero-title {
  margin: 6px 0 14px; font-size: 26px; line-height: 1.2; font-weight: 700;
  word-break: break-word;
}
.hero-meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hero-count { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.hero-count-label { font-size: 14px; opacity: .82; }
.hero-reset {
  margin-left: auto; padding: 8px 14px; border-radius: 999px;
  background: rgba(255,255,255,.18); color: #fff; font-size: 13px; font-weight: 500;
  transition: background .15s;
}
.hero-reset:hover, .hero-reset:active { background: rgba(255,255,255,.28); }

/* =================== Filters (accordion) =================== */
.filters {
  display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px;
}
.filter {
  background: var(--surface); border-radius: var(--radius-md);
  box-shadow: var(--shadow-1); overflow: hidden;
  transition: box-shadow .2s;
}
.filter.open { box-shadow: var(--shadow-2); }
.filter-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer;
  width: 100%; text-align: left;
}
.filter-ico {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px;
  background: var(--brand-100); color: var(--brand-700);
  display: grid; place-items: center;
}
.filter-ico svg { width: 18px; height: 18px; }
.filter-body { flex: 1; min-width: 0; }
.filter-label { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .3px; text-transform: uppercase; }
.filter-value { font-size: 15px; color: var(--text); font-weight: 600; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-value.empty { color: var(--muted); font-weight: 500; }
.filter-caret {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center; color: var(--muted);
  transition: transform .25s, background .15s;
  flex: 0 0 28px;
}
.filter.open .filter-caret { transform: rotate(180deg); color: var(--brand-700); }
.filter-options {
  padding: 0 16px;
  max-height: 0; overflow: hidden;
  transition: max-height .3s ease, padding .3s ease;
}
.filter.open .filter-options { padding: 4px 16px 16px; max-height: 420px; overflow-y: auto; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); font-size: 13px; font-weight: 500;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  cursor: pointer;
}
.chip:hover { background: var(--brand-50); border-color: var(--brand-400); color: var(--brand-800); }
.chip:active { transform: scale(.97); }
.chip.selected {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 4px 12px rgba(81, 45, 168, .3);
}
.chip .chip-x { margin-left: 6px; opacity: .75; font-weight: 700; }

/* =================== Results =================== */
.results { display: flex; flex-direction: column; gap: 10px; }
.results-empty {
  padding: 40px 16px; text-align: center; color: var(--muted);
  background: var(--surface); border-radius: var(--radius-md);
  border: 1px dashed var(--border);
}

/* Mobile: card layout */
.row-card {
  background: var(--surface); border-radius: var(--radius-md);
  padding: 14px 16px; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 8px;
  border-left: 4px solid var(--brand-400);
  transition: transform .1s, box-shadow .15s;
}
.row-card:active { transform: scale(.995); }
.row-card.techop-zzr { border-left-color: var(--amber-500); }
.row-card.techop-dobryva { border-left-color: var(--green-600); }
.row-card.techop-grunt { border-left-color: var(--brown-500); }
.row-card.techop-posiv { border-left-color: var(--blue-500); }
.row-card.techop-zbir { border-left-color: var(--pink-500); }

.row-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.row-tmc { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.3; }
.row-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-stage { font-size: 12px; color: var(--text-2); font-weight: 500; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
  background: var(--brand-50); color: var(--brand-800);
}
.tag.norma { background: #fff7e6; color: #b26500; }
.tag.faza { background: #e6f4ea; color: var(--green-600); }
.tag.techop-zzr { background: #fff3e0; color: var(--amber-500); }
.tag.techop-dobryva { background: #e8f5e9; color: var(--green-600); }
.tag.techop-grunt { background: #efebe9; color: var(--brown-500); }
.tag.techop-posiv { background: #e3f2fd; color: var(--blue-500); }
.tag.techop-zbir { background: #fce4ec; color: var(--pink-500); }

/* Desktop: table */
.results-table {
  display: none;
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border-radius: var(--radius-md);
  overflow: hidden; box-shadow: var(--shadow-1);
}
.results-table thead th {
  background: var(--brand-50); color: var(--brand-800);
  text-align: left; padding: 12px 16px; font-weight: 600; font-size: 13px;
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.results-table tbody td { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 14px; }
.results-table tbody tr:first-child td { border-top: 0; }
.results-table tbody tr:hover { background: var(--brand-50); }

/* =================== FAB =================== */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--safe-bottom));
  z-index: 20;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 14px 20px; border-radius: 999px;
  background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
  color: #fff; font-weight: 600; font-size: 14px;
  box-shadow: 0 12px 24px rgba(69, 39, 160, .35), 0 4px 8px rgba(69, 39, 160, .2);
  transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: translateY(1px) scale(.98); }
.fab svg { stroke-width: 2.25; }

/* =================== Bottom-sheet modals =================== */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute; inset: 0; background: rgba(26, 16, 51, .45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .2s ease;
}
.sheet-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 14px 20px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow-3);
  animation: slide-up .28s cubic-bezier(.2, .9, .3, 1.2);
  max-height: 90vh; overflow-y: auto;
}
.sheet-handle {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 0 auto 14px;
}
.sheet-panel h2 { margin: 0 0 6px; font-size: 19px; font-weight: 700; }
.sheet-sub { margin: 0 0 16px; color: var(--text-2); font-size: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.full { flex: 1 1 100%; }

.sv-options { display: flex; flex-direction: column; gap: 10px; }
.sv-option {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.sv-option:has(input:checked) {
  border-color: var(--brand-600); background: var(--brand-50);
}
.sv-option input { accent-color: var(--brand-700); width: 18px; height: 18px; }
.sv-option span { flex: 1; font-size: 14px; }

.qr-canvas { display: grid; place-items: center; margin: 16px 0; padding: 16px; background: #fff; border-radius: var(--radius-md); border: 1px solid var(--border); }
.qr-url {
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; color: var(--muted);
  background: var(--surface-2); padding: 8px 12px; border-radius: var(--radius-sm);
  margin: 0;
}

/* =================== Buttons =================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  transition: background .15s, color .15s, transform .1s, box-shadow .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
  color: #fff;
  box-shadow: 0 4px 12px rgba(69, 39, 160, .25);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(69, 39, 160, .35); }
.btn-outline {
  background: var(--surface); color: var(--brand-700);
  border: 1.5px solid var(--brand-600);
}
.btn-outline:hover { background: var(--brand-50); }
.btn-ghost { background: var(--surface-2); color: var(--text-2); }
.btn-ghost:hover { background: var(--brand-100); color: var(--brand-800); }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid #f5c6cb; }
.btn-danger:hover { background: #fef2f4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* =================== Login =================== */
.login-body {
  display: grid; place-items: center; min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(80% 60% at 20% 10%, rgba(126, 87, 194, .22), transparent 60%),
    radial-gradient(80% 60% at 100% 100%, rgba(46, 125, 50, .12), transparent 60%),
    linear-gradient(135deg, #f6f2fb 0%, #ede7f6 100%);
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface); padding: 32px 28px;
  border-radius: var(--radius-xl); box-shadow: var(--shadow-2);
}
.login-card .brand { text-align: center; margin-bottom: 22px; }
.login-card .brand-logo {
  width: 200px; height: auto; margin: 0 auto; display: block;
}
.login-card .brand-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.login-card h1 { margin: 0 0 18px; font-size: 18px; font-weight: 600; text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stack input, .stack textarea {
  padding: 13px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 15px; font-family: inherit; background: var(--surface-2); color: var(--text);
  transition: border-color .15s, background .15s;
}
.stack input:focus, .stack textarea:focus {
  outline: 0; border-color: var(--brand-600); background: var(--surface);
}
.stack .btn { padding: 14px; margin-top: 4px; }
.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 12px; margin: 18px 0 14px; text-transform: uppercase; letter-spacing: 1px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.hint { color: var(--muted); font-size: 12px; margin: 14px 0 0; text-align: center; line-height: 1.5; }
.err { color: var(--danger); font-size: 13px; margin: 4px 0 0; }

/* =================== Admin =================== */
.admin-screen { padding: 16px; padding-bottom: calc(32px + var(--safe-bottom)); max-width: 1080px; margin: 0 auto; }
.admin-grid {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
}
.card {
  background: var(--surface); border-radius: var(--radius-md);
  padding: 20px; box-shadow: var(--shadow-1);
}
.card h2 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.card .card-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.card h3 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.row-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-inline input {
  padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; flex: 1; min-width: 140px; font-family: inherit; background: var(--surface-2);
}
.row-inline input:focus { outline: 0; border-color: var(--brand-600); background: var(--surface); }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.checkbox input { accent-color: var(--brand-700); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions .btn { padding: 7px 12px; font-size: 12px; font-weight: 500; }
.tally-row { margin: 8px 0; font-size: 13px; }
.tally-label { display: flex; justify-content: space-between; margin-bottom: 4px; }
.tally-label span:first-child { font-weight: 500; }
.tally-n { color: var(--muted); font-variant-numeric: tabular-nums; }
.tally-bar { background: var(--surface-2); height: 8px; border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.tally-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-400), var(--brand-700));
  transition: width .4s ease;
}

.admin-table {
  width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px;
}
.admin-table thead th {
  text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.admin-table tbody td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table tbody tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: #e6f4ea; color: var(--green-600); }
.badge.closed { background: var(--surface-2); color: var(--muted); }

/* =================== Responsive =================== */
@media (min-width: 720px) {
  .hero-title { font-size: 30px; }
  .filters { display: grid; grid-template-columns: repeat(2, 1fr); }
  .filter.open { grid-column: span 2; }
  .appbar-logo { height: 38px; }
}
@media (min-width: 1024px) {
  .filters { grid-template-columns: repeat(4, 1fr); }
  .filter.open { grid-column: auto; }
  .results .row-card { display: none; }
  .results-table { display: table; }
  .screen { padding: 24px; }
  .admin-grid { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
  .card.wide { grid-column: 1 / -1; }
  .fab { right: 24px; bottom: 24px; }
}

/* Tap-friendly */
@media (hover: none) and (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .chip { padding: 10px 16px; font-size: 14px; }
  .sv-option { padding: 16px; }
}
