:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111114;
  --muted: #6c6c72;
  --line: rgba(60, 60, 67, 0.16);
  --accent: #0a6cff;
  --accent-fill: #0a6cff;
  --wa: #1a9f53;
  --danger: #e5484d;
  --chip: #e5e5ea;
  --chip-on: #111114;
  --chip-on-ink: #ffffff;
  --pending: #b35f00;
  --done: #1c8048;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 6px 20px rgba(0, 0, 0, 0.05);
  --bar: rgba(242, 242, 247, 0.86);
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1f;
    --text: #f4f4f6;
    --muted: #9d9da5;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #3d8bff;
    --accent-fill: #1d6ae5;
    --chip: #2a2a2e;
    --chip-on: #f4f4f6;
    --chip-on-ink: #111114;
    --pending: #ffb340;
    --done: #4cd27e;
    --shadow: none;
    --bar: rgba(18, 18, 20, 0.86);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body.locked {
  overflow: hidden;
}

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

input,
textarea {
  font: inherit;
  font-size: 16px;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
}

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

.icon-xs {
  width: 12px;
  height: 12px;
}

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

.small {
  font-size: 14px;
}

.center {
  text-align: center;
}

.offscreen {
  position: fixed;
  left: -9999px;
  top: 0;
  opacity: 0;
}

/* Layout */
.view {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(var(--tab-h) + var(--safe-b) + 28px);
}

.view-form {
  padding-bottom: calc(100px + var(--safe-b));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  margin: 0 -16px;
  padding: var(--safe-t) 16px 0;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
}

.topbar.has-title {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
}

.topbar-side {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar:not(.has-title) .topbar-side:first-child {
  flex: 1;
}

.topbar-right {
  flex: none;
  justify-content: flex-end;
}

.topbar-title {
  font-weight: 600;
  font-size: 17px;
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.large-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 4px 0 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 15px;
  min-width: 0;
  max-width: 100%;
}

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

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 999px;
}

.icon-btn:active {
  background: var(--chip);
}

.icon-btn-sm {
  width: 36px;
  height: 36px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  margin-left: -8px;
  color: var(--accent);
  font-size: 17px;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  height: 44px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
}

/* Search + chips */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--chip);
  color: var(--muted);
}

.search {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.chips-scroll,
.composer .chips {
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-left: -16px;
  margin-right: -16px;
  padding: 0 16px;
  scrollbar-width: none;
}

.chips-scroll::-webkit-scrollbar,
.composer .chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}

.chip-on {
  background: var(--chip-on);
  color: var(--chip-on-ink);
}

