:root {
  color-scheme: light;
  --color-bg: #ececec;
  --color-surface: #ececec;
  --color-panel: #ffffff;
  --color-text: #111111;
  --color-muted: #666666;
  --color-border: #1f1f1f;
  --color-strong: #050505;
  --screen-max: 30rem;
  --footer-height: 7rem;
}

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

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  font-family: "Avenir Next", "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

body,
button,
input,
label {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

button,
input {
  border-radius: 0;
}

.app-shell {
  min-height: 100svh;
  width: 100%;
  padding-top: env(safe-area-inset-top);
  padding-right: 0;
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: 0;
}

.mobile-stage {
  width: 100%;
  min-height: 100svh;
  margin: 0;
}

.app-frame {
  min-height: inherit;
  background: var(--color-surface);
  border: 0;
  overflow: clip;
}

.screen {
  min-height: inherit;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--color-surface);
}

.screen-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(17, 17, 17, 0.22);
  background: #efefef;
}

.screen-header--center {
  grid-template-columns: 1fr auto 1fr;
}

.header-spacer {
  width: 56px;
  height: 56px;
}

.screen-title {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.nav-button:focus-visible,
.app-button:focus-visible,
.field-input:focus-visible,
.capture-input:focus-visible + .capture-panel {
  outline: 2px solid #000000;
  outline-offset: 2px;
}

.screen-content {
  min-width: 0;
  padding: 16px;
  padding-bottom: calc(var(--footer-height) + 16px + env(safe-area-inset-bottom));
}

.screen-content--empty {
  display: grid;
  place-items: center;
}

.screen-footer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(17, 17, 17, 0.18);
  background: #efefef;
}

.app-button {
  width: 100%;
  min-height: 56px;
  border: 1px solid var(--color-border);
  padding: 14px 18px;
  background: #050505;
  color: #ffffff;
  font-size: 0.98rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.app-button[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.app-button--secondary {
  background: #ffffff;
  color: var(--color-text);
}

.history-stack {
  display: grid;
  gap: 12px;
}

.history-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid rgba(17, 17, 17, 0.72);
  background: var(--color-panel);
}

.history-card-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 1.02rem;
  font-weight: 800;
}

.history-card-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-card-actions {
  position: relative;
}

.card-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(17, 17, 17, 0.25);
  background: #ffffff;
  color: var(--color-text);
  font-size: 1.1rem;
  cursor: pointer;
}

.card-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  min-width: 132px;
  border: 1px solid var(--color-border);
  background: #ffffff;
  z-index: 5;
}

.card-menu-item {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid rgba(17, 17, 17, 0.12);
  background: #ffffff;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}

.card-menu-item:last-child {
  border-bottom: 0;
}

.card-menu-item--danger {
  color: #7b1111;
}

.history-card-body {
  display: grid;
  gap: 12px;
}

.history-row {
  min-width: 0;
}

.history-label,
.helper-text,
.status-banner,
.preview-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-muted);
}

.history-value,
.preview-value {
  min-width: 0;
  font-size: 1rem;
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.empty-state {
  width: 100%;
  padding: 24px;
  border: 1px solid rgba(17, 17, 17, 0.24);
  background: #f3f3f3;
  text-align: center;
}

.empty-icon {
  margin: 0 auto 16px;
  width: clamp(44px, 11vw, 56px);
  height: clamp(44px, 11vw, 56px);
  border: 1px solid rgba(17, 17, 17, 0.44);
  background: #efefef;
}

.empty-state p {
  margin: 0;
  font-size: 1rem;
}

.panel {
  padding: 16px;
  border: 1px solid rgba(17, 17, 17, 0.22);
  background: #f4f4f4;
}

.field-group {
  display: grid;
  gap: 10px;
}

.field-label {
  display: block;
  font-size: 0.96rem;
  font-weight: 700;
}

.field-input {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid rgba(17, 17, 17, 0.62);
  background: #ffffff;
  color: var(--color-text);
}

.field-input::placeholder {
  color: #9a9a9a;
}

.status-banner {
  margin-bottom: 12px;
}

.status-box {
  min-height: 52px;
  padding: 12px;
  border: 1px solid rgba(17, 17, 17, 0.28);
  background: #f0f0f0;
  font-size: 0.98rem;
  line-height: 1.45;
}

.capture-layout {
  display: grid;
  gap: 16px;
}

.capture-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.capture-panel {
  display: grid;
  place-items: center;
  min-height: min(52svh, 420px);
  padding: 0;
  border: 1px solid rgba(17, 17, 17, 0.34);
  background: #efefef;
  text-align: center;
}

.camera-live-wrap {
  position: relative;
  width: 100%;
  min-height: min(52svh, 420px);
  background: #d8d8d8;
}

.camera-video,
.camera-preview-image {
  width: 100%;
  height: min(52svh, 420px);
  object-fit: contain;
  filter: none;
  background: #d8d8d8;
}

.camera-live-overlay {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(17, 17, 17, 0.72) 100%);
  color: #ffffff;
}

.capture-fallback-message {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: min(52svh, 420px);
  padding: 24px;
}

.capture-text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
}

.file-meta {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid rgba(17, 17, 17, 0.18);
  background: #f6f6f6;
  font-size: 0.92rem;
}

.file-meta--loading {
  border-color: rgba(17, 17, 17, 0.26);
  background: #efefef;
}

.file-meta--approved {
  border-color: #1f6b2a;
  background: #dff3e3;
  color: #103f18;
}

.file-meta--rejected {
  border-color: #8a1f1f;
  background: #f7dfdf;
  color: #5a1111;
}

.preview-layout {
  display: grid;
  gap: 16px;
}

.preview-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(17, 17, 17, 0.24);
  background: #f4f4f4;
}

.preview-image-wrap {
  border: 1px solid rgba(17, 17, 17, 0.34);
  background: #ffffff;
  padding: 12px;
}

.preview-image {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  background: #f2f2f2;
}

.loading-text {
  margin-top: 10px;
  font-size: 0.86rem;
  color: var(--color-muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.28);
  z-index: 20;
}

.modal-panel {
  width: 100%;
  max-height: 88svh;
  border-top: 1px solid rgba(17, 17, 17, 0.22);
  background: #efefef;
  overflow: auto;
}

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

.modal-title {
  margin: 0;
  font-size: 1.1rem;
}

.modal-content {
  display: grid;
  gap: 12px;
  padding: 16px;
}

@media (min-width: 768px) {
  .modal-backdrop {
    place-items: center;
    padding: 24px;
  }

  .modal-panel {
    max-width: 560px;
    border: 1px solid rgba(17, 17, 17, 0.22);
  }
}

@media (max-width: 360px) {
  .screen-header,
  .screen-content,
  .screen-footer {
    padding-right: 12px;
    padding-left: 12px;
  }

  .history-card,
  .panel,
  .preview-card {
    padding: 14px;
  }

  .history-card-header {
    grid-template-columns: 1fr;
  }

  .history-card-title {
    flex-direction: column;
    align-items: flex-start;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}
