:root {
  --bg: #0b1020;
  --bg-2: #111936;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.14);
  --text: #eef3ff;
  --muted: #9ba8c7;
  --primary: #6d8cff;
  --primary-2: #7c4dff;
  --ok: #43d99d;
  --warn: #ffce5c;
  --danger: #ff6678;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --radius: 24px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(109, 140, 255, 0.26), transparent 34rem),
    radial-gradient(circle at 100% 30%, rgba(67, 217, 157, 0.16), transparent 30rem),
    linear-gradient(145deg, var(--bg), #050713 72%);
  color: var(--text);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
}

.app-shell.login-mode {
  grid-template-columns: 1fr;
}

.app-shell.login-mode .main {
  padding: 34px;
}

.app-shell.login-mode .login-screen {
  min-height: calc(100vh - 68px);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(8, 12, 27, 0.72);
  backdrop-filter: blur(22px);
}

.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 36px; }
.brand-mark {
  width: 54px; height: 54px; border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 16px 38px rgba(109, 140, 255, 0.36);
  font-weight: 900;
}
.brand-title { font-weight: 800; font-size: 20px; letter-spacing: -0.03em; }
.brand-subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }

.nav { display: grid; gap: 10px; }
.nav-item {
  width: 100%; text-align: left;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
  padding: 13px 14px;
  border-radius: 16px;
}
.nav-item:hover, .nav-item.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
}

.sidebar-footer { margin-top: auto; display: grid; gap: 14px; }
.user-card {
  display: flex; gap: 12px; align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}
.user-avatar {
  width: 38px; height: 38px; border-radius: 14px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.12);
  font-weight: 800;
}
.user-email { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.user-role { color: var(--muted); font-size: 12px; margin-top: 2px; }

.main { padding: 34px; min-width: 0; }
.login-screen { min-height: calc(100vh - 68px); display: grid; place-items: center; }
.login-card {
  width: min(520px, 100%);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06));
  box-shadow: var(--shadow);
  border-radius: 32px;
  padding: 36px;
}
.login-card h1, .topbar h1 { margin: 8px 0 10px; letter-spacing: -0.05em; }
.login-card p { color: var(--muted); line-height: 1.55; margin-bottom: 24px; }
.eyebrow { color: var(--ok); text-transform: uppercase; letter-spacing: 0.16em; font-size: 12px; font-weight: 800; }

.workspace { display: grid; gap: 24px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }

.panel {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.18);
}
.accent-panel { background: linear-gradient(135deg, rgba(109,140,255,0.18), rgba(255,255,255,0.07)); }
.panel-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.panel-header h2 { margin: 0 0 4px; letter-spacing: -0.03em; }
.panel-header p { margin: 0; color: var(--muted); font-size: 14px; }
.split { align-items: center; }

.grid.two { display: grid; grid-template-columns: 1fr 1.25fr; gap: 24px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.11), rgba(255,255,255,0.055));
  border-radius: 22px;
  padding: 20px;
}
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin: 8px 0 4px; font-size: 30px; letter-spacing: -0.06em; }
.stat-card em { color: var(--muted); font-size: 12px; font-style: normal; }

.form, .measurement-grid, .admin-form { display: grid; gap: 14px; }
.measurement-grid { grid-template-columns: repeat(4, 1fr); }
.admin-form { grid-template-columns: 1.4fr 1fr 220px auto; margin-bottom: 18px; }
.inline-form { display: flex; gap: 10px; margin-bottom: 18px; }
.wide { grid-column: 1 / -1; }

