@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f4fa;
  --surface-3: #e8eef8;
  --text: #172033;
  --muted: #65708a;
  --border: #d9e1ef;
  --primary: #2d6cdf;
  --primary-strong: #1f57ba;
  --accent: #0f9d7a;
  --danger: #cf3f53;
  --warning: #d98e1a;
  --shadow: 0 10px 30px rgba(21, 34, 57, 0.08);
  --shadow-soft: 0 6px 18px rgba(21, 34, 57, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 10px;
  --sidebar-width: 270px;
  --sidebar-collapsed-width: 92px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Plus Jakarta Sans", Inter, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

img,
svg,
canvas {
  max-width: 100%;
  display: block;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.12);
}

textarea {
  resize: vertical;
  min-height: 110px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.04s ease, background 0.2s ease, opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}

.btn:hover {
  opacity: 0.96;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-sm {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  min-height: 36px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-block {
  width: 100%;
}

.muted {
  color: var(--muted);
}

.status-text {
  min-height: 20px;
  color: var(--danger);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}

.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.stack-sm > * + * {
  margin-top: 10px;
}

.stack-md > * + * {
  margin-top: 14px;
}

.stack-lg > * + * {
  margin-top: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stat-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  margin-top: 8px;
  line-height: 1.1;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.22s ease;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.sidebar {
  background: linear-gradient(180deg, #13203b 0%, #17284c 100%);
  color: #e7eefc;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.22s ease, padding 0.22s ease;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 26px;
  min-height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: auto;
  height: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
  flex-shrink: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.brand-logo-only {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  padding: 0 6px;
}

.brand-logo-large {
  width: 150px;
  max-width: 100%;
  height: auto;
  max-height: 44px;
  padding: 0;
  border-radius: 0;
  object-fit: contain;
  object-position: center;
}

.brand-text {
  display: none;
}

.sidebar-toggle {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}

.sidebar-toggle:hover {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.08));
  border-color: rgba(255, 255, 255, 0.16);
}

.sidebar-toggle:active {
  transform: translateY(1px);
}

.sidebar-toggle-bar {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: #ffffff;
  position: absolute;
}

.sidebar-toggle-bar:first-child {
  transform: translateY(-4px);
}

.sidebar-toggle-bar:last-child {
  transform: translateY(4px);
}

.nav-group {
  display: grid;
  gap: 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  color: #d5e1fb;
  transition: background 0.2s ease, color 0.2s ease, transform 0.12s ease;
  word-break: break-word;
  min-height: 48px;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transform: translateX(2px);
}

.nav-link.active {
  background: linear-gradient(180deg, rgba(45, 108, 223, 0.22), rgba(45, 108, 223, 0.14));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.nav-icon {
  width: 22px;
  display: inline-grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar.collapsed .nav-label {
  display: none;
}

.sidebar.collapsed .sidebar-top {
  justify-content: center;
  flex-direction: column;
  gap: 14px;
}

.sidebar.collapsed .brand {
  justify-content: center;
  width: auto;
}

.sidebar.collapsed .brand-logo-large {
  width: 72px;
  height: auto;
  max-height: 24px;
  padding: 0;
  border-radius: 0;
}

.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 12px 10px;
}

.main-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  gap: 14px;
  flex-wrap: nowrap;
  min-width: 0;
}

.topbar > div:first-child {
  min-width: 0;
  flex: 1 1 auto;
}

.topbar > div:first-child strong,
.topbar > div:first-child .muted {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-content {
  padding: 24px;
  display: grid;
  gap: 20px;
  min-width: 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0 0 6px;
  line-height: 1.15;
}

.page-header.split {
  align-items: center;
}

.helper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.section-note {
  color: var(--muted);
  font-size: 0.92rem;
}

hr.soft {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0 0;
}

.word-break {
  word-break: break-word;
}

.nowrap {
  white-space: nowrap;
}

.hide-mobile {
  display: initial;
}

.show-mobile {
  display: none;
}

.badge {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.success {
  background: rgba(15, 157, 122, 0.12);
  color: #0b7c61;
}

.badge.warn {
  background: rgba(217, 142, 26, 0.14);
  color: #a26a0e;
}

.badge.info {
  background: rgba(45, 108, 223, 0.12);
  color: #1f57ba;
}

.badge.danger {
  background: rgba(207, 63, 83, 0.12);
  color: #b13243;
}

.badge.neutral {
  background: rgba(23, 32, 51, 0.08);
  color: var(--text);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}

.table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}

.table th,
.table td,
.data-table th,
.data-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th,
.data-table th {
  color: var(--muted);
  font-weight: 700;
  background: #f9fbff;
}

.table tbody tr:hover,
.data-table tbody tr:hover {
  background: #fbfdff;
}

.table td,
.data-table td {
  word-break: break-word;
}

.action-stack {
  display: grid;
  gap: 12px;
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.action-row .btn {
  width: auto;
}

.chart-box {
  width: 100%;
  min-height: 420px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.chart-box.small {
  min-height: 320px;
}

.status-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 14px;
  border: 1px solid var(--border);
}

.mode-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  min-height: 42px;
}

.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.scan-grid {
  align-items: start;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 18% 20%, rgba(59, 130, 246, 0.14), transparent 22%),
    radial-gradient(circle at 82% 78%, rgba(15, 157, 122, 0.08), transparent 20%),
    linear-gradient(145deg, #08111f 0%, #0d1728 45%, #13203b 100%);
  padding: 20px;
}

.login-shell {
  width: min(1080px, 92vw);
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  border-radius: 30px;
  overflow: hidden;
  box-shadow: 0 28px 70px rgba(4, 10, 22, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.login-panel {
  padding: 42px;
}

.brand-panel {
  background:
    linear-gradient(180deg, rgba(19, 32, 59, 0.78) 0%, rgba(13, 23, 40, 0.78) 100%);
  color: #fff;
}

.login-logo-panel {
  display: grid;
  place-items: center;
  min-height: 560px;
  padding: 48px;
}

.login-brand-logo {
  width: min(420px, 100%);
  height: auto;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.22));
}

.form-panel {
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-left: 1px solid rgba(255, 255, 255, 0.14);
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.form-panel h2,
.form-panel p,
.form-panel form,
.form-panel #loginMessage {
  width: min(520px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.form-panel .muted {
  color: rgba(255, 255, 255, 0.72);
}

.form-panel label {
  color: rgba(255, 255, 255, 0.94);
}

.form-panel input {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.form-panel input::placeholder {
  color: rgba(255, 255, 255, 0.46);
}

.form-panel input:focus {
  border-color: rgba(96, 165, 250, 0.8);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 52px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.password-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.password-toggle:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.9);
  outline-offset: 2px;
}

.form-panel .btn-primary {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.form-panel .btn-primary:hover {
  background: linear-gradient(180deg, #4b8df7 0%, #2d6cdf 100%);
}

.form-panel .status-text {
  color: #ffd4d9;
}

.feature-list {
  padding-left: 18px;
  line-height: 1.8;
}

.mini-table {
  display: grid;
  gap: 12px;
}

.mini-table div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.muted-card {
  background: var(--surface-2);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--border);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 28, 46, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.icon-btn {
  background: none;
  border: 0;
  font-size: 1.4rem;
  cursor: pointer;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 0 auto;
}

.topbar-user > div {
  min-width: 0;
}

.topbar-user > div:last-child strong,
.topbar-user > div:last-child .muted {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex-shrink: 0;
}

.preview-table {
  max-height: 220px;
  overflow: auto;
}

.empty-state {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin-bottom: 16px;
}

.meta-grid p {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
  word-break: break-word;
}

.status-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.active {
  background: #dff6e8;
  color: #147a3f;
}

.status-badge.inactive {
  background: #fbe4e6;
  color: #9b1c31;
}

.mobile-list {
  display: none;
  gap: 12px;
}

.mobile-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

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

.mobile-item-title {
  font-weight: 700;
  word-break: break-word;
}

.mobile-item-body {
  display: grid;
  gap: 8px;
}

.mobile-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.mobile-row span:first-child {
  color: var(--muted);
  font-weight: 600;
  min-width: 90px;
}

.mobile-row span:last-child {
  text-align: right;
  word-break: break-word;
}

.result-focus {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
  border-radius: 12px;
}

#projectsMobileList .mobile-item-title {
  font-size: 1rem;
}

/* Mobile shell */
.mobile-bottom-nav {
  display: none;
}

.mobile-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 28, 46, 0.34);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.mobile-sheet-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.mobile-more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  box-shadow: 0 -18px 40px rgba(21, 34, 57, 0.18);
  z-index: 60;
  transform: translateY(105%);
  transition: transform 0.24s ease;
  padding: 10px 16px 18px;
}

.mobile-more-sheet.show {
  transform: translateY(0);
}

.mobile-sheet-handle {
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: #d7deea;
  margin: 2px auto 12px;
}

.mobile-more-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.mobile-more-sheet-title {
  font-size: 1rem;
  font-weight: 800;
}

.mobile-more-sheet-links {
  display: grid;
  gap: 10px;
}

.mobile-more-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-weight: 700;
}

.mobile-more-link-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-more-link-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

.mobile-more-link.active {
  border-color: rgba(45, 108, 223, 0.25);
  background: rgba(45, 108, 223, 0.06);
}

.mobile-more-link-danger {
  color: var(--danger);
}

.mobile-bottom-link,
.mobile-bottom-btn {
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 8px 4px 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  background: transparent;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.05s ease;
}

.mobile-bottom-link:active,
.mobile-bottom-btn:active {
  transform: translateY(1px);
}

.mobile-bottom-link.active,
.mobile-bottom-btn.active {
  color: var(--primary);
  background: rgba(45, 108, 223, 0.1);
}

.mobile-bottom-icon {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  line-height: 1;
}

.mobile-bottom-link.active .mobile-bottom-icon,
.mobile-bottom-btn.active .mobile-bottom-icon {
  background: rgba(45, 108, 223, 0.12);
}

/* Dashboard */
.dashboard-recent-list {
  display: grid;
  gap: 12px;
}

.dashboard-result-link {
  display: block;
}

.dashboard-result-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.dashboard-result-link:hover .dashboard-result-item {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
  border-color: rgba(45, 108, 223, 0.22);
  background: #f8fbff;
}

.dashboard-result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.dashboard-result-id {
  word-break: break-word;
}

.dashboard-result-meta {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  word-break: break-word;
}

.dashboard-result-meta + .dashboard-result-meta {
  margin-top: 6px;
}

/* Results */
.results-toolbar-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

.results-toolbar-compact .field-grow {
  flex: 2 1 220px;
}

.results-toolbar-compact .field-mid {
  flex: 1 1 140px;
}

.results-toolbar-compact .field-auto {
  flex: 0 0 auto;
}

.results-mobile-toolbar {
  display: none;
}

.results-mobile-list-gmail {
  display: none;
}

.results-summary-row {
  margin-bottom: 16px;
}

.result-row-clickable {
  cursor: pointer;
}

.result-row-clickable:hover {
  background: rgba(255, 255, 255, 0.06);
}

.result-card-clickable {
  cursor: pointer;
}

/* Scan page */
.scan-page-content {
  gap: 18px;
}

.scan-hero-grid {
  display: grid;
  grid-template-columns: minmax(340px, 720px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.scan-advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.scan-card-head-tight {
  margin-bottom: 8px;
}

.scan-status-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.scan-status-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  min-width: 0;
}

.scan-chip-label {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.scan-chip-value {
  display: block;
  font-weight: 800;
  font-size: 0.98rem;
  word-break: break-word;
}

.status-panel-prominent {
  border: 1px solid rgba(45, 108, 223, 0.18);
  background: linear-gradient(180deg, rgba(45, 108, 223, 0.06), rgba(45, 108, 223, 0.02));
}

.status-panel-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.status-panel-message {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  word-break: break-word;
}

.status-panel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.scan-chart-box {
  min-height: 420px;
}

.mini-table-soft {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 8px;
}

.disclosure-card {
  padding: 0;
  overflow: hidden;
}

.disclosure-card summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
}

.disclosure-card summary::-webkit-details-marker {
  display: none;
}

.disclosure-body {
  padding: 0 20px 20px;
}

.disclosure-indicator {
  font-size: 1rem;
  color: var(--muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.disclosure-card[open] .disclosure-indicator {
  transform: rotate(180deg);
}

.serial-mono {
  font-family: Consolas, "Courier New", monospace;
  word-break: break-word;
}

.scan-action-row .btn {
  flex: 1 1 160px;
}

.scan-action-sticky {
  position: static;
}

.preview-table {
  max-height: 260px;
  overflow: auto;
}

.is-hidden {
  display: none !important;
}

/* Large tablet */
@media (max-width: 1200px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }

  .chart-box {
    min-height: 360px;
  }

  .chart-box.small {
    min-height: 300px;
  }

  .scan-hero-grid {
    grid-template-columns: 1fr;
  }

  .scan-chart-box {
    min-height: 360px;
  }
}

/* Tablet */
@media (max-width: 980px) {
  .app-shell,
  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .grid-2,
  .grid-3,
  .stat-grid,
  .login-shell,
  .grid-form,
  .meta-grid,
  .scan-advanced-grid {
    grid-template-columns: 1fr;
  }

  .main-shell {
    min-width: 0;
  }

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

  .login-logo-panel {
    min-height: 220px;
    padding: 32px;
  }

  .login-brand-logo {
    width: min(240px, 68%);
  }

  .form-panel {
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }

  .topbar {
    top: 0;
    z-index: 48;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 14px 18px;
  }

  .page-content {
    padding: 18px;
    gap: 20px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-box {
    min-height: 320px;
  }

  .chart-box.small {
    min-height: 280px;
  }

  .table,
  .data-table {
    min-width: 620px;
  }

  .hide-mobile {
    display: none !important;
  }

  .show-mobile {
    display: initial !important;
  }

  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    top: auto;
    transform: translateZ(0);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(217, 225, 239, 0.9);
    border-radius: 22px;
    box-shadow: 0 12px 28px rgba(21, 34, 57, 0.12);
    z-index: 1000;
    padding: 6px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }

  .results-desktop-toolbar,
  .desktop-table {
    display: none !important;
  }

  .results-mobile-toolbar,
  .results-mobile-list-gmail {
    display: grid;
  }

  .results-mobile-toolbar {
    gap: 10px;
    margin-bottom: 16px;
  }

  .results-mobile-toolbar-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
  }

  .results-mobile-toolbar-row.filters-2 {
    grid-template-columns: 1fr 1fr;
  }

  #resultsPagination {
    display: none !important;
  }

  .results-mobile-list-gmail {
    gap: 12px;
  }

  .results-mobile-list-gmail .mobile-item {
    border-radius: 14px;
    padding: 12px 14px;
  }

  .results-mobile-list-gmail .mobile-item-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: start;
    margin-bottom: 6px;
  }

  .results-mobile-check {
    margin-top: 2px;
  }

  .results-mobile-main {
    min-width: 0;
  }

  .results-mobile-title-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
    margin-bottom: 2px;
  }

  .results-mobile-title {
    font-weight: 800;
    font-size: 0.95rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .results-mobile-date {
    font-size: 0.74rem;
    color: var(--muted);
    white-space: nowrap;
  }

  .results-mobile-subject {
    font-size: 0.83rem;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .results-mobile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    font-size: 0.76rem;
    color: var(--muted);
  }

  .results-mobile-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
  }

  .results-mobile-actions .btn {
    padding: 8px 10px;
    width: auto;
  }

  .results-mobile-inline-badge {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    background: rgba(45, 108, 223, 0.1);
    color: var(--primary);
  }

  .results-mobile-list-gmail .mobile-item-body {
    display: block;
  }

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

/* Phone */
@media (max-width: 640px) {
  .login-body {
    padding: 12px;
  }

  .login-panel {
    padding: 24px 20px;
  }

  .login-logo-panel {
    min-height: 180px;
    padding: 24px;
  }

  .login-brand-logo {
    width: min(210px, 70%);
  }

  .card {
    padding: 16px;
    border-radius: 16px;
  }

  .page-content {
    padding: 14px;
    gap: 16px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .topbar {
    padding: 12px 14px;
  }

  .dashboard-result-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-box {
    min-height: 260px;
  }

  .chart-box.small {
    min-height: 220px;
  }

  .btn,
  .btn-sm {
    width: 100%;
  }

  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .mode-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .mode-btn {
    width: 100%;
  }

  .table,
  .data-table {
    min-width: 540px;
  }

  .brand-mark {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
  }

  .stat-value {
    font-size: 1.45rem;
  }

  .mobile-row {
    flex-direction: column;
    gap: 4px;
  }

  .mobile-row span:last-child {
    text-align: left;
  }

  .scan-status-board {
    grid-template-columns: 1fr 1fr;
  }

  .scan-chart-box {
    min-height: 320px;
  }

  .disclosure-card summary {
    padding: 16px;
  }

  .disclosure-body {
    padding: 0 16px 16px;
  }

  .scan-action-sticky {
    position: sticky;
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 12;
    background: rgba(245, 247, 251, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding-top: 10px;
  }
}

/* Very small phone */
@media (max-width: 420px) {
  .page-content {
    padding: 12px;
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  .topbar {
    padding: 10px 12px;
  }

  .card {
    padding: 14px;
  }

  .mode-group {
    grid-template-columns: 1fr;
  }

  .chart-box {
    min-height: 220px;
  }

  .chart-box.small {
    min-height: 200px;
  }

  .scan-status-board {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  body {
    padding-bottom: calc(110px + env(safe-area-inset-bottom));
  }
}

/* =========================================================
   APTSENS GLOBAL VISUAL THEME OVERRIDES
   ========================================================= */

:root {
  --bg: #0d1728;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-2: rgba(255, 255, 255, 0.12);
  --surface-3: rgba(255, 255, 255, 0.18);
  --text: #eaf2ff;
  --muted: rgba(234, 242, 255, 0.68);
  --border: rgba(255, 255, 255, 0.14);
  --primary: #3b82f6;
  --primary-strong: #2563eb;
  --accent: #14b8a6;
  --danger: #ef5a72;
  --warning: #f3a63b;
  --shadow: 0 16px 40px rgba(4, 10, 22, 0.28);
  --shadow-soft: 0 10px 28px rgba(4, 10, 22, 0.18);
}

/* Base background */
html,
body {
  background:
    radial-gradient(circle at 15% 18%, rgba(59, 130, 246, 0.14), transparent 22%),
    radial-gradient(circle at 82% 78%, rgba(20, 184, 166, 0.08), transparent 20%),
    linear-gradient(145deg, #08111f 0%, #0d1728 45%, #13203b 100%);
  color: var(--text);
}

/* Keep login page as-is if already styled */
body.login-body {
  background:
    radial-gradient(circle at 18% 20%, rgba(59, 130, 246, 0.14), transparent 22%),
    radial-gradient(circle at 82% 78%, rgba(15, 157, 122, 0.08), transparent 20%),
    linear-gradient(145deg, #08111f 0%, #0d1728 45%, #13203b 100%);
}

/* App shell surfaces */
.main-shell {
  background: transparent;
}

.page-content {
  background: transparent;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, rgba(11, 20, 38, 0.94) 0%, rgba(18, 32, 59, 0.94) 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 18px 0 40px rgba(4, 10, 22, 0.16);
}

.nav-link {
  color: rgba(231, 238, 252, 0.8);
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.nav-link.active {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.24), rgba(59, 130, 246, 0.14));
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 8px 24px rgba(37, 99, 235, 0.14);
}

.sidebar-toggle {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06));
}

/* Topbar */
.topbar {
  background: rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 10px 26px rgba(4, 10, 22, 0.12);
}

.topbar strong {
  color: #ffffff;
}

.topbar .muted {
  color: rgba(234, 242, 255, 0.68);
}

.avatar {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
}

/* Generic cards */
.card,
.stat-card,
.mobile-item,
.muted-card,
.modal-card {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.card-head h2,
.card-head h3,
.page-header h1,
.mobile-item-title {
  color: #ffffff;
}

.section-note,
.muted,
.stat-label,
.dashboard-result-meta,
.mobile-row span:first-child {
  color: rgba(234, 242, 255, 0.68);
}

.stat-value,
.scan-chip-value,
.dashboard-result-id {
  color: #ffffff;
}

/* Inputs / selects / textarea */
input,
select,
textarea {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

input::placeholder,
textarea::placeholder {
  color: rgba(234, 242, 255, 0.42);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(96, 165, 250, 0.78);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

label {
  color: rgba(255, 255, 255, 0.92);
}

/* Buttons */
.btn-primary {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #4b8df7 0%, #2d6cdf 100%);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
}

.btn-danger {
  background: linear-gradient(180deg, #f26a80 0%, #d9485f 100%);
  color: #ffffff;
}

/* Badges */
.badge.success {
  background: rgba(20, 184, 166, 0.14);
  color: #86fff0;
}

.badge.warn {
  background: rgba(243, 166, 59, 0.14);
  color: #ffd08c;
}

.badge.info {
  background: rgba(59, 130, 246, 0.16);
  color: #b7d3ff;
}

.badge.danger {
  background: rgba(239, 90, 114, 0.16);
  color: #ffc1cb;
}

.badge.neutral {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

/* Tables */
.table-wrap {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.table,
.data-table {
  background: transparent;
  color: #ffffff;
}

.table th,
.data-table th {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(234, 242, 255, 0.68);
}

.table td,
.data-table td,
.table th,
.data-table th {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.table tbody tr:hover,
.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

/* Panels and status boxes */
.status-panel,
.scan-status-chip,
.meta-grid p {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.empty-state,
.status-text {
  color: rgba(234, 242, 255, 0.72);
}

hr.soft {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Chart containers */
.chart-box,
.chart-box.small {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Dashboard recent cards */
.dashboard-result-item {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.dashboard-result-link:hover .dashboard-result-item {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(96, 165, 250, 0.28);
}

/* Mobile nav */
.mobile-bottom-nav {
  background: rgba(255, 255, 255, 0.12) !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 36px rgba(4, 10, 22, 0.22);
}

.mobile-bottom-link,
.mobile-bottom-btn {
  color: rgba(234, 242, 255, 0.68);
}

.mobile-bottom-link.active,
.mobile-bottom-btn.active {
  color: #ffffff;
  background: rgba(59, 130, 246, 0.18);
}

.mobile-bottom-link.active .mobile-bottom-icon,
.mobile-bottom-btn.active .mobile-bottom-icon {
  background: rgba(59, 130, 246, 0.2);
}

/* More sheet */
.mobile-more-sheet {
  background: rgba(16, 25, 44, 0.92);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.mobile-sheet-handle {
  background: rgba(255, 255, 255, 0.22);
}

.mobile-more-sheet-title {
  color: #ffffff;
}

.mobile-more-link {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.mobile-more-link-icon {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.mobile-more-link.active {
  border-color: rgba(96, 165, 250, 0.3);
  background: rgba(59, 130, 246, 0.14);
}

.mobile-more-link-danger {
  color: #ffb5c0;
}

/* Password eye stays readable on glass forms */
.password-toggle {
  color: rgba(255, 255, 255, 0.76);
}

.password-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

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

*::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* Projects page mobile visibility */
@media (max-width: 980px) {
  #projectsTableWrap {
    display: none !important;
  }

  #projectsMobileList {
    display: grid !important;
    gap: 12px;
  }
}

@media (min-width: 981px) {
  #projectsMobileList {
    display: none !important;
  }
}

/* =========================================================
   LIGHT THEME
   ========================================================= */

html[data-theme="light"] {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f4fa;
  --surface-3: #e8eef8;
  --text: #172033;
  --muted: #65708a;
  --border: #d9e1ef;
  --primary: #2d6cdf;
  --primary-strong: #1f57ba;
  --accent: #0f9d7a;
  --danger: #cf3f53;
  --warning: #d98e1a;
  --shadow: 0 10px 30px rgba(21, 34, 57, 0.08);
  --shadow-soft: 0 6px 18px rgba(21, 34, 57, 0.06);
}

html[data-theme="light"],
html[data-theme="light"] body {
  background: var(--bg) !important;
  color: var(--text);
}

html[data-theme="light"] .main-shell,
html[data-theme="light"] .page-content {
  background: transparent;
}

html[data-theme="light"] .sidebar {
  background: linear-gradient(180deg, #13203b 0%, #17284c 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: none;
}

html[data-theme="light"] .nav-link {
  color: #d5e1fb;
}

html[data-theme="light"] .nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

html[data-theme="light"] .nav-link.active {
  background: linear-gradient(180deg, rgba(45, 108, 223, 0.22), rgba(45, 108, 223, 0.14));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

html[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 10px 26px rgba(4, 10, 22, 0.08);
}

html[data-theme="light"] .topbar strong {
  color: var(--text);
}

html[data-theme="light"] .topbar .muted {
  color: var(--muted);
}

html[data-theme="light"] .card,
html[data-theme="light"] .stat-card,
html[data-theme="light"] .mobile-item,
html[data-theme="light"] .muted-card,
html[data-theme="light"] .modal-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: var(--shadow);
}

html[data-theme="light"] .card-head h2,
html[data-theme="light"] .card-head h3,
html[data-theme="light"] .page-header h1,
html[data-theme="light"] .mobile-item-title,
html[data-theme="light"] .stat-value,
html[data-theme="light"] .scan-chip-value,
html[data-theme="light"] .dashboard-result-id {
  color: var(--text);
}

html[data-theme="light"] .section-note,
html[data-theme="light"] .muted,
html[data-theme="light"] .stat-label,
html[data-theme="light"] .dashboard-result-meta,
html[data-theme="light"] .mobile-row span:first-child,
html[data-theme="light"] .empty-state,
html[data-theme="light"] .status-text {
  color: var(--muted);
}

html[data-theme="light"] input,
html[data-theme="light"] select,
html[data-theme="light"] textarea {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder {
  color: rgba(23, 32, 51, 0.42);
}

html[data-theme="light"] label {
  color: var(--text);
}

html[data-theme="light"] .btn-primary {
  background: linear-gradient(180deg, #2d6cdf 0%, #1f57ba 100%);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.16);
}

html[data-theme="light"] .btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

html[data-theme="light"] .btn-danger {
  background: linear-gradient(180deg, #f26a80 0%, #d9485f 100%);
  color: #fff;
}

html[data-theme="light"] .badge.success {
  background: rgba(15, 157, 122, 0.12);
  color: #0b7c61;
}

html[data-theme="light"] .badge.warn {
  background: rgba(217, 142, 26, 0.14);
  color: #a26a0e;
}

html[data-theme="light"] .badge.info {
  background: rgba(45, 108, 223, 0.12);
  color: #1f57ba;
}

html[data-theme="light"] .badge.danger {
  background: rgba(207, 63, 83, 0.12);
  color: #b13243;
}

html[data-theme="light"] .badge.neutral {
  background: rgba(23, 32, 51, 0.08);
  color: var(--text);
}

html[data-theme="light"] .table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

html[data-theme="light"] .table,
html[data-theme="light"] .data-table {
  background: #fff;
  color: var(--text);
}

html[data-theme="light"] .table th,
html[data-theme="light"] .data-table th {
  background: #f9fbff;
  color: var(--muted);
}

html[data-theme="light"] .table td,
html[data-theme="light"] .data-table td,
html[data-theme="light"] .table th,
html[data-theme="light"] .data-table th {
  border-bottom: 1px solid var(--border);
}

html[data-theme="light"] .table tbody tr:hover,
html[data-theme="light"] .data-table tbody tr:hover {
  background: #fbfdff;
}

html[data-theme="light"] .status-panel,
html[data-theme="light"] .scan-status-chip,
html[data-theme="light"] .meta-grid p {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

html[data-theme="light"] .chart-box,
html[data-theme="light"] .chart-box.small {
  background: #fff;
  border: 1px solid var(--border);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

html[data-theme="light"] .dashboard-result-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

html[data-theme="light"] .dashboard-result-link:hover .dashboard-result-item {
  background: #f8fbff;
  border-color: rgba(45, 108, 223, 0.22);
}

html[data-theme="light"] .mobile-bottom-nav {
  background: rgba(255, 255, 255, 0.96) !important;
  border: 1px solid rgba(217, 225, 239, 0.9) !important;
  box-shadow: 0 12px 28px rgba(21, 34, 57, 0.12);
}

html[data-theme="light"] .mobile-bottom-link,
html[data-theme="light"] .mobile-bottom-btn {
  color: var(--muted);
}

html[data-theme="light"] .mobile-bottom-link.active,
html[data-theme="light"] .mobile-bottom-btn.active {
  color: var(--primary);
  background: rgba(45, 108, 223, 0.1);
}

html[data-theme="light"] .mobile-bottom-link.active .mobile-bottom-icon,
html[data-theme="light"] .mobile-bottom-btn.active .mobile-bottom-icon {
  background: rgba(45, 108, 223, 0.12);
}

html[data-theme="light"] .mobile-more-sheet {
  background: #fff;
  border-top: 1px solid var(--border);
}

html[data-theme="light"] .mobile-sheet-handle {
  background: #d7deea;
}

html[data-theme="light"] .mobile-more-sheet-title {
  color: var(--text);
}

html[data-theme="light"] .mobile-more-link {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

html[data-theme="light"] .mobile-more-link-icon {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
}

html[data-theme="light"] .mobile-more-link.active {
  border-color: rgba(45, 108, 223, 0.25);
  background: rgba(45, 108, 223, 0.06);
}

html[data-theme="light"] .mobile-more-link-danger {
  color: var(--danger);
}

/* Safety: mobile overlays must never block desktop pages */
@media (min-width: 981px) {
  .mobile-sheet-overlay,
  .mobile-more-sheet,
  .mobile-bottom-nav {
    display: none !important;
    pointer-events: none !important;
  }

  .mobile-sheet-overlay.show,
  .mobile-more-sheet.show {
    display: none !important;
    pointer-events: none !important;
    opacity: 0 !important;
    transform: translateY(105%) !important;
  }
}

/* PWA install button */
.install-pwa-btn {
  display: none;
  margin-top: 12px;
  background: linear-gradient(180deg, rgba(20, 184, 166, 0.95), rgba(15, 157, 122, 0.95));
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 14px 30px rgba(15, 157, 122, 0.22);
}

.install-pwa-btn::before {
  content: "⇩";
  font-size: 1rem;
  line-height: 1;
}

.install-pwa-btn:hover {
  background: linear-gradient(180deg, rgba(31, 201, 182, 0.98), rgba(17, 173, 134, 0.98));
}

.install-help-text {
  margin-top: 10px;
  font-size: 0.85rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.72);
}

/* Show install button only on phone/tablet size */
@media (max-width: 980px) {
  .install-pwa-btn {
    display: inline-flex;
  }
}

html[data-theme="light"] .install-pwa-btn {
  background: linear-gradient(180deg, #14b8a6, #0f9d7a);
  color: #ffffff;
  border: 1px solid rgba(15, 157, 122, 0.18);
  box-shadow: 0 12px 26px rgba(15, 157, 122, 0.16);
}

html[data-theme="light"] .install-help-text {
  color: var(--muted);
}
.hidden {
  display: none !important;
}

.onboarding-shell {
  width: min(1180px, 94vw);
  grid-template-columns: 0.9fr 1.6fr;
}

.onboarding-panel {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.form-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface-2);
}

.form-section h2,
.form-section h3 {
  margin: 0 0 14px;
}

input[readonly] {
  cursor: not-allowed;
  opacity: 0.82;
}

/* =========================================================
   First-time onboarding page
   ========================================================= */

.onboarding-body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(45, 108, 223, 0.25), transparent 35%),
    radial-gradient(circle at bottom right, rgba(27, 42, 78, 0.8), transparent 42%),
    var(--bg);
  color: var(--text);
}

.onboarding-page {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0;
}

.onboarding-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.onboarding-brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.onboarding-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 24px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
}

.onboarding-brand h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  line-height: 1.1;
}

.onboarding-brand p {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 560px;
}

.onboarding-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow-sm);
}

.onboarding-step {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.onboarding-step span {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  border: 1px solid var(--border);
}

.onboarding-step small {
  font-weight: 700;
}

.onboarding-step.active {
  color: var(--text);
}

.onboarding-step.active span {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.onboarding-line {
  width: 48px;
  height: 2px;
  background: var(--border);
}

.onboarding-card {
  border: 1px solid var(--border);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03)),
    var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 36px);
}

.onboarding-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
}

.onboarding-card-head h2 {
  margin: 6px 0 0;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
}

.onboarding-form {
  display: grid;
  gap: 20px;
}

.onboarding-form.hidden {
  display: none;
}

.form-grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.onboarding-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
}

.onboarding-form input,
.onboarding-form textarea,
.onboarding-form select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
  font: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.onboarding-form input:focus,
.onboarding-form textarea:focus,
.onboarding-form select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(45, 108, 223, 0.18);
}

.onboarding-form input[readonly] {
  opacity: 0.85;
  cursor: not-allowed;
}

.onboarding-section-title {
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.onboarding-section-title h3 {
  margin: 0;
  font-size: 1.05rem;
}

.onboarding-section-title p {
  margin: 6px 0 0;
  color: var(--muted);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.form-status {
  margin: 0 auto 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 860px) {
  .onboarding-page {
    width: min(100% - 24px, 720px);
    padding: 24px 0;
  }

  .onboarding-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .onboarding-progress {
    width: 100%;
    justify-content: center;
  }

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

  .onboarding-card-head {
    flex-direction: column;
  }

  .form-actions {
    justify-content: stretch;
  }

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

  .form-status {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .onboarding-brand {
    align-items: flex-start;
  }

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

  .onboarding-progress {
    border-radius: 20px;
  }

  .onboarding-line {
    width: 28px;
  }

  .onboarding-step small {
    display: none;
  }

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

/* Project setup options in Add User modal */
.radio-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
}

.radio-line input[type="radio"] {
  width: auto;
}

/* Project edit modal helpers */
.btn:disabled,
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#editProjectLimitNote {
  margin-top: 4px;
}

#editProjectSpe[readonly] {
  opacity: 0.85;
  cursor: not-allowed;
}


/* Scan console refresh */
.scan-console-layout {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}
.scan-control-card,
.scan-plot-card,
.scan-buffer-card {
  min-height: 100%;
}
.scan-control-buttons .btn {
  width: 100%;
}
.reader-message {
  position: relative;
  border-radius: 16px;
  padding: 1rem 1.1rem 1rem 3rem;
  font-weight: 700;
  line-height: 1.5;
  border: 1px solid var(--border, #d7dfeb);
  background: var(--surface-2, #f5f7fb);
  box-shadow: inset 4px 0 0 transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.reader-message::before {
  content: "";
  position: absolute;
  left: 1rem;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  transform: translateY(-50%);
  background: currentColor;
  opacity: 0.95;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.35);
}
.reader-message-idle {
  color: #1d4ed8;
  background: rgba(59,130,246,0.10);
  border-color: rgba(59,130,246,0.28);
  box-shadow: inset 4px 0 0 rgba(59,130,246,0.85);
}
.reader-message-success {
  color: #047857;
  background: rgba(16,185,129,0.12);
  border-color: rgba(16,185,129,0.32);
  box-shadow: inset 4px 0 0 rgba(16,185,129,0.9);
}
.reader-message-warning {
  color: #b45309;
  background: rgba(245,158,11,0.14);
  border-color: rgba(245,158,11,0.34);
  box-shadow: inset 4px 0 0 rgba(245,158,11,0.9);
}
.reader-message-error {
  color: #b91c1c;
  background: rgba(239,68,68,0.14);
  border-color: rgba(239,68,68,0.34);
  box-shadow: inset 4px 0 0 rgba(239,68,68,0.95);
}
[data-theme="dark"] .reader-message-idle {
  color: #93c5fd;
}
[data-theme="dark"] .reader-message-success {
  color: #86efac;
}
[data-theme="dark"] .reader-message-warning {
  color: #fcd34d;
}
[data-theme="dark"] .reader-message-error {
  color: #fca5a5;
}
.buffer-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border-radius: 14px;
  border: 1px solid var(--border, #d7dfeb);
  background: var(--surface-2, #f8fafc);
  padding: 0.9rem 1rem;
  font: 500 0.92rem/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  color: inherit;
}
@media (max-width: 900px) {
  .scan-console-layout {
    grid-template-columns: 1fr;
  }
}

.scan-control-buttons .btn:disabled {
  cursor: wait;
  opacity: 0.68;
}


/* Result detail report layout */
.result-report-layout {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}
.result-report-left {
  min-width: 0;
}
.result-chemical-card,
.result-project-card,
.result-remarks-card,
.result-report-main {
  border: 1px solid var(--primary, #2d6cdf);
}
.result-chemical-card {
  text-align: center;
  padding-bottom: 16px;
}
.result-gauge-wrap {
  max-width: 220px;
  margin: 0 auto 10px;
}
.result-gauge {
  position: relative;
  height: 105px;
  overflow: hidden;
  border-radius: 120px 120px 0 0;
  background: conic-gradient(from 270deg at 50% 100%, #e11d48 0deg 32deg, #ef4444 32deg 56deg, #f97316 56deg 82deg, #f59e0b 82deg 112deg, #84cc16 112deg 138deg, #22c55e 138deg 162deg, #15803d 162deg 180deg, transparent 180deg 360deg);
}
.result-gauge-hole {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 128px;
  height: 64px;
  transform: translateX(-50%);
  border-radius: 128px 128px 0 0;
  background: var(--surface, #fff);
  box-shadow: inset 0 6px 10px rgba(15, 23, 42, 0.12);
}
.result-gauge-needle {
  position: absolute;
  left: 50%;
  bottom: 8px;
  width: 4px;
  height: 68px;
  border-radius: 999px;
  background: #111827;
  transform-origin: 50% 100%;
  transform: translateX(-50%) rotate(var(--gauge-angle, 0deg));
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.3);
}
.result-gauge-needle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #111827;
  border: 3px solid var(--surface, #fff);
  transform: translateX(-50%);
}
.result-gauge-labels {
  display: flex;
  justify-content: space-between;
  padding: 0 22px;
  margin-top: 3px;
  font-size: 0.65rem;
  font-weight: 800;
}
.result-gauge-labels span:first-child { color: #e11d48; }
.result-gauge-labels span:last-child { color: #15803d; }
.result-concentration-block {
  margin-top: 12px;
}
.result-concentration-label {
  font-weight: 800;
  letter-spacing: 0.02em;
}
.result-concentration-value {
  margin-top: 4px;
  font-weight: 800;
  font-size: 1.15rem;
}
.result-mini-metrics {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  margin-top: 12px;
  text-align: left;
  font-size: 0.92rem;
}
.result-project-card h2 {
  margin: 0 0 10px;
  font-size: 0.98rem;
}
.result-project-meta {
  display: grid;
  gap: 4px;
}
.result-project-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  font-size: 0.9rem;
}
.result-project-row span {
  color: var(--text, #111827);
}
.result-project-row strong {
  overflow-wrap: anywhere;
}
.result-remarks-card textarea {
  min-height: 92px;
}
.result-report-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 560px;
}
.result-report-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
}
.result-subject-edit label {
  font-weight: 800;
}
.result-subject-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}
.result-subject-row input {
  min-width: 0;
}
.result-id-block {
  text-align: right;
  font-size: 0.92rem;
}
.result-chart-frame {
  flex: 1;
  min-height: 390px;
  border: 1px solid var(--border, #d7dfeb);
  display: flex;
}
.result-detail-chart {
  min-height: 390px;
  width: 100%;
}
.result-report-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-top: 12px;
  text-align: right;
  font-size: 0.92rem;
}
@media (max-width: 980px) {
  .result-report-layout {
    grid-template-columns: 1fr;
  }
  .result-report-topbar {
    grid-template-columns: 1fr;
  }
  .result-id-block,
  .result-report-footer {
    text-align: left;
  }
}
@media (max-width: 560px) {
  .result-subject-row {
    flex-direction: column;
    align-items: stretch;
  }
  .result-project-row {
    grid-template-columns: 1fr;
    gap: 0;
  }
}


/* =========================================================
   Theme mode refinements
   ========================================================= */
html[data-theme="dark"] {
  --bg: #050505;
  --surface: #111111;
  --surface-2: #1a1a1a;
  --surface-3: #242424;
  --text: #f4f4f5;
  --muted: #b7bbc3;
  --border: #303030;
  --primary: #4f8cff;
  --primary-strong: #78a8ff;
  --accent: #22c55e;
  --danger: #fb7185;
  --warning: #fbbf24;
  --shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.34);
}

html[data-theme="dark"] body {
  background: var(--bg);
  color: var(--text);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .modal-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .table,
html[data-theme="dark"] .data-table,
html[data-theme="dark"] .chart-box {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

html[data-theme="dark"] input[readonly],
html[data-theme="dark"] textarea[readonly] {
  background: var(--surface-2);
  color: var(--muted);
}

html[data-theme="dark"] .table th,
html[data-theme="dark"] .data-table th {
  background: var(--surface-2);
  color: var(--muted);
}

html[data-theme="dark"] .table tbody tr:hover,
html[data-theme="dark"] .data-table tbody tr:hover {
  background: var(--surface-2);
}

html[data-theme="dark"] .topbar {
  background: rgba(17, 17, 17, 0.92);
  border-bottom-color: var(--border);
}

html[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #000000 0%, #111111 100%);
  border-right-color: #2a2a2a;
}

html[data-theme="dark"] .nav-link {
  color: #d4d4d8;
}

html[data-theme="dark"] .nav-link:hover,
html[data-theme="dark"] .nav-link.active {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .status-panel,
html[data-theme="dark"] .form-section,
html[data-theme="dark"] .project-mobile-card,
html[data-theme="dark"] .mobile-more-link {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .muted {
  color: var(--muted);
}

html[data-theme="dark"] .badge.info {
  background: rgba(79, 140, 255, 0.18);
  color: #9ec1ff;
}

html[data-theme="dark"] .badge.success {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

html[data-theme="dark"] .badge.warn {
  background: rgba(251, 191, 36, 0.18);
  color: #fde68a;
}

html[data-theme="dark"] .badge.danger {
  background: rgba(251, 113, 133, 0.18);
  color: #fda4af;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-left > div:first-child {
  min-width: 0;
}

.theme-toggle {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  min-height: 38px;
  padding: 5px 10px 5px 5px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.theme-toggle-knob {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--border);
  position: relative;
}

.theme-toggle-knob::before {
  content: "☀";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
}

.theme-toggle.is-dark .theme-toggle-knob {
  background: #000000;
  border-color: #404040;
  color: #ffffff;
}

.theme-toggle.is-dark .theme-toggle-knob::before {
  content: "☾";
}

.theme-toggle-text {
  font-size: 0.82rem;
}

.profile-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.profile-summary-grid > div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  min-width: 0;
}

.profile-summary-wide {
  grid-column: 1 / -1;
}

.profile-summary-label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 800;
}

.profile-summary-grid strong {
  display: block;
  word-break: break-word;
}

@media (max-width: 720px) {
  .topbar-left {
    gap: 10px;
  }

  .theme-toggle-text {
    display: none;
  }

  .profile-summary-grid {
    grid-template-columns: 1fr;
  }
}


/* Scan trigger method */
.scan-trigger-console .muted {
  margin: 0;
}
.trigger-choice-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.trigger-choice-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
  cursor: pointer;
}
.trigger-choice-card input {
  width: auto;
  margin-top: 4px;
}
.trigger-choice-card strong {
  display: block;
  margin-bottom: 4px;
}
.trigger-choice-card small {
  display: block;
  color: var(--muted);
  line-height: 1.45;
}
.trigger-choice-card:has(input:checked) {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45,108,223,0.14);
}
.scan-trigger-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #1d4ed8;
  background: rgba(59,130,246,0.10);
  border: 1px solid rgba(59,130,246,0.24);
}
.scan-trigger-pill.is-web-app {
  color: #047857;
  background: rgba(16,185,129,0.12);
  border-color: rgba(16,185,129,0.28);
}
[data-theme="dark"] .scan-trigger-pill {
  color: #93c5fd;
}
[data-theme="dark"] .scan-trigger-pill.is-web-app {
  color: #86efac;
}

.scan-method-field small {
  display: block;
  margin-top: 6px;
  line-height: 1.35;
}
.scan-method-field select:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}


/* Scan method button selector */
.scan-method-button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.45rem;
}
.scan-method-btn {
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border, #d7dfeb);
  background: var(--surface-2, #f8fafc);
  color: var(--text, #13203b);
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.scan-method-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(45,108,223,0.55);
  box-shadow: 0 8px 20px rgba(15,23,42,0.08);
}
.scan-method-btn.is-active {
  background: var(--primary, #2d6cdf);
  border-color: var(--primary, #2d6cdf);
  color: #fff;
  box-shadow: 0 10px 24px rgba(45,108,223,0.24);
}
.scan-method-btn.is-empty {
  cursor: default;
  opacity: 0.35;
  background: transparent;
  border-style: dashed;
  box-shadow: none;
}
.scan-method-btn:disabled:not(.is-empty) {
  cursor: wait;
  opacity: 0.68;
}
[data-theme="dark"] .scan-method-btn {
  background: #111111;
  color: #f5f5f5;
  border-color: #2f2f2f;
}
[data-theme="dark"] .scan-method-btn.is-active {
  background: var(--primary, #2d6cdf);
  border-color: var(--primary, #2d6cdf);
  color: #fff;
}
[data-theme="dark"] .scan-method-btn.is-empty {
  background: transparent;
}


/* Web-app scan trigger buttons */
.scan-method-field {
  margin-top: 0;
}
.scan-method-button-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.scan-method-btn {
  min-height: 46px;
  font-weight: 800;
}
.scan-method-btn:not(.is-empty):not(:disabled) {
  cursor: pointer;
}
.scan-method-btn:not(.is-empty):not(:disabled):hover {
  transform: translateY(-1px);
}


/* Sidebar polish + version */
.sidebar {
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.sidebar-top {
  position: relative;
}

.nav-group {
  flex: 1 1 auto;
  align-content: start;
}

.sidebar-toggle {
  overflow: hidden;
}

.sidebar-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 1.65rem;
  font-weight: 800;
  line-height: 1;
  transform: translateX(-1px);
  transition: transform 0.22s ease;
}

.sidebar.collapsed .sidebar-toggle-icon {
  transform: rotate(180deg) translateX(-1px);
}

.sidebar.collapsed .sidebar-toggle {
  width: 40px;
  height: 40px;
  border-radius: 999px;
}

.sidebar-version {
  margin-top: auto;
  padding: 12px 10px 4px;
  color: rgba(231, 238, 252, 0.72);
  font-size: 0.78rem;
  line-height: 1.35;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-version-number {
  font-weight: 800;
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-version {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.sidebar.collapsed .sidebar-version-label {
  display: none;
}

.sidebar.collapsed .sidebar-version-number {
  padding: 4px 7px;
  font-size: 0.72rem;
}

.results-summary-row {
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.results-summary-row #downloadSelectedResultsBtn {
  white-space: nowrap;
}

@media (max-width: 640px) {
  .results-summary-row {
    align-items: stretch;
  }
  .results-summary-row #downloadSelectedResultsBtn {
    width: 100%;
  }
}


/* Sidebar polish v0.30 */
.sidebar {
  padding: 18px 14px 14px;
}
.sidebar-top {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 10px;
  min-height: 72px;
  margin-bottom: 22px;
}
.brand-logo-only {
  min-height: 58px;
  padding: 0;
  justify-content: flex-start;
}
.brand-logo-large {
  display: block;
  width: 166px;
  max-height: 50px;
  margin: 0 auto 0 0;
}
.sidebar-toggle {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 10px 26px rgba(0,0,0,0.16), inset 0 1px 0 rgba(255,255,255,0.08);
}
.sidebar-toggle:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,0.16);
}
.sidebar-toggle-icon {
  font-size: 1.35rem;
  transform: none;
}
.sidebar.collapsed .sidebar-top {
  grid-template-columns: 1fr;
  gap: 12px;
  justify-items: center;
  min-height: 112px;
  margin-bottom: 18px;
}
.sidebar.collapsed .brand-logo-only {
  width: 100%;
  min-height: 50px;
  justify-content: center;
}
.sidebar.collapsed .brand-logo-large {
  width: 66px;
  max-height: 34px;
  margin: 0 auto;
}
.sidebar.collapsed .sidebar-toggle {
  width: 40px;
  height: 32px;
  border-radius: 999px;
  margin: 0 auto;
}
.sidebar.collapsed .sidebar-toggle-icon {
  transform: rotate(180deg);
}
.sidebar.collapsed .nav-link {
  width: 52px;
  height: 52px;
  margin-inline: auto;
  padding: 0;
  border-radius: 18px;
}
.sidebar.collapsed .nav-icon {
  font-size: 1.08rem;
}
.sidebar-version {
  border-radius: 16px;
  background: rgba(255,255,255,0.055);
  border: 1px solid rgba(255,255,255,0.075);
  padding: 10px;
  margin-top: auto;
}
.sidebar.collapsed .sidebar-version {
  width: 54px;
  margin-inline: auto;
  padding: 8px 4px;
}
.sidebar.collapsed .sidebar-version-number {
  font-size: 0.7rem;
  padding: 4px 6px;
}
.dashboard-device-list {
  display: grid;
  gap: 10px;
}
.dashboard-device-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 16px;
  padding: 12px 13px;
}
.dashboard-device-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.dashboard-device-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dashboard-device-meta {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

/* Admin/Archive tools + UX polish */
.btn-success {
  background: #16a34a;
  color: #fff;
  border-color: #16a34a;
}
.btn-success:hover { filter: brightness(0.95); }
.btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #dc2626;
}
.btn-danger:hover { filter: brightness(0.95); }
.btn-warning {
  background: #f59e0b;
  color: #111827;
  border-color: #f59e0b;
}
.empty-state {
  border: 1px dashed var(--border, #d7dfeb);
  border-radius: 18px;
  padding: 1.25rem;
  background: var(--surface-2, #f8fafc);
  color: var(--muted, #64748b);
}
.empty-state p { margin: 0.2rem 0; }
.compact-empty { padding: 0.85rem; }
.admin-tool-grid { align-items: start; }
.admin-archive-list {
  display: grid;
  gap: 0.75rem;
}
.admin-archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.85rem;
  border: 1px solid var(--border, #d7dfeb);
  border-radius: 16px;
  background: var(--surface-2, #f8fafc);
}
.project-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.project-summary-card small {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted, #64748b);
}
.sidebar-toggle {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 20px rgba(15,23,42,0.10);
}
.sidebar-toggle-icon {
  font-size: 1.35rem;
  line-height: 1;
  transition: transform .2s ease;
}
.sidebar.collapsed .sidebar-toggle-icon {
  transform: rotate(180deg);
}
.sidebar.collapsed .brand {
  justify-content: center;
}
.sidebar.collapsed .brand-logo-large {
  margin-inline: auto;
}
@media (max-width: 980px) {
  .page-content {
    padding-inline: 0.85rem;
  }
  .page-header.split,
  .card-head {
    gap: 0.75rem;
    align-items: flex-start;
  }
  .admin-archive-item,
  .action-row {
    flex-wrap: wrap;
  }
  .admin-archive-item .action-row {
    width: 100%;
  }
  .results-desktop-toolbar {
    display: none !important;
  }
  .results-mobile-toolbar {
    display: grid !important;
  }
  .grid-3.admin-tool-grid,
  .grid-2,
  .scan-console-layout,
  .result-detail-layout {
    grid-template-columns: 1fr !important;
  }
  .modal-card {
    width: min(96vw, 720px);
    max-height: 90vh;
    overflow: auto;
  }
  .data-table {
    min-width: 760px;
  }
}


/* Mobile navigation stability patch */
@media (max-width: 980px) {
  html,
  body {
    min-height: 100%;
    overflow-x: hidden;
  }

  .main-shell {
    min-width: 0;
    width: 100%;
  }

  .page-content {
    padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
  }

  .mobile-bottom-nav {
    z-index: 1100 !important;
    pointer-events: auto;
    touch-action: manipulation;
  }

  .mobile-bottom-link,
  .mobile-bottom-btn,
  .mobile-more-link {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .mobile-sheet-overlay {
    z-index: 1200 !important;
  }

  .mobile-more-sheet {
    z-index: 1210 !important;
    max-height: min(78vh, 520px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  body.mobile-nav-open .mobile-bottom-nav {
    pointer-events: none;
  }
}


/* Mobile sidebar hard fix v0.36
   Several later sidebar polish rules reset .sidebar to display:flex after the tablet media block.
   This final override must stay at the end so the desktop sidebar cannot cover mobile pages. */
@media (max-width: 980px) {
  .app-shell,
  body.sidebar-collapsed .app-shell {
    display: block !important;
    grid-template-columns: 1fr !important;
  }

  .sidebar,
  .sidebar.collapsed {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    position: absolute !important;
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
  }

  .main-shell {
    display: flex !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .topbar,
  .page-content {
    width: 100% !important;
    max-width: 100% !important;
  }

  .mobile-bottom-nav {
    display: grid !important;
  }
}


/* User/mobile list visibility fix */
@media (max-width: 980px) {
  .mobile-list {
    display: grid !important;
    gap: 12px;
    width: 100%;
  }

  .mobile-list:empty {
    display: none !important;
  }

  #usersMobileList {
    display: grid !important;
  }

  #usersMobileList:empty {
    display: none !important;
  }

  #usersTableWrap,
  #usersTableWrap.desktop-table {
    display: none !important;
  }

  body[data-page="users"] .card {
    overflow: visible;
  }

  body[data-page="users"] .mobile-item .action-row {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    width: 100%;
  }

  body[data-page="users"] .mobile-item .btn-sm {
    flex: 1 1 auto;
  }
}


/* v0.40 mobile/tablet stability + rotatable layout patch */
:root {
  --mobile-nav-height: 86px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-font-smoothing: antialiased;
}

button,
.btn,
a,
input,
select,
textarea {
  min-height: 44px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
}

.mobile-list,
.mobile-item,
.card,
.page-header,
.topbar {
  min-width: 0;
}

.mobile-row,
.mobile-item-header,
.action-row,
.card-head,
.page-header.split {
  min-width: 0;
}

.mobile-row > *,
.mobile-item-header > *,
.action-row > *,
.card-head > *,
.page-header.split > * {
  min-width: 0;
}

@media (max-width: 980px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    padding-top: max(0.7rem, env(safe-area-inset-top));
  }

  .topbar-left,
  .topbar-user {
    min-width: 0;
  }

  .topbar-left > div:first-child,
  .topbar-user > div:last-child {
    min-width: 0;
    overflow: hidden;
  }

  .topbar-left strong,
  .topbar-user strong,
  .topbar .muted {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-content {
    width: 100%;
    padding-left: max(0.85rem, env(safe-area-inset-left));
    padding-right: max(0.85rem, env(safe-area-inset-right));
    padding-bottom: calc(var(--mobile-nav-height) + 28px + env(safe-area-inset-bottom)) !important;
  }

  .page-header,
  .page-header.split,
  .card-head {
    display: flex;
    flex-wrap: wrap;
  }

  .page-header .btn,
  .page-header.split .btn,
  .card-head .btn,
  .action-row .btn {
    white-space: normal;
  }

  .action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    width: 100%;
  }

  .action-row .btn,
  .mobile-item .btn,
  .modal-actions .btn,
  .form-actions .btn {
    flex: 1 1 min(170px, 100%);
  }

  .modal {
    align-items: flex-start;
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
    overflow-y: auto;
  }

  .modal-card {
    width: min(100%, 760px) !important;
    max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body[data-page="scan"] .scan-grid,
  body[data-page="scan"] .scan-console-layout,
  body[data-page="dashboard"] .grid-2,
  body[data-page="settings"] .grid-2,
  body[data-page="projects"] .grid-2,
  body[data-page="result-detail"] .result-detail-layout {
    grid-template-columns: 1fr !important;
  }

  .plot-wrap,
  #scanChart,
  #resultChart {
    min-height: 280px;
    width: 100%;
  }
}

/* Rotatable tablet / mobile landscape view */
@media (max-width: 980px) and (orientation: landscape) {
  :root {
    --mobile-nav-height: 64px;
  }

  .topbar {
    position: static;
    padding-block: 0.55rem;
  }

  .page-content {
    padding-top: 0.75rem;
    padding-bottom: calc(var(--mobile-nav-height) + 14px + env(safe-area-inset-bottom)) !important;
  }

  .page-header {
    margin-bottom: 0.75rem;
  }

  .card {
    padding: 0.9rem;
  }

  .mobile-bottom-nav {
    min-height: var(--mobile-nav-height) !important;
    padding-top: 0.35rem !important;
    padding-bottom: max(0.35rem, env(safe-area-inset-bottom)) !important;
  }

  .mobile-bottom-link,
  .mobile-bottom-btn {
    gap: 0.1rem;
    font-size: 0.72rem;
  }

  .mobile-bottom-link span:first-child,
  .mobile-bottom-btn span:first-child {
    font-size: 1rem;
  }

  body[data-page="dashboard"] .scan-grid,
  body[data-page="dashboard"] .grid-2,
  body[data-page="settings"] .grid-2,
  body[data-page="projects"] .grid-2,
  body[data-page="result-detail"] .result-detail-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: start;
  }

  body[data-page="scan"] .scan-console-layout {
    grid-template-columns: minmax(280px, 0.8fr) minmax(360px, 1.2fr) !important;
    align-items: start;
  }

  body[data-page="scan"] .scan-grid {
    grid-template-columns: minmax(300px, 0.9fr) minmax(380px, 1.1fr) !important;
    align-items: start;
  }

  .plot-wrap,
  #scanChart,
  #resultChart {
    min-height: 240px;
  }
}

@media (min-width: 641px) and (max-width: 980px) and (orientation: portrait) {
  .stat-grid,
  .summary-grid,
  .grid-3.admin-tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 0.6rem;
  }

  .theme-toggle {
    transform: scale(0.92);
    transform-origin: left center;
  }

  .page-header h1 {
    font-size: clamp(1.45rem, 8vw, 2rem);
  }

  .btn,
  button {
    width: auto;
  }

  .page-header.split > .btn,
  .card-head > .btn,
  .form-actions .btn,
  .modal-actions .btn {
    width: 100%;
  }
}

/* v0.42 scan live gauge + test information panel */
.scan-live-workspace {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
  align-items: stretch;
}

.scan-live-side {
  min-width: 0;
}

.scan-live-result-card,
.scan-test-info-card {
  min-width: 0;
}

.scan-live-result-card {
  text-align: center;
}

.scan-gauge-wrap {
  max-width: 210px;
  margin-bottom: 0.75rem;
}

.scan-gauge {
  height: 96px;
}

.scan-gauge .result-gauge-hole {
  width: 116px;
  height: 58px;
}

.scan-gauge .result-gauge-needle {
  height: 62px;
}

.scan-concentration-block {
  margin-top: 0.75rem;
}

.scan-calibration-hint {
  margin-top: 0.3rem;
  font-size: 0.78rem;
}

.scan-mini-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 1rem;
  text-align: left;
}

.scan-mini-metrics > div {
  border: 1px solid var(--border, #d7dfeb);
  border-radius: 14px;
  padding: 0.7rem;
  background: var(--surface-2, #f8fafc);
  min-width: 0;
}

.scan-mini-metrics span,
.scan-test-info-list span {
  display: block;
  color: var(--muted, #64748b);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.scan-mini-metrics strong,
.scan-test-info-list strong {
  display: block;
  margin-top: 0.25rem;
  color: var(--text, #0f172a);
  overflow-wrap: anywhere;
}

.scan-test-info-list {
  display: grid;
  gap: 0.55rem;
}

.scan-test-info-list > div {
  border-bottom: 1px solid var(--border, #d7dfeb);
  padding-bottom: 0.55rem;
}

.scan-test-info-list > div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

html[data-theme="dark"] .scan-mini-metrics > div {
  background: rgba(15, 23, 42, 0.72);
}

html[data-theme="dark"] .scan-mini-metrics strong,
html[data-theme="dark"] .scan-test-info-list strong {
  color: #e5ecf7;
}

@media (max-width: 1240px) {
  .scan-live-workspace {
    grid-template-columns: 1fr;
  }

  .scan-live-side {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }
}

@media (max-width: 720px) {
  .scan-live-side,
  .scan-live-workspace {
    grid-template-columns: 1fr;
  }

  .scan-mini-metrics {
    grid-template-columns: 1fr;
  }

  .scan-gauge-wrap {
    max-width: 230px;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  body[data-page="scan"] .scan-console-layout {
    grid-template-columns: minmax(230px, 0.55fr) minmax(520px, 1.45fr) !important;
  }

  body[data-page="scan"] .scan-live-workspace {
    grid-template-columns: minmax(220px, 260px) minmax(0, 1fr) !important;
  }

  body[data-page="scan"] .scan-live-side {
    display: block;
  }

  body[data-page="scan"] .scan-mini-metrics {
    grid-template-columns: 1fr 1fr;
  }

  body[data-page="scan"] #scanChart {
    min-height: 260px;
  }
}

/* v0.43 scan console layout: console | graph | gauge/project info, then buffered points */
body[data-page="scan"] .scan-console-layout {
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr) minmax(220px, 280px) !important;
  align-items: stretch;
  gap: 0.85rem;
}

body[data-page="scan"] .scan-control-card {
  grid-column: 1;
  min-width: 0;
}

body[data-page="scan"] .scan-plot-card {
  grid-column: 2;
  min-width: 0;
}

body[data-page="scan"] .scan-live-side {
  grid-column: 3;
  display: grid;
  grid-template-columns: 1fr !important;
  gap: 0.85rem;
  align-content: start;
  min-width: 0;
}

body[data-page="scan"] .scan-plot-card .chart-box,
body[data-page="scan"] #scanChart {
  min-height: clamp(360px, 48vh, 560px);
}

body[data-page="scan"] .scan-live-result-card,
body[data-page="scan"] .scan-test-info-card {
  min-height: 0;
}

body[data-page="scan"] .scan-card-head-tight {
  margin-bottom: 0.55rem;
}

body[data-page="scan"] .scan-card-head-tight h2,
body[data-page="scan"] .scan-plot-card h2 {
  font-size: 1.02rem;
}

body[data-page="scan"] .scan-card-head-tight p {
  font-size: 0.78rem;
}

/* Compact collapsible buffered points panel */
.scan-buffer-details {
  padding: 0 !important;
  overflow: hidden;
}

.scan-buffer-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.scan-buffer-summary::-webkit-details-marker {
  display: none;
}

.scan-buffer-summary-icon {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--border, #d7dfeb);
  font-weight: 900;
  line-height: 1;
}

.scan-buffer-summary strong {
  display: block;
  color: var(--text, #0f172a);
  font-size: 1rem;
}

.scan-buffer-summary small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted, #64748b);
  font-size: 0.82rem;
  line-height: 1.35;
}

.scan-buffer-details .buffer-textarea {
  width: calc(100% - 2rem);
  margin: 0 1rem 1rem;
}

html[data-theme="dark"] .scan-buffer-summary-icon {
  background: rgba(15, 23, 42, 0.72);
}

@media (max-width: 1180px) and (min-width: 901px) {
  body[data-page="scan"] .scan-console-layout {
    grid-template-columns: minmax(210px, 260px) minmax(0, 1fr) minmax(210px, 250px) !important;
  }

  body[data-page="scan"] .scan-mini-metrics {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body[data-page="scan"] .scan-console-layout {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }

  body[data-page="scan"] .scan-control-card {
    grid-column: auto;
    order: 1;
  }

  body[data-page="scan"] .scan-plot-card {
    grid-column: auto;
    order: 2;
  }

  body[data-page="scan"] .scan-live-side {
    grid-column: auto;
    order: 3;
    grid-template-columns: 1fr !important;
  }

  body[data-page="scan"] .scan-buffer-card {
    order: 4;
  }

  body[data-page="scan"] .scan-plot-card .chart-box,
  body[data-page="scan"] #scanChart {
    min-height: 300px !important;
  }
}

@media (min-width: 721px) and (max-width: 900px) and (orientation: landscape) {
  body[data-page="scan"] .scan-console-layout {
    grid-template-columns: minmax(210px, 0.75fr) minmax(0, 1.25fr) !important;
    align-items: start;
  }

  body[data-page="scan"] .scan-control-card {
    order: 1;
  }

  body[data-page="scan"] .scan-plot-card {
    order: 2;
  }

  body[data-page="scan"] .scan-live-side {
    order: 3;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 720px) {
  body[data-page="scan"] .page-content {
    padding-inline: 0.65rem;
  }

  body[data-page="scan"] .page-header {
    margin-bottom: 0.6rem;
  }

  body[data-page="scan"] .page-header h1 {
    font-size: clamp(1.25rem, 6vw, 1.65rem);
  }

  body[data-page="scan"] .page-header p {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  body[data-page="scan"] .card {
    padding: 0.72rem;
    border-radius: 16px;
  }

  body[data-page="scan"] .scan-control-card,
  body[data-page="scan"] .scan-plot-card,
  body[data-page="scan"] .scan-live-result-card,
  body[data-page="scan"] .scan-test-info-card {
    min-height: 0;
  }

  body[data-page="scan"] label {
    font-size: 0.78rem;
    margin-bottom: 0.35rem;
  }

  body[data-page="scan"] input,
  body[data-page="scan"] select {
    min-height: 40px;
    padding: 0.58rem 0.7rem;
    font-size: 0.92rem;
  }

  body[data-page="scan"] .btn,
  body[data-page="scan"] button {
    min-height: 40px;
    padding: 0.58rem 0.7rem;
    font-size: 0.88rem;
  }

  body[data-page="scan"] .reader-message {
    padding: 0.72rem 0.78rem 0.72rem 2.35rem;
    border-radius: 14px;
    font-size: 0.86rem;
  }

  body[data-page="scan"] .reader-message::before {
    left: 0.78rem;
    width: 10px;
    height: 10px;
  }

  body[data-page="scan"] .scan-plot-card .chart-box,
  body[data-page="scan"] #scanChart {
    min-height: 255px !important;
    border-radius: 12px;
  }

  body[data-page="scan"] .scan-gauge-wrap {
    max-width: 170px;
    margin-bottom: 0.35rem;
  }

  body[data-page="scan"] .scan-gauge {
    height: 74px;
  }

  body[data-page="scan"] .scan-gauge .result-gauge-hole {
    width: 88px;
    height: 44px;
  }

  body[data-page="scan"] .scan-gauge .result-gauge-needle {
    height: 48px;
  }

  body[data-page="scan"] .result-concentration-value {
    font-size: clamp(1.45rem, 9vw, 2.1rem);
    line-height: 1;
  }

  body[data-page="scan"] .scan-calibration-hint {
    font-size: 0.72rem;
  }

  body[data-page="scan"] .scan-mini-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.45rem;
    margin-top: 0.65rem;
  }

  body[data-page="scan"] .scan-mini-metrics > div {
    padding: 0.5rem;
    border-radius: 12px;
  }

  body[data-page="scan"] .scan-mini-metrics span,
  body[data-page="scan"] .scan-test-info-list span {
    font-size: 0.62rem;
    letter-spacing: 0.035em;
  }

  body[data-page="scan"] .scan-mini-metrics strong,
  body[data-page="scan"] .scan-test-info-list strong {
    font-size: 0.82rem;
  }

  body[data-page="scan"] .scan-test-info-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  body[data-page="scan"] .scan-test-info-list > div {
    padding: 0.48rem;
    border: 1px solid var(--border, #d7dfeb);
    border-radius: 12px;
    background: var(--surface-2, #f8fafc);
  }

  body[data-page="scan"] .scan-test-info-list > div:last-child {
    border-bottom: 1px solid var(--border, #d7dfeb);
    padding-bottom: 0.48rem;
  }

  body[data-page="scan"] .scan-buffer-summary {
    padding: 0.72rem;
    gap: 0.55rem;
  }

  body[data-page="scan"] .scan-buffer-summary-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 0.86rem;
  }

  body[data-page="scan"] .scan-buffer-summary strong {
    font-size: 0.92rem;
  }

  body[data-page="scan"] .scan-buffer-summary small {
    font-size: 0.72rem;
  }

  body[data-page="scan"] .scan-buffer-details .buffer-textarea {
    min-height: 135px;
    width: calc(100% - 1.44rem);
    margin: 0 0.72rem 0.72rem;
    padding: 0.65rem;
    font-size: 0.76rem;
    border-radius: 12px;
  }
}

@media (max-width: 420px) {
  body[data-page="scan"] .scan-test-info-list {
    grid-template-columns: 1fr;
  }
}


/* v0.44 reader connection wizard */
.reader-wizard-card {
  border: 1px solid var(--border, #d7dfeb);
  border-radius: 18px;
  padding: 0.85rem;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.92), rgba(255, 255, 255, 0.92));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.62);
}

.reader-wizard-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.72rem;
}

.reader-wizard-head h2 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.15;
}

.reader-wizard-head p {
  margin: 0.18rem 0 0;
  font-size: 0.76rem;
  line-height: 1.35;
}

.reader-wizard-badge,
.reader-capability-grid strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 0.22rem 0.5rem;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  border: 1px solid var(--border, #d7dfeb);
  color: var(--muted, #64748b);
  background: var(--surface, #ffffff);
}

.reader-wizard-badge[data-state="success"],
.reader-capability-grid strong[data-state="success"] {
  border-color: rgba(22, 163, 74, 0.3);
  color: #15803d;
  background: rgba(34, 197, 94, 0.12);
}

.reader-wizard-badge[data-state="warning"],
.reader-capability-grid strong[data-state="warning"] {
  border-color: rgba(217, 119, 6, 0.32);
  color: #a16207;
  background: rgba(245, 158, 11, 0.14);
}

.reader-wizard-badge[data-state="error"],
.reader-capability-grid strong[data-state="error"] {
  border-color: rgba(220, 38, 38, 0.32);
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.12);
}

.reader-capability-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.72rem;
}

.reader-capability-grid > div {
  min-width: 0;
  border: 1px solid var(--border, #d7dfeb);
  border-radius: 13px;
  padding: 0.5rem;
  background: var(--surface-2, #f8fafc);
}

.reader-capability-grid span {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--muted, #64748b);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.reader-wizard-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.reader-wizard-actions .btn:last-child {
  grid-column: 1 / -1;
}

.reader-wizard-more {
  margin-top: 0.68rem;
  border-top: 1px solid var(--border, #d7dfeb);
  padding-top: 0.58rem;
}

.reader-wizard-more summary {
  cursor: pointer;
  color: var(--muted, #64748b);
  font-size: 0.78rem;
  font-weight: 900;
  user-select: none;
}

.reader-wizard-help {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.58rem;
}

.reader-wizard-help ol {
  margin: 0.15rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted, #64748b);
  font-size: 0.75rem;
  line-height: 1.45;
}

.reader-wizard-help p {
  margin: 0;
  font-size: 0.73rem;
  line-height: 1.35;
}

html[data-theme="dark"] .reader-wizard-card {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.78), rgba(15, 23, 42, 0.58));
}

html[data-theme="dark"] .reader-capability-grid > div,
html[data-theme="dark"] .reader-wizard-badge,
html[data-theme="dark"] .reader-capability-grid strong {
  background: rgba(15, 23, 42, 0.72);
}

@media (max-width: 720px) {
  body[data-page="scan"] .reader-wizard-card {
    padding: 0.65rem;
    border-radius: 14px;
  }

  body[data-page="scan"] .reader-wizard-head {
    margin-bottom: 0.52rem;
  }

  body[data-page="scan"] .reader-wizard-head h2 {
    font-size: 0.9rem;
  }

  body[data-page="scan"] .reader-wizard-head p {
    font-size: 0.7rem;
  }

  body[data-page="scan"] .reader-capability-grid {
    gap: 0.35rem;
    margin-bottom: 0.52rem;
  }

  body[data-page="scan"] .reader-capability-grid > div {
    padding: 0.42rem;
    border-radius: 11px;
  }

  body[data-page="scan"] .reader-capability-grid span {
    font-size: 0.56rem;
  }

  body[data-page="scan"] .reader-wizard-badge,
  body[data-page="scan"] .reader-capability-grid strong {
    font-size: 0.6rem;
    padding: 0.2rem 0.4rem;
  }

  body[data-page="scan"] .reader-wizard-actions {
    gap: 0.35rem;
  }

  body[data-page="scan"] .reader-wizard-help ol {
    font-size: 0.7rem;
  }
}

/* v0.45 end-user reader connection reset UI */
.reader-quick-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
  margin: -0.15rem 0 0.7rem;
}

.reader-quick-steps span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--border, #d7dfeb);
  border-radius: 999px;
  padding: 0.28rem 0.38rem;
  background: var(--surface-2, #f8fafc);
  color: var(--muted, #64748b);
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
}

.reader-capability-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.reader-wizard-actions .btn:last-child {
  grid-column: auto;
}

.reader-wizard-actions .reader-primary-action {
  grid-column: 1 / -1;
  min-height: 42px;
  font-weight: 950;
}

.reader-wizard-help .btn {
  width: 100%;
}

@media (max-width: 720px) {
  body[data-page="scan"] .reader-quick-steps {
    gap: 0.28rem;
    margin-bottom: 0.52rem;
  }

  body[data-page="scan"] .reader-quick-steps span {
    min-height: 24px;
    padding: 0.22rem 0.3rem;
    font-size: 0.57rem;
  }

  body[data-page="scan"] .reader-capability-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body[data-page="scan"] .reader-wizard-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body[data-page="scan"] .reader-wizard-actions .btn {
    min-height: 36px;
    padding: 0.48rem 0.55rem;
    font-size: 0.75rem;
  }

  body[data-page="scan"] .reader-wizard-actions .reader-primary-action {
    min-height: 38px;
  }
}

@media (max-width: 380px) {
  body[data-page="scan"] .reader-quick-steps,
  body[data-page="scan"] .reader-capability-grid {
    grid-template-columns: 1fr;
  }

  body[data-page="scan"] .reader-wizard-actions {
    grid-template-columns: 1fr;
  }

  body[data-page="scan"] .reader-wizard-actions .reader-primary-action {
    grid-column: auto;
  }
}


/* App Shell router additions */
.app-view-root {
  min-height: calc(100vh - var(--topbar-height, 72px));
}

.app-route-loading {
  min-height: 160px;
  display: grid;
  place-items: center;
  text-align: center;
}

body[data-router="shell"] .page-content {
  animation: appViewFadeIn 0.16s ease-out;
}

@keyframes appViewFadeIn {
  from { opacity: 0.78; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* App Shell background scan keep-alive */
.app-keepalive-view[hidden] {
  display: none !important;
}

.background-scan-banner {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 2200;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-lg, 0 12px 32px rgba(15, 23, 42, 0.18));
  background: var(--primary, #2563eb);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.background-scan-banner.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .background-scan-banner {
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    padding: 0.7rem 0.85rem;
    font-size: 0.9rem;
  }
}

/* v0.52 persistent reader connection indicator */
.reader-topbar-indicator {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  min-height: 36px;
  padding: 6px 11px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.reader-topbar-indicator:hover {
  transform: translateY(-1px);
}

.reader-topbar-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.16);
  flex: 0 0 auto;
}

.reader-topbar-indicator[data-state="connected"] {
  color: #166534;
  border-color: rgba(34, 197, 94, 0.36);
  background: rgba(34, 197, 94, 0.12);
}

.reader-topbar-indicator[data-state="connected"] .reader-topbar-dot {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18), 0 0 14px rgba(34, 197, 94, 0.42);
}

.reader-topbar-indicator[data-state="scanning"] {
  color: #14532d;
  border-color: rgba(34, 197, 94, 0.44);
  background: rgba(34, 197, 94, 0.16);
}

.reader-topbar-indicator[data-state="scanning"] .reader-topbar-dot {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2), 0 0 18px rgba(34, 197, 94, 0.58);
  animation: readerPulse 1.15s ease-in-out infinite;
}

.reader-topbar-indicator[data-state="connecting"] {
  color: #92400e;
  border-color: rgba(245, 158, 11, 0.42);
  background: rgba(245, 158, 11, 0.13);
}

.reader-topbar-indicator[data-state="connecting"] .reader-topbar-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
  animation: readerPulse 1.15s ease-in-out infinite;
}

@keyframes readerPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.32); opacity: 0.7; }
}

html[data-theme="dark"] .reader-topbar-indicator {
  background: rgba(15, 23, 42, 0.68);
  color: #cbd5e1;
}

html[data-theme="dark"] .reader-topbar-indicator[data-state="connected"],
html[data-theme="dark"] .reader-topbar-indicator[data-state="scanning"] {
  color: #86efac;
  background: rgba(34, 197, 94, 0.13);
  border-color: rgba(34, 197, 94, 0.34);
}

html[data-theme="dark"] .reader-topbar-indicator[data-state="connecting"] {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.34);
}

@media (max-width: 980px) {
  .reader-topbar-indicator {
    min-height: 32px;
    padding: 5px 8px;
    gap: 6px;
    font-size: 0.72rem;
    max-width: 42vw;
  }

  .reader-topbar-text {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .reader-topbar-dot {
    width: 8px;
    height: 8px;
  }
}

@media (max-width: 520px) {
  .reader-topbar-indicator {
    max-width: 34vw;
  }

  .reader-topbar-indicator[data-state="disconnected"] .reader-topbar-text {
    display: none;
  }
}
