/* PWA acquisition modal, thank-you page, and app shell additions */

/* App home only: photo backgrounds (set by app-shell.js after successful image load).
   Other app pages use solid theme colours. Body background-color is the fallback. */
html.app-bg-image body.app-home {
  background-image: var(--app-bg-url);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.pwa-cta-section {
  background: linear-gradient(135deg, #eef3ff 0%, #f8faff 100%);
  border: 2px solid #4c7be9;
  border-radius: 16px;
  padding: 32px 24px;
  margin: 24px auto 32px;
  max-width: 640px;
}

html.dark .pwa-cta-section {
  background: linear-gradient(135deg, #1a2540 0%, #0f172a 100%);
  border-color: #6b9af5;
}

.pwa-cta-section h3 {
  color: #4c7be9;
  font-size: 1.6rem;
  margin: 0 0 8px;
}

.pwa-cta-section .free-counter {
  font-size: 1rem;
  color: #28a745;
  font-weight: 600;
  margin-bottom: 16px;
}

html.dark .pwa-cta-section .free-counter {
  color: #5dd879;
}

.pwa-get-btn {
  background: #4c7be9;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 16px 32px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 260px;
  transition: background 0.2s, transform 0.1s;
}

.pwa-get-btn:hover {
  background: #3a6ad8;
  transform: translateY(-1px);
}

/* Acquisition modal */
.acquire-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.acquire-modal[hidden] {
  display: none;
}

.acquire-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.acquire-modal-panel {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

html.dark .acquire-modal-panel {
  background: #1e293b;
  color: #e2e8f0;
}

.acquire-modal-panel h2 {
  margin: 0 0 8px;
  color: #4c7be9;
}

.acquire-modal-panel .close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #888;
  line-height: 1;
}

.acquire-email-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #d0d8f0;
  border-radius: 8px;
  font-size: 1rem;
  margin: 16px 0;
  box-sizing: border-box;
}

html.dark .acquire-email-input {
  background: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}

.acquire-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.acquire-btn-free {
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.acquire-btn-free:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.acquire-btn-paid {
  background: #4c7be9;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.acquire-error {
  color: #dc3545;
  font-size: 0.9rem;
  margin-top: 8px;
}

/* Thank-you page */
.thank-you-key {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 1.3rem;
  letter-spacing: 2px;
  background: #f0f4ff;
  padding: 16px 20px;
  border-radius: 10px;
  margin: 16px 0;
  word-break: break-all;
}

html.dark .thank-you-key {
  background: #1a2540;
}

.thank-you-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* App shell */
.app-header {
  background: #4c7be9;
  color: #fff;
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 12px calc(16px + env(safe-area-inset-left, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-settings-gear,
.app-help-link,
.app-header .app-theme-toggle,
.app-header .dark-mode-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  text-decoration: none;
  font-size: 1.2rem;
  line-height: 1;
  transition: background 0.2s;
}

.app-help-link {
  padding: 0 10px;
  font-size: 0.85rem;
  font-weight: 600;
  width: auto;
}

.app-header .app-theme-toggle,
.app-header .dark-mode-toggle {
  border: none;
  cursor: pointer;
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 600;
  width: auto;
  font-family: inherit;
}

.app-settings-gear:hover,
.app-help-link:hover,
.app-header .app-theme-toggle:hover,
.app-header .dark-mode-toggle:hover {
  background: rgba(255, 255, 255, 0.28);
}

.app-top-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 8px calc(12px + env(safe-area-inset-left, 0px));
  background: #3a6ad8;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 150;
}

.app-top-bar-back {
  justify-self: start;
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.app-top-bar-title {
  justify-self: center;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Back | title | Help | gear */
.app-top-bar:has(.app-help-link) {
  grid-template-columns: 1fr auto auto auto;
}

.app-top-bar .app-settings-gear {
  justify-self: end;
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
}

.app-top-bar .app-help-link {
  justify-self: end;
  width: auto;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  font-size: 0.8rem;
  margin-right: 2px;
}

.app-footer-bar {
  background: #3a6ad8;
  color: #fff;
  text-align: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  margin-top: 0;
  font-size: 0.9rem;
}

.app-footer-bar p {
  margin: 0;
}

.app-footer-version {
  font-size: 0.65rem;
  opacity: 0.85;
  margin-top: 2px;
}

.app-footer-links {
  font-size: 0.75rem;
  margin-top: 4px;
}

.app-footer-links a {
  color: #fff;
  opacity: 0.9;
}

.app-settings-subheading {
  font-size: 0.95rem;
  margin: 16px 0 6px;
  color: #334155;
}

.app-device-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
}

.app-device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.app-device-info {
  font-size: 0.9rem;
  color: #334155;
  line-height: 1.4;
}

.app-device-seen {
  font-size: 0.8rem;
  color: #64748b;
}

.app-device-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: #4c7be9;
}

.app-btn-remove-device {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 0.8rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #475569;
  cursor: pointer;
}

.app-btn-remove-device:hover {
  background: #f1f5f9;
}

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

.app-license-bar {
  background: #eef3ff;
  padding: 8px 16px;
  font-size: 0.85rem;
  text-align: center;
  color: #334155;
}

.app-license-bar-inset {
  border-radius: 8px;
  margin-bottom: 14px;
}

html.dark .app-license-bar {
  background: #1a2540;
  color: #94a3b8;
}

.app-btn-remove-key {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: #dc3545;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.app-btn-remove-key:hover {
  background: #c82333;
}

body.app-home {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

body.app-home .app-tool-grid {
  flex: 1;
  align-content: center;
}

.app-tool-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.app-tool-card {
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
  text-decoration: none;
  color: inherit;
  display: block;
}

html.dark .app-tool-card {
  background: #1e293b;
  border-color: #334155;
}

.app-tool-card:hover {
  border-color: #4c7be9;
  transform: translateY(-2px);
}

.app-tool-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  color: #4c7be9;
}

.app-tool-card p {
  margin: 0;
  font-size: 0.8rem;
  color: #64748b;
}

.app-tool-card.is-default-tool,
.service-card.is-default-refrigerant {
  border-color: #28a745;
  box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.25);
}

html.dark .app-tool-card.is-default-tool,
html.dark .service-card.is-default-refrigerant {
  border-color: #5dd879;
  box-shadow: 0 0 0 2px rgba(93, 216, 121, 0.2);
}

.app-default-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #28a745;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
}

.app-tool-card .app-default-badge {
  display: block;
  margin-top: 8px;
}

/* Settings page */
.app-header-compact h1 {
    font-size: 1.35rem;
    margin-bottom: 0.15rem;
}

.app-header-sub {
    font-size: 0.85rem;
    opacity: 0.85;
    margin: 0;
    font-weight: 400;
}

.ref-calc-switcher {
    max-width: 420px;
    margin: 0 auto 1rem;
    padding: 0 16px;
}

.app-settings-page {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

.app-settings-section {
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 16px;
  margin-bottom: 16px;
}

html.dark .app-settings-section {
  background: #1e293b;
  border-color: #334155;
}

.app-settings-section h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
  color: #4c7be9;
}

.app-settings-hint {
  margin: 0 0 14px;
  font-size: 0.85rem;
  color: #64748b;
}

.app-settings-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.app-settings-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-settings-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}

html.dark .app-settings-option {
  border-color: #334155;
}

.app-settings-option:has(input:checked) {
  border-color: #4c7be9;
  background: #eef3ff;
}

html.dark .app-settings-option:has(input:checked) {
  background: #1a2540;
}

.app-settings-option input {
  margin: 0;
}

.app-settings-warning {
    color: #b45309;
    border-left: 3px solid #f59e0b;
    padding-left: 12px;
}

html.dark .app-settings-warning {
    color: #fbbf24;
}

.app-settings-section-danger {
    border-color: #fecaca;
}

html.dark .app-settings-section-danger {
    border-color: #7f1d1d;
}

.app-settings-note {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: #64748b;
}

.app-settings-link-btn {
  display: block;
  text-align: center;
  padding: 12px 16px;
  border-radius: 8px;
  background: #eef3ff;
  color: #4c7be9;
  font-weight: 600;
  text-decoration: none;
  border: 2px solid #d0d8f0;
  transition: border-color 0.2s, background 0.2s;
}

/* Help index — compact bullet topics + search */
.help-search-input {
  margin-top: 8px;
  margin-bottom: 1rem;
  max-width: 32rem;
  width: 100%;
  box-sizing: border-box;
}

.help-topic-list {
  list-style: disc;
  margin: 0 0 1rem 1.15rem;
  padding: 0;
}

.help-topic-list .help-item {
  margin: 0.28rem 0;
  line-height: 1.35;
}

.help-topic-list .help-item a {
  color: #4c7be9;
  font-weight: 600;
  text-decoration: none;
}

.help-topic-list .help-item a:hover {
  text-decoration: underline;
}

html.dark .help-topic-list .help-item a {
  color: #6b9af5;
}

.help-item-hint {
  display: block;
  font-size: 0.78rem;
  color: #64748b;
  font-weight: 400;
  margin-top: 0.1rem;
  margin-left: 0;
}

html.dark .help-item-hint {
  color: #94a3b8;
}

.help-no-results {
  text-align: center;
  color: #64748b;
  font-style: italic;
  padding: 1.5rem 0.5rem;
  margin: 0;
}

.help-article-nav {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

.help-article-nav a {
  color: #4c7be9;
  font-weight: 600;
  text-decoration: none;
}

.help-article-nav a:hover {
  text-decoration: underline;
}

html.dark .help-article-nav a {
  color: #6b9af5;
}

.app-settings-link-btn:hover {
  border-color: #4c7be9;
  background: #e0e9ff;
}

html.dark .app-settings-link-btn {
  background: #1a2540;
  border-color: #334155;
  color: #6b9af5;
}

.ref-calc-page #log-actions-block {
  margin: 1rem 8px 0;
}

.ref-calc-page #log-actions-block[hidden] {
  display: none !important;
}

