/* ============================================================
   UmzugsPost – mobile-first PWA
   ============================================================ */

:root {
  --bg: #f4f1ea;
  --bg-deep: #ece7dd;
  --surface: #fffdf9;
  --surface-2: #f8f4ec;
  --input-bg: #fcfaf6;
  --ink: #101c2b;
  --ink-soft: #46586b;
  --muted: #78869a;
  --line: #e3ddd1;
  --line-strong: #d2cabb;
  --brand: #12314f;
  --brand-strong: #0d2740;
  --brand-soft: #e7eef5;
  --link: #1b557f;
  --accent: #e9a13b;
  --accent-strong: #9a6414;
  --accent-soft: #fbf0dc;
  --warn: #8a5a00;
  --warn-soft: #fdf3df;
  --danger: #b02a1c;
  --danger-soft: #fbeceb;
  --success: #17694b;
  --success-soft: #e4f3ea;
  --btn: #12314f;
  --btn-hover: #0d2740;
  --btn-ink: #ffffff;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(16, 42, 67, 0.04), 0 14px 34px -22px rgba(16, 42, 67, 0.35);
  --shadow-lg: 0 24px 60px -24px rgba(16, 42, 67, 0.4);
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d151d;
    --bg-deep: #0a1118;
    --surface: #14212e;
    --surface-2: #101b26;
    --input-bg: #0f1a24;
    --ink: #eef3f8;
    --ink-soft: #b5c3d1;
    --muted: #8595a7;
    --line: #243444;
    --line-strong: #33475b;
    --brand: #2e6d99;
    --brand-strong: #7fb6dc;
    --brand-soft: #1a2f42;
    --link: #8cc3e8;
    --accent: #f0ac4c;
    --accent-strong: #f3bf74;
    --accent-soft: #332814;
    --warn: #f3c16d;
    --warn-soft: #322813;
    --danger: #ff9d90;
    --danger-soft: #3a1d1a;
    --success: #82d9b4;
    --success-soft: #122e24;
    --btn: #2e6d99;
    --btn-hover: #3a7fac;
    --btn-ink: #f4fbff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 40px -26px rgba(0, 0, 0, 0.8);
    --shadow-lg: 0 26px 70px -26px rgba(0, 0, 0, 0.85);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 50% -12%, color-mix(in srgb, var(--surface) 92%, transparent) 0%, transparent 62%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  cursor: pointer;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- layout ---------- */

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 20px calc(104px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

main {
  display: block;
}

.view {
  padding-top: 8px;
  animation: view-in 0.3s cubic-bezier(0.22, 0.68, 0.36, 1) both;
}

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.grid-2-address {
  grid-template-columns: 108px 1fr;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -20px;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  box-shadow: 0 6px 14px -8px rgba(16, 42, 67, 0.75);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-text strong {
  font-size: 16.5px;
  font-weight: 750;
  letter-spacing: -0.015em;
}

.brand-text span {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* ---------- typography ---------- */

.hero {
  padding: 26px 2px 20px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin-bottom: 8px;
}

h1 {
  font-size: clamp(2rem, 8.6vw, 2.65rem);
  line-height: 1.05;
  letter-spacing: -0.032em;
  font-weight: 800;
  text-wrap: balance;
}

h1 em {
  font-style: normal;
  color: var(--brand-strong);
}

@media (prefers-color-scheme: dark) {
  h1 em {
    color: var(--accent);
  }
}

h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.lede {
  margin-top: 14px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.center-hint {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.version {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 0 4px;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad {
  padding: 18px;
}

.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.view-head h1 {
  font-size: clamp(1.85rem, 7.5vw, 2.2rem);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 13px;
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.07s ease, background-color 0.16s ease, box-shadow 0.16s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.btn:focus-visible {
  outline: 2px solid var(--brand-strong);
  outline-offset: 2px;
}

.btn .icon {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--btn);
  color: var(--btn-ink);
  box-shadow: 0 12px 22px -14px rgba(18, 49, 79, 0.9);
}

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

.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 42, 67, 0.04);
}

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

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-success {
  background: var(--success-soft);
  color: var(--success);
}

.btn-danger-ghost {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-small {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12.5px;
  border-radius: 10px;
  gap: 6px;
}

.btn-small .icon {
  width: 15px;
  height: 15px;
}

.btn-block {
  width: 100%;
}

.btn-lg {
  min-height: 54px;
  border-radius: 15px;
  font-size: 15.5px;
}

.btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

.btn.is-loading .icon {
  display: none;
}

.link-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 16px;
  padding: 6px 10px 6px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.link-back:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.link-back .icon {
  width: 17px;
  height: 17px;
}

.inline-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  align-self: center;
}

.inline-btn {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- badges & notices ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent-strong);
}

.badge-good {
  background: var(--success-soft);
  border-color: transparent;
  color: var(--success);
}

.badge-warn {
  background: var(--warn-soft);
  border-color: transparent;
  color: var(--warn);
}

.badge-open {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-strong);
}

.badge-done {
  background: var(--success-soft);
  border-color: transparent;
  color: var(--success);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
  animation: view-in 0.24s ease both;
}

.notice .icon {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: var(--muted);
  flex: none;
}

.notice strong {
  color: var(--ink);
}

.notice-accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
  color: var(--accent-strong);
}

.notice-accent .icon {
  color: var(--accent-strong);
}

.notice-warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 26%, transparent);
  color: var(--warn);
}

