* {
  box-sizing: border-box;
}

:root {
  --ink: #efede5;
  --muted: #a5a49d;
  --quiet: #74746f;
  --ground: #161714;
  --surface: #1d1e1a;
  --surface-raised: #24251f;
  --line: rgba(239, 237, 229, 0.12);
  --line-strong: rgba(239, 237, 229, 0.22);
  --paper: #f2ecdd;
  --ada: #d6a84e;
  --theo: #4e9bb0;
  --danger: #df7166;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.32);
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid rgba(239, 237, 229, 0.65);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.hidden {
  display: none !important;
}

.rv-shell {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rv-header {
  min-height: 62px;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 15px;
  border-bottom: 1px solid var(--line);
  background: rgba(22, 23, 20, 0.94);
  backdrop-filter: blur(16px);
  z-index: 20;
}

.rv-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.rv-brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  opacity: 0.9;
}

.rv-brand h1,
.rv-agent-topline h2,
.rv-pad-heading h2,
.rv-map-heading h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-weight: 500;
  letter-spacing: 0;
}

.rv-brand h1 {
  font-size: 22px;
}

.rv-live-line {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rv-live-line #rvStatus {
  color: var(--ink);
}

.rv-dot {
  color: var(--quiet);
}

.rv-controls,
.rv-control-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.rv-icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}

.rv-icon-button svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.7;
}

.rv-icon-button:hover {
  border-color: var(--line-strong);
  background: rgba(239, 237, 229, 0.06);
  color: var(--ink);
}

.rv-icon-button.danger:hover {
  color: var(--danger);
}

.rv-icon-button.quiet {
  border-color: transparent;
}

.rv-main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(310px, 27vw, 410px) minmax(0, 1fr);
  gap: 13px;
  padding: 13px;
}

.rv-agent-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d0e0c;
}

.rv-agent-topline {
  min-height: 50px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.rv-agent-topline h2 {
  font-size: 24px;
  line-height: 1;
}

.rv-agent-panel.ada h2 {
  color: var(--ada);
}

.rv-agent-panel.theo h2 {
  color: var(--theo);
}

.rv-agent-meta {
  min-width: 0;
  display: flex;
  gap: 8px;
  color: var(--quiet);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.rv-agent-meta span + span::before {
  content: "·";
  margin-right: 8px;
}

.rv-street {
  width: 100%;
  height: 100%;
  min-height: 320px;
  background: #050505;
}

.rv-agent-note {
  min-height: 62px;
  max-height: 88px;
  margin: 0;
  padding: 12px 14px 13px;
  overflow: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: #c4c2ba;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 14px;
  line-height: 1.4;
  scrollbar-color: rgba(239, 237, 229, 0.28) transparent;
  scrollbar-width: thin;
}

.rv-agent-note::-webkit-scrollbar {
  width: 5px;
}

.rv-agent-note::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(239, 237, 229, 0.24);
}

.rv-center {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 13px;
}

.rv-scratchpad-section,
.rv-map-section {
  min-width: 0;
  min-height: 0;
}

.rv-scratchpad-section {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 4px 5px 8px;
}

.rv-pad-heading,
.rv-map-heading {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 9px;
}

.rv-pad-heading h2,
.rv-map-heading h2 {
  font-size: 18px;
}

.rv-pad-heading p,
.rv-map-heading p {
  margin: 2px 0 0;
  color: var(--quiet);
  font-size: 11px;
}

.rv-history-controls {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 3px;
}

.rv-history-controls > span {
  min-width: 88px;
  color: var(--quiet);
  text-align: center;
  white-space: nowrap;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.rv-history-button {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--quiet);
  cursor: pointer;
}

.rv-history-button[hidden] {
  display: none;
}

.rv-history-button:hover:not(:disabled),
.rv-history-button:focus-visible {
  background: rgba(239, 237, 229, 0.07);
  color: var(--ink);
}

.rv-history-button svg {
  width: 15px;
  height: 15px;
  stroke-width: 1.8;
}

.rv-history-live {
  margin-left: 3px;
  color: #91c9a6;
}

.rv-paper {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  max-height: calc(100% - 46px);
  margin: auto;
  overflow: hidden;
  border-radius: 2px;
  background: var(--paper);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(45, 38, 28, 0.08);
  transform: rotate(-0.35deg);
  transform-origin: center;
  transition: transform 220ms ease, box-shadow 220ms ease;
}

.rv-paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 12px 0 24px rgba(71, 57, 35, 0.035), inset -8px -8px 20px rgba(71, 57, 35, 0.025);
}

.rv-paper.pulse {
  animation: rvPadArrives 700ms cubic-bezier(0.22, 0.9, 0.3, 1);
}

#rvScratchpad,
#rvScratchpadImage {
  display: block;
  width: 100%;
  height: 100%;
}

#rvScratchpadImage {
  object-fit: cover;
}

#rvScratchpadImage[hidden],
#rvScratchpad[hidden] {
  display: none;
}

.rv-pad-empty {
  fill: rgba(62, 52, 41, 0.38);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 23px;
  font-style: italic;
}