/* RefCalc action bars — input row of 3; output row 2×2 (loads after styles.css) */
.ref-calc-page #action-buttons.ref-calc-action-bars {
  display: flex !important;
  flex-direction: column !important;
  gap: 10px;
}

.ref-calc-page #ref-calc-primary-actions {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.ref-calc-page #log-action-buttons.ref-calc-log-actions {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.ref-calc-page #ref-calc-primary-actions[hidden],
.ref-calc-page #log-action-buttons[hidden] {
  display: none !important;
}

.ref-calc-page #log-action-buttons:not([hidden]) {
  display: grid !important;
}

html.dark .ref-calc-page #action-buttons .ref-calc-compact-btn {
  background: linear-gradient(135deg, #1a3568, #0f2347) !important;
  color: #e8eef8 !important;
}

.ref-calc-page #action-buttons .ref-calc-compact-btn {
  min-width: 0 !important;
  width: 100%;
  font-size: 0.68rem;
  padding: 10px 4px;
  white-space: normal;
}

.ref-calc-info-link {
  display: flex !important;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: stretch;
  gap: 4px;
  max-width: 100%;
  margin: 0 auto 4px;
  padding: 0 16px;
  box-sizing: border-box;
}

.ref-calc-info-link .app-settings-link-btn {
  display: block;
  width: auto;
  flex: 1 1 0;
  min-width: 0;
  max-width: 50%;
  padding: 3px 4px;
  font-size: 0.55rem;
  font-weight: 600;
  border-width: 1px;
  border-radius: 2px;
  line-height: 1.2;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  box-sizing: border-box;
}

