:root {
  color-scheme: light;
  --bg: #e8ece8;
  --surface: #f9faf7;
  --surface-2: #eef2ed;
  --ink: #17201b;
  --muted: #647069;
  --line: #d8ded7;
  --accent: #1e6f5c;
  --accent-ink: #ffffff;
  --warm: #a05a2c;
  --warn-bg: #fff1df;
  --danger: #a33434;
  --shadow: 0 24px 70px rgba(25, 38, 30, 0.18);
  --native-safe-top: env(safe-area-inset-top, 0px);
  --native-safe-bottom: env(safe-area-inset-bottom, 0px);
  --native-safe-left: env(safe-area-inset-left, 0px);
  --native-safe-right: env(safe-area-inset-right, 0px);
  --app-safe-bottom: var(--native-safe-bottom);
  --content-safe-bottom: min(var(--app-safe-bottom), 20px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

.prototype {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(28px + var(--native-safe-top)) calc(16px + var(--native-safe-right))
    calc(28px + var(--content-safe-bottom)) calc(16px + var(--native-safe-left));
}

.phone {
  position: relative;
  width: min(100%, 410px);
  height: min(860px, calc(100dvh - 56px - var(--native-safe-top) - var(--content-safe-bottom)));
  min-height: min(720px, calc(100dvh - var(--native-safe-top) - var(--content-safe-bottom)));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(23, 32, 27, 0.08);
  border-radius: 34px;
  box-shadow: var(--shadow);
}

.statusbar {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  color: rgba(23, 32, 27, 0.72);
  font-size: 12px;
  font-weight: 700;
}

.screen {
  position: absolute;
  inset: 34px 0 0;
  display: none;
  overflow-y: auto;
  padding: 22px 20px calc(28px + var(--content-safe-bottom));
  scroll-padding-bottom: calc(28px + var(--content-safe-bottom));
}

.screen.active {
  display: block;
}

.screen::-webkit-scrollbar {
  width: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  line-height: 1.15;
  font-size: 24px;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  letter-spacing: 0;
}

.muted {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.lock-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  padding-top: 36px;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--ink);
  color: var(--surface);
  font-size: 26px;
  font-weight: 900;
}

.connection-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.connection-panel div {
  min-width: 0;
}

.connection-panel strong {
  display: block;
  font-size: 13px;
}

.connection-panel span {
  color: var(--muted);
  font-size: 12px;
}

.state-pill {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 999px;
  background: #dbeee4;
  color: var(--accent);
  font-weight: 800;
}

.pattern-panel {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.pattern-head,
.edit-form label {
  display: grid;
  gap: 8px;
}

.pattern-head {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.pattern-head span,
.edit-form label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.edit-form label input:not([type="checkbox"]),
.edit-form textarea,
.edit-form select,
.modal-sheet input,
.modal-sheet select,
.form-field-row select,
.form-field-row input:not([type="checkbox"]) {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.edit-form label input:not([type="checkbox"]),
.edit-form select,
.modal-sheet input,
.modal-sheet select,
.form-field-row select,
.form-field-row input:not([type="checkbox"]) {
  min-height: 46px;
  padding: 0 12px;
}

.edit-form textarea {
  min-height: 110px;
  padding: 12px;
  resize: vertical;
}

.pattern-pad {
  width: min(72vw, 246px);
  max-width: 100%;
  aspect-ratio: 1;
  margin: 2px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  place-items: center;
  gap: 18px;
  padding: 18px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
  touch-action: none;
  user-select: none;
}

.pattern-pad.tracking {
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 0 0 3px rgba(30, 111, 92, 0.08);
}

.pattern-dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow:
    inset 0 0 0 1px #bfcbc3,
    0 0 0 12px rgba(238, 242, 237, 0.74);
}

.pattern-status {
  min-height: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.app-header,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.app-header > div,
.toolbar > div {
  min-width: 0;
}

.app-header h1,
.toolbar h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.save-button {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--accent-ink);
  font-size: 26px;
  font-weight: 700;
}

.icon-button.secondary {
  background: var(--surface-2);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.icon-button.mini {
  min-width: 34px;
  width: 34px;
  height: 34px;
  font-size: 21px;
}

.save-button {
  width: auto;
  padding: 0 16px;
  font-size: 14px;
}

.search-box {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 0 14px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.search-box.compact {
  margin-bottom: 14px;
}

.search-box span {
  color: var(--muted);
  font-size: 20px;
}

.search-box input,
.edit-form input:not([type="checkbox"]) {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.empty-state {
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.content-section {
  margin-top: 24px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.text-button {
  padding: 5px 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

.quick-list,
.item-list,
.timeline-list,
.field-stack {
  display: grid;
  gap: 10px;
}

.favorite-item,
.vault-row,
.timeline-list button,
.field-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  box-shadow: inset 0 0 0 1px var(--line);
}

.favorite-item > span:last-child,
.row-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.favorite-item strong,
.vault-row strong,
.timeline-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

small {
  color: var(--muted);
  font-size: 12px;
}

.item-type {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 900;
}

.item-type.text {
  background: #e3f1e7;
  color: #185843;
}

.item-type.image {
  background: #e8ecff;
  color: #293d91;
}

.item-type.file {
  background: #fff0d9;
  color: #854c12;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.category-card {
  min-height: 92px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  padding: 14px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.category-open {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.category-open strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-open span {
  color: var(--muted);
  font-size: 12px;
}

.category-reorder {
  display: grid;
  gap: 6px;
}

.category-order {
  width: 34px;
  min-height: 32px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 15px;
  font-weight: 900;
}

.category-order:disabled {
  color: var(--muted);
  opacity: 0.35;
}

.timeline-list button {
  justify-content: space-between;
}

.category-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.category-actions button {
  min-height: 40px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--line);
}

.category-actions .danger {
  color: var(--danger);
}

.row-action {
  margin-left: auto;
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.field-row {
  align-items: flex-start;
  justify-content: space-between;
}

.field-row > div:first-child {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.field-row strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.field-row p {
  color: var(--ink);
  line-height: 1.5;
  font-size: 14px;
}

.file-detail {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: start;
}

.file-detail .button-pair {
  grid-column: 1 / -1;
  width: 100%;
}

.file-detail .button-pair .small-button {
  flex: 1;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--line);
}

.small-button.strong {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
}

.button-pair {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.note-row {
  display: block;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.detail-actions button,
.primary-button {
  min-height: 46px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--line);
}

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
  font-weight: 900;
}

.primary-button.full {
  width: 100%;
}

.detail-actions .danger {
  color: var(--danger);
}

.segmented {
  height: 44px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-2);
  margin-bottom: 18px;
}

.segmented button {
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented .active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(23, 32, 27, 0.08);
}

.edit-form {
  display: grid;
  gap: 14px;
}

.form-fields {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

#field-editor {
  display: grid;
  gap: 14px;
}

.form-field-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(108px, 0.44fr) 44px;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow:
    inset 0 0 0 1px var(--line),
    0 8px 18px rgba(23, 32, 27, 0.045);
}

.form-field-row:focus-within {
  box-shadow:
    inset 0 0 0 1px rgba(30, 111, 92, 0.46),
    0 0 0 3px rgba(30, 111, 92, 0.08);
}

.form-field-row.field-row-highlight {
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 0 0 4px rgba(30, 111, 92, 0.1),
    0 12px 24px rgba(23, 32, 27, 0.08);
}

.form-field-row > [data-field-label] {
  grid-column: 1 / 2;
  grid-row: 1;
}

.field-type-select {
  grid-column: 2 / 3;
  grid-row: 1;
}

.field-remove {
  grid-column: 3 / 4;
  grid-row: 1;
}

.field-value-input,
.file-picker {
  grid-column: 1 / 3;
  grid-row: 2;
}

.field-copy {
  grid-column: 3 / 4;
  grid-row: 2;
}

.file-field-row .file-picker {
  grid-column: 1 / -1;
}

.form-field-row input:not([type="checkbox"]),
.form-field-row select,
.file-picker {
  background: var(--surface);
}

.file-picker {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.file-pick-button {
  position: relative;
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  overflow: hidden;
}

.file-pick-button span {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

.field-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  cursor: pointer;
}

.selected-file-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-remove,
.field-copy {
  min-height: 46px;
  min-width: 44px;
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 900;
}

.field-remove {
  color: var(--danger);
  font-size: 18px;
}

.field-copy {
  color: var(--accent);
  font-size: 12px;
}

.checkbox-row {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
}

.edit-form .checkbox-row input[type="checkbox"],
.checkbox-row input[type="checkbox"] {
  appearance: auto;
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
}

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

.add-field {
  min-height: 44px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 900;
}

.hidden {
  display: none !important;
}

.form-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.4;
}

.toast {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 20px;
  bottom: calc(16px + var(--content-safe-bottom));
  z-index: 20;
  display: none;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(23, 32, 27, 0.94);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.toast.visible {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  padding: 16px 16px calc(16px + var(--content-safe-bottom));
  background: rgba(23, 32, 27, 0.38);
}

.modal-sheet {
  width: 100%;
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(23, 32, 27, 0.24);
}

.modal-sheet h2 {
  font-size: 18px;
}

.modal-sheet p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.modal-sheet input:focus,
.modal-sheet select:focus {
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 0 0 3px rgba(30, 111, 92, 0.10);
}

.modal-sheet label:not(.radio-row) {
  display: grid;
  gap: 8px;
}

.modal-sheet label > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.radio-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
}

.radio-row input {
  width: 18px;
  height: 18px;
}

.modal-sheet .radio-row input[type="radio"] {
  appearance: auto;
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
}

.modal-sheet .radio-row input[type="radio"]:focus {
  outline: 2px solid rgba(30, 111, 92, 0.28);
  outline-offset: 2px;
  box-shadow: none;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.modal-actions button {
  min-height: 44px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 900;
  box-shadow: inset 0 0 0 1px var(--line);
}

.modal-actions a {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
  box-shadow: inset 0 0 0 1px var(--line);
}

.modal-actions .danger {
  background: var(--danger);
  color: #ffffff;
  box-shadow: none;
}

.modal-actions .primary-action {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
}

.preview-sheet {
  height: min(780px, calc(100% - 8px));
  max-height: calc(100dvh - 40px - var(--content-safe-bottom));
  grid-template-rows: auto minmax(220px, 1fr) auto auto auto;
}

.preview-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: start;
  gap: 12px;
}

.preview-head h2,
.preview-head p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-body {
  min-height: 220px;
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: none;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: grab;
}

.preview-body.is-panning {
  cursor: grabbing;
}

.preview-stage {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.preview-stage canvas,
.preview-stage img {
  position: absolute;
  display: block;
  max-width: none;
  max-height: none;
  user-select: none;
  -webkit-user-drag: none;
}

.preview-image {
  object-fit: contain;
  image-rendering: auto;
}

.preview-loading,
.preview-empty {
  display: grid;
  gap: 8px;
  padding: 18px;
  text-align: center;
}

.preview-empty strong {
  overflow-wrap: anywhere;
}

.preview-empty span,
.preview-loading {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.pdf-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.pdf-nav button {
  min-height: 38px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 900;
  box-shadow: inset 0 0 0 1px var(--line);
}

.pdf-nav button:disabled {
  opacity: 0.4;
}

.pdf-nav span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.preview-toolbar {
  display: grid;
  grid-template-columns: 42px minmax(64px, 1fr) 42px auto auto;
  align-items: center;
  gap: 8px;
}

.preview-toolbar button,
.preview-toolbar span {
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px var(--line);
}

.preview-toolbar span {
  color: var(--muted);
}

.preview-toolbar button:disabled {
  opacity: 0.4;
}

.modal-actions button:disabled {
  opacity: 0.45;
}

@media (max-width: 520px) {
  .prototype {
    --content-safe-bottom: min(var(--native-safe-bottom), 16px);
    display: block;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: var(--native-safe-top) var(--native-safe-right) 0 var(--native-safe-left);
  }

  .phone {
    width: calc(100vw - var(--native-safe-left) - var(--native-safe-right));
    height: calc(100vh - var(--native-safe-top));
    height: calc(100dvh - var(--native-safe-top));
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .file-preview-backdrop {
    padding: 0 0 var(--content-safe-bottom);
  }

  .preview-sheet {
    height: 100%;
    max-height: none;
    border-radius: 0;
    grid-template-rows: auto minmax(180px, 1fr) auto auto auto;
  }

  .screen {
    padding-bottom: calc(36px + var(--content-safe-bottom));
    scroll-padding-bottom: calc(36px + var(--content-safe-bottom));
  }

  .detail-actions {
    margin-bottom: 0;
  }
}