.notice-warn .icon {
  color: var(--warn);
}

.notice-error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 26%, transparent);
  color: var(--danger);
}

.notice-error .icon {
  color: var(--danger);
}

.notice-success {
  background: var(--success-soft);
  border-color: transparent;
  color: var(--success);
}

.notice-success .icon {
  color: var(--success);
}

/* ---------- photo / scan ---------- */

.photo-card {
  padding: 12px;
}

.photo-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 18px 22px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 15px;
  background:
    radial-gradient(circle at 50% 0%, color-mix(in srgb, var(--accent-soft) 70%, transparent) 0%, transparent 68%),
    var(--surface);
  text-align: center;
}

.photo-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 12px;
  border-radius: 17px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent);
}

.photo-icon .icon {
  width: 27px;
  height: 27px;
  stroke-width: 1.6;
}

.photo-title {
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.015em;
}

.photo-sub {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-top: 20px;
}

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

.preview-frame {
  padding: 9px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.preview-frame img {
  display: block;
  width: 100%;
  max-height: 48vh;
  object-fit: contain;
  margin: 0 auto;
  border-radius: 10px;
  background: var(--bg-deep);
}

.photo-preview-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.photo-preview-actions .btn-primary {
  flex: 1;
}

/* ---------- how it works ---------- */

.how {
  margin-top: 18px;
  padding: 18px 18px 10px;
}

.how h2 {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

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

.steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.steps li:first-child {
  border-top: 0;
}

.step-num {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 750;
}

.steps strong {
  display: block;
  font-size: 14px;
  font-weight: 650;
}

.steps p {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.privacy-note {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 18px 6px 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.privacy-note .icon {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  color: var(--muted);
}

/* ---------- forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

label,
.label {
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.005em;
  color: var(--ink-soft);
}

.optional {
  font-weight: 500;
  color: var(--muted);
  font-size: 11.5px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 0 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input {
  height: 48px;
  font-size: 15px;
}

textarea {
  min-height: 84px;
  padding: 12px 13px;
  font-size: 14.5px;
  line-height: 1.55;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--brand) 16%, transparent);
  background: var(--surface);
}

input[type="date"] {
  min-width: 0;
}

input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 12%, transparent);
}

body.no-scroll {
  overflow: hidden;
}

.field-hint {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

.hint-warn {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--warn);
}

.hint-warn .icon {
  width: 15px;
  height: 15px;
  margin-top: 1px;
}

/* ---------- references ---------- */

.refs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ref-row {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr) 30px;
  gap: 5px;
  align-items: center;
}

.ref-row input {
  height: 42px;
  font-size: 12.5px;
  padding: 0 8px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn .icon {
  width: 17px;
  height: 17px;
}

.refs-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 2px 4px;
}

#btnAddRef {
  align-self: flex-start;
  margin-top: 2px;
}

/* ---------- email helper ---------- */

.email-tools {
  margin-top: 4px;
  padding: 12px;
  border: 1px dashed color-mix(in srgb, var(--accent) 48%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface));
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.chip {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.chip:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
}

.chips-label {
  width: 100%;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.inline-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
}

.inline-links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 600;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.link-btn:disabled {
  opacity: 0.5;
  text-decoration: none;
  cursor: default;
}

.link-btn .icon {
  width: 14px;
  height: 14px;
}

.mini-spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 4px;
  vertical-align: -1px;
  border: 1.7px solid color-mix(in srgb, var(--brand) 20%, transparent);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.field-hint a {
  color: var(--link);
  font-weight: 650;
}

.inline-links .icon {
  width: 14px;
  height: 14px;
}

/* ---------- draft ---------- */

.email-card {
  overflow: hidden;
  margin-top: 16px;
}

.mail-head {
  padding: 4px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.field-flat {
  gap: 1px;
  padding: 9px 0;
}

.field-flat + .field-flat {
  border-top: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
}

.field-flat label {
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-flat input {
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 14.5px;
  font-weight: 550;
}

.subject-input {
  min-height: 0;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: var(--sans);
  font-size: 14.5px;
  font-weight: 550;
  line-height: 1.35;
  resize: none;
  overflow: hidden;
}

.field-flat input:focus,
.subject-input:focus {
  box-shadow: none;
  background: transparent;
  border-color: transparent;
}

.mail-body-text {
  display: block;
  width: 100%;
  min-height: 430px;
  padding: 18px 17px 22px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.68;
  resize: vertical;
}

.mail-body-text:focus {
  box-shadow: none;
  background: transparent;
}

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

.draft-secondary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.draft-secondary .btn {
  width: 100%;
}

.save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  padding: 0 2px;
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.save-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ---------- segmented / history ---------- */

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
}

.seg-btn {
  flex: 1;
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.seg-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(16, 42, 67, 0.12);
}

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.history-item:hover {
  border-color: var(--line-strong);
}

.history-item:active {
  transform: scale(0.995);
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.avatar.is-done {
  background: var(--success-soft);
  color: var(--success);
}

.history-main {
  flex: 1;
  min-width: 0;
  padding-top: 1px;
}

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

.history-top strong {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
}

.history-meta-row .badge {
  flex: none;
  padding: 2px 7px;
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.history-subject {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  margin-top: 0;
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.history-item .icon-btn {
  width: 32px;
  height: 32px;
  margin: -2px -4px 0 0;
  flex: none;
}

.history-item .icon-btn .icon {
  width: 16px;
  height: 16px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 42px 24px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-bottom: 14px;
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--muted);
}

.empty-icon .icon {
  width: 26px;
  height: 26px;
  stroke-width: 1.5;
}

.empty-state h2 {
  font-size: 17px;
}

.empty-state p {
  margin: 6px 0 18px;
  max-width: 30ch;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- settings rows ---------- */

.app-card {
  margin-top: 20px;
}

.app-card h2 {
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.setting-row:first-of-type {
  border-top: 0;
}

.setting-row strong {
  display: block;
  font-size: 13.5px;
  font-weight: 650;
}

.setting-row p {
  margin-top: 1px;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 70;
  transform: translateX(-50%);
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px 14px calc(7px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border-top: 1px solid var(--line);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 4px 3px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.tab .icon {
  width: 24px;
  height: 24px;
  padding: 3px;
  border-radius: 8px;
  transition: background-color 0.15s ease;
}

.tab.is-active {
  color: var(--brand-strong);
}

.tab.is-active .icon {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tab:hover {
  color: var(--ink);
}

/* ---------- overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fade-in 0.2s ease both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.overlay-card {
  width: min(320px, 100%);
  padding: 22px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
}

.scan-preview {
  position: relative;
  width: 168px;
  height: 208px;
  margin: 0 auto 18px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-deep);
  border: 1px solid var(--line);
}

.scan-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-line {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 8%;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 14px 3px color-mix(in srgb, var(--accent) 70%, transparent);
  animation: scan 1.9s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}

@keyframes scan {
  from {
    top: 8%;
  }
  to {
    top: 88%;
  }
}

.spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto 12px;
  border: 2.5px solid color-mix(in srgb, var(--brand) 18%, transparent);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.overlay-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.overlay-sub {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
  min-height: 2.6em;
}

/* ---------- dialog ---------- */

.dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background: rgba(8, 18, 28, 0.45);
  backdrop-filter: blur(4px);
}

.dialog h2 {
  font-size: 19px;
}

.dialog .lede {
  margin: 8px 0 16px;
  font-size: 13.5px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 100;
  max-width: calc(100vw - 36px);
  padding: 11px 17px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 550;
  text-align: center;
  box-shadow: 0 18px 40px -14px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- responsive ---------- */

@media (min-width: 620px) {
  .app {
    padding-left: 24px;
    padding-right: 24px;
  }

  .topbar {
    margin-left: -24px;
    margin-right: -24px;
    padding-left: 24px;
    padding-right: 24px;
  }

  .photo-empty {
    padding: 40px 30px 30px;
  }

  .photo-actions {
    max-width: 360px;
  }
}

@media (max-width: 360px) {
  .brand-text span {
    display: none;
  }

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

  .grid-2-address {
    grid-template-columns: 88px 1fr;
  }
}

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