.ref-info-modal-content {
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}

.ref-info-section {
  margin-top: 1.25rem;
}

.ref-info-section h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: #334155;
}

.ref-info-section ul {
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.5;
}

.ref-info-section li + li {
  margin-top: 0.35rem;
}

.ref-info-section a {
  color: #4c7be9;
}

.ref-info-empty {
  list-style: none;
  margin-left: -1.25rem;
  color: #64748b;
  font-style: italic;
}

html.dark .ref-info-section h3 {
  color: #cbd5e1;
}

html.dark .ref-info-section a {
  color: #6b9af5;
}

html.dark .ref-info-empty {
  color: #94a3b8;
}

/* App development log */
.app-log-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.app-log-heading {
  color: #4c7be9;
  font-size: 1.25rem;
  margin: 0 0 8px;
}

.app-log-meta {
  font-size: 0.85rem;
  color: #64748b;
  margin: 0 0 24px;
}

.app-log-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.app-log-entry {
  display: block;
  padding: 14px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

html.dark .app-log-entry {
  border-color: #334155;
}

.app-log-entry:hover {
  border-color: #4c7be9;
}

.app-log-date {
  display: block;
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 4px;
}

.app-log-title {
  display: block;
  font-weight: 600;
  color: #4c7be9;
}

.app-log-section {
  margin-bottom: 24px;
}

.app-log-section h3 {
  color: #334155;
  font-size: 1rem;
  margin: 0 0 10px;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 6px;
}

html.dark .app-log-section h3 {
  color: #e2e8f0;
  border-bottom-color: #334155;
}

.app-log-section ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.55;
}

.app-log-section li {
  margin-bottom: 6px;
}

.app-log-section code {
  font-size: 0.85em;
  background: #f0f4ff;
  padding: 1px 5px;
  border-radius: 4px;
}

html.dark .app-log-section code {
  background: #1a2540;
}

/* License gate overlay */
.license-gate {
  position: fixed;
  inset: 0;
  background: #0f172a;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.license-gate[hidden] {
  display: none;
}

.license-gate-panel {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

html.dark .license-gate-panel {
  background: #1e293b;
  color: #e2e8f0;
}

.license-gate-panel h2 {
  color: #4c7be9;
  margin: 0 0 12px;
}

.license-gate-panel .acquire-error.license-gate-msg-ok {
  color: #28a745;
}

html.dark .license-gate-panel .acquire-error.license-gate-msg-ok {
  color: #3dd68c;
}

/* Update toast */
.sw-update-toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: #4c7be9;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  z-index: 30000;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.sw-update-toast[hidden] {
  display: none;
}

.sw-update-toast button {
  background: #fff;
  color: #4c7be9;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
}

/* PWA numeric pad — overflow lock styles live in styles.css (html.phvac-numpad-overflow).
   Kept here as a light safeguard if site CSS is stale in cache; no touch-action:none on
   html/body (that blocks reliable key gestures on some WebKit builds). */
html.phvac-numpad-overflow .phvac-numpad-overlay {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

html.phvac-numpad-overflow .phvac-numpad {
  transform: none;
}