label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
input, .select {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 13px;
  outline: none;
}
input:focus, .select:focus { border-color: rgba(109,140,255,0.8); box-shadow: 0 0 0 4px rgba(109,140,255,0.14); }
select option { color: #111827; }

.btn {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  color: var(--text);
  background: var(--panel-strong);
  font-weight: 750;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { border: 0; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 12px 28px rgba(109,140,255,0.25); }
.btn.secondary { background: rgba(255,255,255,0.11); }
.btn.ghost { background: transparent; }
.full { width: 100%; }

.list-stack { display: grid; gap: 10px; }
.list-card {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 13px 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  border-radius: 16px;
}
.list-card.active { border-color: rgba(109,140,255,0.8); background: rgba(109,140,255,0.16); }
.badge {
  border-radius: 999px;
  background: rgba(67,217,157,0.14);
  color: #9cf4ce;
  font-size: 12px;
  padding: 5px 9px;
}
.badge.read { background: rgba(255,206,92,0.13); color: #ffe29a; }
.badge.owner { background: rgba(109,140,255,0.18); color: #b9c7ff; }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; background: rgba(255,255,255,0.05); }
td { color: #e8edff; }
tr:last-child td { border-bottom: 0; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }

#chart { width: 100%; max-height: 380px; }
.chart-legend {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  margin: 12px 0 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
}
.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 0 18px currentColor;
}
.legend-dot.systolic { background: #8ea2ff; color: #8ea2ff; }
.legend-dot.diastolic { background: #43d99d; color: #43d99d; }
.legend-dot.pulse { background: #ffce5c; color: #ffce5c; }
.notice, .toast {
  border: 1px solid rgba(255,102,120,0.35);
  background: rgba(255,102,120,0.12);
  color: #ffd1d8;
  border-radius: 16px;
  padding: 12px 14px;
  margin-top: 16px;
}
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(420px, calc(100vw - 48px));
  margin: 0;
  box-shadow: var(--shadow);
  z-index: 10;
}
.toast.ok { border-color: rgba(67,217,157,0.35); background: rgba(67,217,157,0.14); color: #c9ffe8; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid.two, .stats-grid { grid-template-columns: 1fr; }
  .measurement-grid, .admin-form { grid-template-columns: 1fr; }
  .topbar { align-items: stretch; flex-direction: column; }
  .topbar-actions { align-items: stretch; }
}

@media (max-width: 720px) {
  .main, .sidebar { padding: 18px; }
  .login-card { padding: 24px; }
  .inline-form, .topbar-actions, .filters { flex-direction: column; align-items: stretch; }
  .panel-header, .split { flex-direction: column; }
}


@media print {
  body {
    background: #fff;
    color: #000;
  }

  body::before {
    content: "BP Tracker — печатный отчет";
    display: block;
    font-size: 22px;
    font-weight: 800;
    margin: 0 0 6px;
  }

  body::after {
    content: "Сформировано: " attr(data-print-date);
    display: block;
    margin-top: 18px;
    font-size: 11px;
    color: #555;
  }

  .sidebar,
  .topbar,
  .grid.two,
  .stats-grid,
  .chart-legend,
  #dashboardView,
  #sharingView,
  #profileView,
  #adminView,
  .filters,
  .toast,
  .login-screen {
    display: none !important;
  }

  .app-shell,
  .main,
  .workspace,
  .view,
  .panel,
  .table-wrap {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #measurementsView {
    display: block !important;
  }

  .panel-header {
    display: block !important;
    margin: 0 0 12px !important;
  }

  .panel-header h2 {
    color: #000 !important;
    margin: 0 0 4px !important;
  }

  .panel-header p {
    color: #555 !important;
    margin: 0 0 12px !important;
  }

  table {
    min-width: 0 !important;
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 11px !important;
  }

  th,
  td {
    color: #000 !important;
    border: 1px solid #999 !important;
    padding: 6px !important;
  }

  th {
    background: #eee !important;
  }
}

.btn.tiny {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 6, 18, 0.72);
  backdrop-filter: blur(14px);
}

.modal-card {
  width: min(760px, 100%);
  border: 1px solid var(--border);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(28, 35, 58, 0.98), rgba(15, 21, 42, 0.98));
  box-shadow: var(--shadow);
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 8px 0 0;
  letter-spacing: -0.04em;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@media print {
  .modal-backdrop,
  .edit-measurement-btn,
  table th:last-child,
  table td:last-child {
    display: none !important;
  }
}

.chart-help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 10px;
}

.chart-help strong {
  color: var(--text);
  margin-right: 4px;
}

.chart-wrap {
  position: relative;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 230px;
  max-width: 300px;
  transform: translateY(-100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(7, 11, 25, 0.94);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  pointer-events: none;
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}

.chart-tooltip span {
  color: var(--muted);
  margin-top: 3px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.danger {
  border-color: rgba(255, 102, 120, 0.38);
  background: rgba(255, 102, 120, 0.14);
  color: #ffd1d8;
}

.btn.danger:hover {
  background: rgba(255, 102, 120, 0.22);
}

.danger-text {
  color: var(--danger);
}

.danger-modal {
  max-width: 660px;
}

.delete-summary {
  display: grid;
  gap: 10px;
  margin: 8px 0 14px;
  padding: 14px;
  border: 1px solid rgba(255, 102, 120, 0.28);
  border-radius: 18px;
  background: rgba(255, 102, 120, 0.08);
}

.delete-summary div {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 12px;
  align-items: baseline;
}

.delete-summary span {
  color: var(--muted);
  font-size: 13px;
}

.delete-summary strong {
  color: var(--text);
  overflow-wrap: anywhere;
}

.danger-note {
  color: #ffd1d8;
  margin: 0 0 18px;
  line-height: 1.5;
}

@media print {
  .chart-help,
  .chart-tooltip,
  .delete-measurement-btn {
    display: none !important;
  }
}

/* Tablet portrait / narrow desktop layout */
@media (min-width: 721px) and (max-width: 1100px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    padding: 14px 18px;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    grid-template-areas:
      "brand footer"
      "nav nav";
    gap: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    grid-area: brand;
    margin: 0;
    min-width: 0;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 16px;
  }

  .brand-title {
    font-size: 18px;
  }

  .brand-subtitle {
    font-size: 12px;
  }

  .nav {
    grid-area: nav;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    padding: 10px 14px;
    border-radius: 999px;
    white-space: nowrap;
  }

  .sidebar-footer {
    grid-area: footer;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
  }

  .user-card {
    max-width: 260px;
    padding: 9px 10px;
    border-radius: 16px;
  }

  .user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 12px;
  }

  .user-email {
    max-width: 150px;
  }

  .sidebar-footer .btn {
    width: auto;
    padding: 10px 14px;
  }

  .main {
    padding: 22px;
  }

  .login-screen {
    min-height: calc(100vh - 100px);
  }

  .topbar {
    flex-direction: row;
    align-items: center;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    width: min(520px, 100%);
  }

  .grid.two {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .measurement-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-form {
    grid-template-columns: 1fr 1fr;
  }

  .inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .filters .btn {
    width: 100%;
  }

  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .panel-header.split {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-card strong {
    font-size: 26px;
  }

  #chart {
    height: auto;
    max-height: 320px;
  }

  .modal-card {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
  }
}

/* Phone / very narrow portrait layout */
@media (max-width: 720px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: auto;
    display: grid;
    gap: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand {
    margin-bottom: 0;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 15px;
  }

  .brand-title {
    font-size: 18px;
  }

  .brand-subtitle {
    font-size: 12px;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    padding: 10px 13px;
    border-radius: 999px;
    white-space: nowrap;
  }

  .sidebar-footer {
    margin-top: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .sidebar-footer .btn {
    width: auto;
  }

  .user-email {
    max-width: 46vw;
  }

  .main {
    padding: 16px;
  }

  .login-screen {
    min-height: calc(100vh - 92px);
    place-items: start stretch;
    padding-top: 18px;
  }

  .login-card {
    border-radius: 24px;
  }

  .workspace {
    gap: 16px;
  }

  .topbar h1,
  .login-card h1 {
    font-size: 28px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .stats-grid,
  .measurement-grid,
  .admin-form,
  .inline-form,
  .filters {
    grid-template-columns: 1fr;
  }

  .stat-card strong {
    font-size: 24px;
  }

  .panel {
    padding: 16px;
    border-radius: 20px;
  }

  .chart-legend {
    gap: 8px;
    font-size: 12px;
  }

  .chart-legend span {
    padding: 7px 9px;
  }

  .chart-help {
    font-size: 12px;
  }

  #chart {
    max-height: 280px;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .row-actions .btn {
    width: 100%;
  }

  .modal-backdrop {
    padding: 12px;
    place-items: end stretch;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100vh - 24px);
    overflow: auto;
    border-radius: 22px;
    padding: 18px;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .delete-summary div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.import-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.11);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
}
.import-label input { display: none; }

.member-access { min-width: 120px; }

@media (min-width: 1101px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

.zone-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
}
.zone-badge.ok, .zone-badge.normal { color: var(--ok); background: rgba(67,217,157,0.12); }
.zone-badge.low, .zone-badge.elevated, .zone-badge.warn { color: var(--warn); background: rgba(255,206,92,0.12); }
.zone-badge.high, .zone-badge.danger { color: var(--danger); background: rgba(255,102,120,0.14); }
.danger-row { background: rgba(255,102,120,0.08); }
.danger-stat.danger, .danger-stat.high { border-color: rgba(255,102,120,0.45); }
.danger-stat.warn, .danger-stat.elevated, .danger-stat.low { border-color: rgba(255,206,92,0.42); }

.profile-grid { display: grid; gap: 18px; margin-top: 22px; grid-template-columns: 1fr; }
.subpanel { border: 1px solid var(--border); border-radius: 18px; padding: 16px; background: rgba(255,255,255,0.055); }
.subpanel h3 { margin: 0 0 14px; }
.small-table { max-height: 320px; overflow: auto; }

.big-input-card { width: min(860px, calc(100vw - 32px)); }
.big-input-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.big-input-grid input[type="number"] { font-size: 44px; font-weight: 900; text-align: center; padding: 20px 12px; }
.big-input-grid label { font-size: 15px; }

:root[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-2: #ffffff;
  --panel: rgba(255,255,255,0.84);
  --panel-strong: rgba(255,255,255,0.96);
  --border: rgba(15,23,42,0.14);
  --text: #172033;
  --muted: #5f6b83;
  --shadow: 0 24px 80px rgba(18, 33, 63, 0.12);
}
:root[data-theme="light"] body {
  background: radial-gradient(circle at 20% 0%, rgba(109, 140, 255, 0.20), transparent 34rem), linear-gradient(145deg, #eef3ff, #f8fafc 72%);
}
:root[data-theme="light"] input, :root[data-theme="light"] .select { background: rgba(255,255,255,0.9); }
:root[data-theme="light"] .sidebar { background: rgba(255,255,255,0.75); }
:root[data-theme="light"] .login-card { background: rgba(255,255,255,0.86); }

:root[data-theme="light"] .panel,
:root[data-theme="light"] .subpanel,
:root[data-theme="light"] .modal-card,
:root[data-theme="light"] .table-wrap,
:root[data-theme="light"] .list-card,
:root[data-theme="light"] .stat-card {
  background: rgba(255,255,255,0.82);
}
:root[data-theme="light"] .nav-item.active,
:root[data-theme="light"] .user-card,
:root[data-theme="light"] .btn.secondary,
:root[data-theme="light"] .btn.ghost {
  background: rgba(15,23,42,0.06);
}
:root[data-theme="light"] table th { color: #42526f; }
:root[data-theme="light"] .danger-row { background: rgba(255,102,120,0.10); }


@media (max-width: 720px) {
  .big-input-grid { grid-template-columns: 1fr; }
  .big-input-grid input[type="number"] { font-size: 38px; }
}

.delete-options {
  display: grid;
  gap: 12px;
  margin: 12px 0 16px;
}

.option-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 700;
}

.option-card input {
  width: 18px;
  height: 18px;
}

.danger-choice {
  border-color: rgba(255, 102, 120, 0.35);
  background: rgba(255, 102, 120, 0.08);
}

/* Inline list and measurement actions */
.list-card {
  align-items: stretch;
  padding: 0;
  overflow: hidden;
}

.list-card.empty-list-card {
  padding: 13px 14px;
}

.list-select-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.list-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 8px 0;
}

.icon-action {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.icon-action:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255,255,255,0.13);
}

.icon-action.danger {
  border-color: rgba(255, 102, 120, 0.36);
  background: rgba(255, 102, 120, 0.12);
  color: #ffd0d6;
}

.icon-action.danger:hover:not(:disabled) {
  background: rgba(255, 102, 120, 0.20);
}

.icon-action:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.icon-row-actions {
  flex-wrap: nowrap;
}

:root[data-theme="light"] .list-select-btn,
:root[data-theme="light"] .icon-action {
  color: var(--text);
}

:root[data-theme="light"] .icon-action {
  background: rgba(15, 23, 42, 0.05);
}

:root[data-theme="light"] .icon-action.danger {
  color: #9f1239;
  background: rgba(225, 29, 72, 0.08);
}

@media (max-width: 720px) {
  .list-card-actions {
    padding-right: 8px;
  }

  .icon-row-actions {
    display: flex;
    flex-direction: row;
  }

  .icon-row-actions .icon-action {
    width: 40px;
  }
}

/* Custom tooltips for compact action buttons */
.icon-action[data-tooltip] {
  position: relative;
}

.icon-action[data-tooltip]::before,
.icon-action[data-tooltip]::after {
  position: absolute;
  left: 50%;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition: opacity 120ms ease, transform 120ms ease;
  z-index: 80;
}

.icon-action[data-tooltip]::before {
  content: attr(data-tooltip);
  bottom: calc(100% + 10px);
  width: max-content;
  max-width: 220px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.icon-action[data-tooltip]::after {
  content: "";
  bottom: calc(100% + 4px);
  border: 6px solid transparent;
  border-top-color: rgba(15, 23, 42, 0.96);
}

.icon-action[data-tooltip]:hover::before,
.icon-action[data-tooltip]:hover::after,
.icon-action[data-tooltip]:focus-visible::before,
.icon-action[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

:root[data-theme="light"] .icon-action[data-tooltip]::before {
  background: rgba(255, 255, 255, 0.98);
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.18);
}

:root[data-theme="light"] .icon-action[data-tooltip]::after {
  border-top-color: rgba(255, 255, 255, 0.98);
}

.list-card,
.list-card-actions,
.row-actions {
  overflow: visible;
}
.muted { color: var(--muted); }
.warning-note { border-color: rgba(255,206,92,0.35); background: rgba(255,206,92,0.10); color: var(--text); }

/* Compact topbar list actions */
.topbar-actions,
.topbar-icon-actions {
  overflow: visible;
}

.topbar-actions {
  flex-wrap: nowrap;
}

.topbar-actions > .select {
  min-width: 240px;
}

.topbar-icon-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.icon-action.top-action {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 22px;
}

@media (min-width: 721px) and (max-width: 1100px) {
  .topbar-actions {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    width: min(520px, 100%);
  }
}

@media (max-width: 720px) {
  .topbar-icon-actions {
    justify-content: flex-start;
  }

  .icon-action.top-action {
    width: 46px;
    height: 46px;
  }
}


/* Profile tables must stay inside their cards. Tooltips stay visible only in action cells. */
.profile-grid .subpanel {
  overflow: hidden;
}

.profile-grid .table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 320px;
  position: relative;
}

.profile-grid table {
  min-width: 760px;
}

.profile-grid th,
.profile-grid td {
  vertical-align: middle;
}

.profile-grid .row-actions {
  overflow: visible;
}

/* Stronger light theme contrast fixes */
:root[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-2: #ffffff;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --border: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --muted: #475569;
  --ok: #059669;
  --warn: #b45309;
  --danger: #be123c;
  --primary: #4f64ff;
  --primary-2: #7047ff;
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
}

:root[data-theme="light"] body {
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(109, 140, 255, 0.18), transparent 34rem),
    radial-gradient(circle at 100% 30%, rgba(67, 217, 157, 0.10), transparent 30rem),
    linear-gradient(145deg, #eef3ff, #f8fafc 72%);
}

:root[data-theme="light"] .sidebar,
:root[data-theme="light"] .panel,
:root[data-theme="light"] .subpanel,
:root[data-theme="light"] .modal-card,
:root[data-theme="light"] .login-card,
:root[data-theme="light"] .table-wrap,
:root[data-theme="light"] .list-card,
:root[data-theme="light"] .stat-card,
:root[data-theme="light"] .user-card {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 23, 42, 0.14);
}

:root[data-theme="light"] .accent-panel,
:root[data-theme="light"] .stat-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96));
}

:root[data-theme="light"] input,
:root[data-theme="light"] .select {
  background: #ffffff;
  color: var(--text);
  border-color: rgba(15, 23, 42, 0.16);
}

:root[data-theme="light"] input::placeholder {
  color: #64748b;
  opacity: 1;
}

:root[data-theme="light"] table,
:root[data-theme="light"] th,
:root[data-theme="light"] td,
:root[data-theme="light"] .table-wrap td,
:root[data-theme="light"] .small-table td {
  color: var(--text);
}

:root[data-theme="light"] table th {
  color: #334155;
  background: rgba(15, 23, 42, 0.035);
  border-bottom-color: rgba(15, 23, 42, 0.14);
}

:root[data-theme="light"] table td {
  border-bottom-color: rgba(15, 23, 42, 0.10);
}

:root[data-theme="light"] .empty-row td,
:root[data-theme="light"] .muted,
:root[data-theme="light"] label,
:root[data-theme="light"] .panel-header p,
:root[data-theme="light"] .brand-subtitle,
:root[data-theme="light"] .stat-card span,
:root[data-theme="light"] .stat-card em,
:root[data-theme="light"] .user-role,
:root[data-theme="light"] .chart-help,
:root[data-theme="light"] .chart-tooltip span {
  color: var(--muted);
}

:root[data-theme="light"] .nav-item {
  color: #475569;
}

:root[data-theme="light"] .nav-item:hover,
:root[data-theme="light"] .nav-item.active {
  color: var(--text);
  background: rgba(79, 100, 255, 0.08);
  border-color: rgba(79, 100, 255, 0.20);
}

:root[data-theme="light"] .btn,
:root[data-theme="light"] .btn.secondary,
:root[data-theme="light"] .btn.ghost,
:root[data-theme="light"] .icon-action,
:root[data-theme="light"] .list-select-btn {
  color: var(--text);
  background: #f8fafc;
  border-color: rgba(15, 23, 42, 0.16);
}

:root[data-theme="light"] .btn.primary {
  color: #ffffff;
}

:root[data-theme="light"] .btn.danger,
:root[data-theme="light"] .icon-action.danger {
  color: #9f1239;
  background: rgba(225, 29, 72, 0.08);
  border-color: rgba(225, 29, 72, 0.22);
}

:root[data-theme="light"] .badge,
:root[data-theme="light"] .zone-badge {
  border-color: rgba(15, 23, 42, 0.12);
}

:root[data-theme="light"] .zone-badge.ok,
:root[data-theme="light"] .zone-badge.normal,
:root[data-theme="light"] .badge.write,
:root[data-theme="light"] .badge.active {
  color: #047857;
  background: rgba(5, 150, 105, 0.12);
}

:root[data-theme="light"] .zone-badge.low,
:root[data-theme="light"] .zone-badge.elevated,
:root[data-theme="light"] .zone-badge.warn,
:root[data-theme="light"] .badge.revoked {
  color: #b45309;
  background: rgba(245, 158, 11, 0.16);
}

:root[data-theme="light"] .zone-badge.high,
:root[data-theme="light"] .zone-badge.danger,
:root[data-theme="light"] .badge.expired {
  color: #be123c;
  background: rgba(225, 29, 72, 0.12);
}

:root[data-theme="light"] .chart-legend span,
:root[data-theme="light"] .chart-help {
  color: var(--text);
  background: rgba(248, 250, 252, 0.90);
  border-color: rgba(15, 23, 42, 0.12);
}

:root[data-theme="light"] .chart-tooltip {
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  border-color: rgba(15, 23, 42, 0.18);
}

:root[data-theme="light"] .chart-tooltip span {
  color: #cbd5e1;
}

:root[data-theme="light"] .danger-row {
  background: rgba(225, 29, 72, 0.08);
}

.import-mapping {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.import-mapping input,
.import-mapping select {
  width: 100%;
}
.stats-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.list-description {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

/* Fix desktop sidebar overflow after adding many navigation sections and PWA button. */
@media (min-width: 1101px) {
  .sidebar {
    overflow-y: auto;
    overflow-x: hidden;
    gap: 14px;
    padding-top: 22px;
    padding-bottom: 18px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
  }

  .sidebar::-webkit-scrollbar {
    width: 6px;
  }

  .sidebar::-webkit-scrollbar-track {
    background: transparent;
  }

  .sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.16);
    border-radius: 999px;
  }

  .brand {
    margin-bottom: 4px;
  }

  .brand-logo {
    width: 58px;
    height: 58px;
    border-radius: 18px;
  }

  .brand-title {
    font-size: 22px;
  }

  .brand-subtitle {
    font-size: 13px;
  }

  .nav {
    flex: 0 0 auto;
    overflow: visible;
    gap: 6px;
  }

  .nav-item {
    min-height: 38px;
    padding: 8px 16px;
    font-size: 15px;
    border-radius: 14px;
  }

  .sidebar-footer {
    flex: 0 0 auto;
    gap: 8px;
    margin-top: auto;
  }

  .sidebar-footer .user-card {
    padding: 10px 12px;
    border-radius: 16px;
  }

  .sidebar-footer .avatar {
    width: 42px;
    height: 42px;
  }

  .sidebar-footer .btn.full {
    min-height: 40px;
    padding: 9px 14px;
    border-radius: 14px;
  }
}