.rv-scratch-stroke {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rv-scratch-stroke.is-new {
  animation: rvDraw 700ms ease-out both;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.rv-scratch-text.is-new {
  animation: rvInkIn 420ms ease-out both;
}

.rv-map-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.rv-map-heading {
  padding-bottom: 7px;
}

.rv-map {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border-radius: 5px;
  background: #dddcd5;
}

.rv-map-marker {
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.rv-mobile-tabs {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(11, 12, 10, 0.78);
  backdrop-filter: blur(8px);
}

.modal-content {
  width: min(410px, 100%);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 20px;
  font-weight: 500;
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
}

.modal-body p {
  margin: 0 0 12px;
  color: var(--muted);
}

.modal-body input {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--ground);
  color: var(--ink);
}

.btn-cancel,
.btn-submit {
  min-height: 35px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.btn-submit {
  background: var(--ink);
  color: var(--ground);
}

.auth-error {
  margin-top: 10px;
  color: var(--danger);
}

.admin-notification {
  position: fixed;
  top: 74px;
  right: 14px;
  z-index: 120;
  max-width: min(380px, calc(100vw - 28px));
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-7px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.admin-notification.error {
  color: #f0a39b;
}

.admin-notification.show {
  opacity: 1;
  transform: translateY(0);
}

@keyframes rvPadArrives {
  0% { transform: translateX(-9px) rotate(-1deg); }
  58% { transform: translateX(3px) rotate(0.2deg); }
  100% { transform: translateX(0) rotate(-0.35deg); }
}

@keyframes rvDraw {
  to { stroke-dashoffset: 0; }
}

@keyframes rvInkIn {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1120px) {
  .rv-main {
    grid-template-columns: minmax(0, 1fr) 300px minmax(0, 1fr);
    gap: 9px;
    padding: 9px;
  }
}

@media (max-width: 900px) {
  .rv-header {
    min-height: 52px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 0 10px;
  }

  .rv-brand-icon {
    width: 27px;
    height: 27px;
  }

  .rv-brand h1 {
    font-size: 18px;
  }

  .rv-live-line {
    justify-content: flex-end;
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
  }

  .rv-live-line #rvStatus,
  .rv-live-line .rv-dot:first-of-type,
  .rv-live-line > span:last-child {
    display: none;
  }

  .rv-main {
    position: relative;
    display: block;
    min-height: 0;
    padding: 8px;
  }

  .rv-center {
    display: contents;
  }

  [data-mobile-panel] {
    width: 100%;
    height: 100%;
    display: none;
  }

  body[data-mobile-view="ada"] [data-mobile-panel="ada"],
  body[data-mobile-view="theo"] [data-mobile-panel="theo"] {
    display: grid;
  }

  body[data-mobile-view="pad"] [data-mobile-panel="pad"] {
    display: flex;
  }

  body[data-mobile-view="map"] [data-mobile-panel="map"] {
    display: flex;
  }

  .rv-agent-panel {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .rv-agent-topline {
    min-height: 46px;
    padding: 10px 11px 8px;
  }

  .rv-agent-topline h2 {
    font-size: 22px;
  }

  .rv-street {
    min-height: 0;
  }

  .rv-agent-note {
    min-height: 58px;
    max-height: clamp(92px, 16dvh, 132px);
    padding: 10px 11px 11px;
    font-size: 13px;
  }

  .rv-scratchpad-section {
    justify-content: center;
    padding: 11px 5px 16px;
  }

  .rv-pad-heading,
  .rv-map-heading {
    width: 100%;
    padding: 0 5px 12px;
  }

  .rv-history-controls > span {
    min-width: 96px;
  }

  .rv-history-button {
    width: 36px;
    height: 36px;
  }

  .rv-pad-heading h2,
  .rv-map-heading h2 {
    font-size: 22px;
  }

  .rv-paper {
    width: min(100%, calc((100dvh - 184px) * 1.5));
    max-height: calc(100dvh - 184px);
  }

  .rv-map-section {
    padding: 8px 0 0;
    border-top: 0;
  }

  .rv-map {
    border-radius: 6px;
  }

  .rv-mobile-tabs {
    flex: 0 0 auto;
    min-height: 64px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(22, 23, 20, 0.97);
    z-index: 30;
  }

  .rv-mobile-tab {
    position: relative;
    min-width: 0;
    min-height: 46px;
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--quiet);
    cursor: pointer;
  }

  .rv-mobile-tab svg {
    width: 16px;
    height: 16px;
    stroke-width: 1.6;
  }

  .rv-mobile-tab span {
    font-size: 11px;
    line-height: 1;
  }

  .rv-mobile-tab.active {
    background: rgba(239, 237, 229, 0.08);
    color: var(--ink);
  }

  body[data-mobile-view="ada"] .rv-mobile-tab[data-mobile-view="ada"] {
    color: var(--ada);
  }

  body[data-mobile-view="theo"] .rv-mobile-tab[data-mobile-view="theo"] {
    color: var(--theo);
  }

  .admin-notification {
    top: 62px;
  }
}

@media (max-width: 430px) {
  .rv-brand h1 {
    font-size: 17px;
  }

  .rv-live-line {
    gap: 5px;
  }

  .rv-mobile-tab {
    grid-template-columns: 16px auto;
    column-gap: 4px;
    padding-inline: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