/* List */
.list,
.group {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list > li + li,
.group > li + li {
  border-top: 1px solid var(--line);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px 14px;
}

.row:active,
.option:active {
  background: var(--chip);
}

.avatar {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

.tag-founder { background: #0a6cff; }
.tag-investor { background: #7a4ff0; }
.tag-salon { background: #e83e7c; }
.tag-partner { background: #e58600; }
.tag-other { background: #8a8a90; }

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

.row-title,
.row-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-title {
  font-weight: 600;
}

.row-sub {
  color: var(--muted);
  font-size: 14px;
}

.row-meta {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
}

.status-done { color: var(--done); }
.status-pending { color: var(--pending); }

.row-time {
  font-size: 12px;
  color: var(--muted);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 16px;
  text-align: center;
}

.empty p {
  margin: 0;
}

.empty-title {
  font-size: 20px;
  font-weight: 700;
}

/* Tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: calc(var(--tab-h) + var(--safe-b));
  padding: 0 28px var(--safe-b);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.tab.active {
  color: var(--accent);
}

.tab-add {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  margin-top: -26px;
  border-radius: 999px;
  background: var(--accent-fill);
  color: #fff;
  box-shadow: 0 8px 22px rgba(10, 108, 255, 0.35);
}

.tab-add .icon {
  width: 30px;
  height: 30px;
  stroke-width: 2.5;
}

.tab-add:active {
  transform: scale(0.95);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.btn-inline {
  width: auto;
  margin-top: 8px;
}

.btn-primary { background: var(--accent-fill); color: #fff; }
.btn-wa { background: var(--wa); color: #fff; }
.btn-secondary { background: var(--chip); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-light { width: auto; background: rgba(255, 255, 255, 0.94); color: #111; }

.btn-danger-ghost {
  margin-top: 28px;
  color: var(--danger);
}

/* Form */
.quick-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 6px 0 16px;
}

.quick {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 54px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-weight: 600;
}

.quick:active {
  background: var(--chip);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pad {
  padding: 14px;
}

.form-card {
  overflow: hidden;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  padding: 9px 14px;
}

.field + .field {
  border-top: 1px solid var(--line);
}

.field:focus-within {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.field-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.field-input {
  width: 100%;
  padding: 3px 0 2px;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
}

.field-label {
  margin: 4px 4px -4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 10px;
  padding: 12px max(16px, calc((100vw - 560px) / 2 + 16px)) calc(12px + var(--safe-b));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}

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

.input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  outline: 0;
}

.input:focus {
  border-color: var(--accent);
}

.inline-form {
  display: flex;
  gap: 8px;
  margin: 8px 0 12px;
}

.inline-form .btn {
  width: auto;
}

/* Contact */
.profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 0 18px;
  text-align: center;
}

.avatar-lg {
  width: 76px;
  height: 76px;
  font-size: 27px;
}

.profile-name {
  margin: 4px 0 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.profile-sub {
  margin: 0;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 13px;
  font-weight: 600;
}

.quick-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.qa {
  flex: 1;
  max-width: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.qa:active {
  background: var(--chip);
}

.section {
  margin: 22px 0;
}

.section-title {
  margin: 0 4px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.option {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  text-align: left;
}

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

.option-title {
  font-weight: 600;
}

.option-sub {
  font-size: 14px;
  color: var(--muted);
}

.option-primary .option-title,
.option-on {
  color: var(--accent);
}

.option.danger {
  color: var(--danger);
}

.sent-mark {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--done);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 14px;
}

.info-value {
  text-align: right;
  overflow-wrap: anywhere;
}

.history-meta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: none;
}

.next-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent-fill);
  color: #fff;
}

.next-link > span {
  display: flex;
  flex-direction: column;
}

.next-label {
  font-size: 13px;
  opacity: 0.85;
}

.next-name {
  font-weight: 600;
}

/* Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.38);
  opacity: 0;
  transition: opacity 0.22s;
}

.sheet-backdrop.open {
  opacity: 1;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-width: 560px;
  max-height: 92dvh;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 16px calc(16px + var(--safe-b));
  border-radius: 20px 20px 0 0;
  background: var(--card);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet.open {
  transform: translateY(0);
}

.sheet-grip {
  width: 40px;
  height: 5px;
  margin: 0 auto 8px;
  border-radius: 3px;
  background: var(--line);
}

.sheet-title {
  margin: 4px 0;
  font-size: 20px;
  font-weight: 700;
}

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

.sheet-body p {
  margin: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.pref {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pref .chips {
  margin: 6px 0 4px;
}

/* Composer */
.composer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.composer .chips {
  margin: 2px -16px;
}

.composer-text {
  width: 100%;
  min-height: 190px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  outline: 0;
  line-height: 1.45;
  resize: vertical;
}

.composer-text:focus {
  border-color: var(--accent);
}

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

.composer-actions .btn {
  min-height: 48px;
  padding: 0 6px;
  font-size: 15px;
}

.composer-actions .btn-main {
  grid-column: 1 / -1;
  min-height: 56px;
  font-size: 18px;
}

/* QR */
.view-card .chips {
  justify-content: center;
}

.qr-box {
  max-width: 400px;
  margin: 6px auto 8px;
  padding: 16px 16px 14px;
  border-radius: 26px;
  background: #fff;
  color: #111;
  box-shadow: var(--shadow);
}

.qr-svg {
  display: block;
  width: 100%;
  height: auto;
}

.qr-box figcaption {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 6px;
  text-align: center;
}

.qr-box strong {
  font-size: 19px;
}

.qr-box figcaption span {
  font-size: 14px;
  color: #555;
  overflow-wrap: anywhere;
}

/* Scanner */
.scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
}

.scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-frame {
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(68vw, 320px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 26px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.38);
}

.scan-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 16px calc(22px + var(--safe-b));
}

.scan-status {
  margin: 0;
  color: #fff;
  font-weight: 500;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + 22px);
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(24, 24, 27, 0.94);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .sheet,
  .sheet-backdrop,
  .toast {
    transition: none;
  }
}
