:root {
  --bg: #0f1115;
  --row-bg: #171a20;
  --row-bg-alt: #1e222a;
  --border: #2a2e37;
  --text: #e6e8eb;
  --muted: #9aa1ab;
  --accent: #4da3ff;
  --accent-contrast: #06111c;
  --price: #3ddc84;
  --flash-rgb: 255, 196, 0;
  --badge-bg: #3ddc84;
  --badge-text: #06231a;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f2f3f5;
  --row-bg: #ffffff;
  --row-bg-alt: #eef0f3;
  --border: #e1e4e9;
  --text: #15181d;
  --muted: #666d78;
  --accent: #2f6fd6;
  --accent-contrast: #ffffff;
  --price: #1f9d58;
  --flash-rgb: 255, 196, 0;
  --badge-bg: #1f9d58;
  --badge-text: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.access-form {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  text-align: center;
}

.access-form h1 {
  font-size: 18px;
  margin: 0 0 8px;
}

.access-input {
  background: var(--row-bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
}

.access-btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.access-error {
  color: #e0544c;
  font-size: 13px;
  margin: 0;
}

html, body {
  margin: 0;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

header {
  /* iOS PWA (standalone, black-translucent status bar) draws the status bar — clock,
     battery — on top of the page instead of pushing it down, so without this the header
     buttons render underneath it and can't be tapped. safe-area-inset-top is exactly
     how tall that overlaid area is; env() needs viewport-fit=cover (set) to be nonzero. */
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 700;
}

.auto-send-badge {
  display: block;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 6px;
}

.auto-send-badge.ok {
  color: #3ddc84;
}

.auto-send-badge.fail {
  color: #e0544c;
}

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

.icon-btn {
  background: var(--row-bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.icon-btn-square {
  padding: 7px 9px;
  font-size: 14px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3ddc84;
  flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6);
  animation: pulse 1.6s infinite;
}

.live-dot.offline {
  background: #e0544c;
  animation: none;
  box-shadow: none;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

.status {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main {
  padding-bottom: 24px;
}

.list {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--row-bg);
  position: relative;
  animation: dropIn 0.3s ease;
}

.row-top-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row:nth-child(odd) {
  background: var(--row-bg-alt);
}

.row.new {
  animation: dropIn 0.3s ease, rowFlash 3.5s ease-out;
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes rowFlash {
  0% { background-color: rgba(var(--flash-rgb), 0.65); }
  100% { background-color: transparent; }
}

.row-img {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--row-bg-alt);
}

.row-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.row-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-price {
  font-weight: 700;
  font-size: 15px;
  color: var(--price);
  white-space: nowrap;
  flex-shrink: 0;
}

.row-specs {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.row-btn {
  flex-shrink: 0;
  width: 64px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}

.row-btn:active {
  opacity: 0.8;
}

.row-msg-btn,
.row-google-btn {
  background: var(--row-bg-alt);
  color: var(--accent);
  border: 1px solid var(--accent);
  font-size: 15px;
  cursor: pointer;
}

.row-msg-btn:active,
.row-google-btn:active {
  opacity: 0.8;
}

.row-msg-btn:disabled,
.row-google-btn:disabled {
  cursor: default;
}

.row-msg-btn.sending,
.row-google-btn.sending {
  color: var(--muted);
  border-color: var(--border);
  opacity: 0.7;
}

.row-msg-btn.sent {
  background: var(--badge-bg);
  color: var(--badge-text);
  border-color: var(--badge-bg);
  font-size: 12px;
  font-weight: 700;
}

.row-msg-btn.partial {
  background: #e0a63c;
  color: #2a1c00;
  border-color: #e0a63c;
  font-size: 12px;
  font-weight: 700;
}

.row-msg-btn.error,
.row-google-btn.error {
  background: #e0544c;
  color: #fff;
  border-color: #e0544c;
}

.badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 1;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 20px;
  animation: badgeFade 4.5s ease forwards;
}

@keyframes badgeFade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

.keepalive-video {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 2px;
  height: 2px;
  opacity: 0.01;
  pointer-events: none;
}

.icon-btn.on {
  background: var(--badge-bg);
  color: var(--badge-text);
  border-color: transparent;
}
