:root {
  color-scheme: light;
  --ink: #1f2321;
  --muted: #6b746f;
  --soft: #f4f2ed;
  --panel: #fffdf8;
  --line: #dcd7ce;
  --rose: #a95f68;
  --rose-dark: #83424b;
  --sage: #6f8779;
  --teal: #2f6f73;
  --gold: #b58a4c;
  --danger: #91424a;
  --shadow: 0 18px 48px rgba(31, 35, 33, 0.11);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(111, 135, 121, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(181, 138, 76, 0.1), transparent 28%),
    var(--soft);
  color: var(--ink);
}

body {
  min-height: 100dvh;
}

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

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 111, 115, 0.28);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100dvh;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
}

.topbar,
.panel,
.camera-frame,
.analysis-panel {
  border: 1px solid rgba(31, 35, 33, 0.11);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 86px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand-block {
  min-width: 0;
}

.top-subtitle,
.muted,
.policy-copy,
.disclaimer,
.provider-error {
  color: var(--muted);
}

.top-subtitle {
  margin: 8px 0 0;
  font-size: 0.96rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  letter-spacing: 0;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.08rem;
}

h3 {
  font-size: 1.15rem;
}

h4 {
  font-size: 0.98rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.counter-pill {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #ece8de;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 720;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #a6aaa4;
}

.status-pill.is-active .status-dot {
  background: var(--teal);
  animation: breathe 1.8s ease-in-out infinite;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, 0.8fr) minmax(420px, 1.35fr) minmax(300px, 0.9fr);
  gap: 14px;
}

.panel,
.analysis-panel {
  min-width: 0;
  min-height: 0;
  padding: 16px;
}

.client-panel,
.gallery-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}

.gallery-panel {
  grid-template-rows: auto minmax(190px, 0.9fr) auto minmax(170px, 0.8fr);
}

.panel-head {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-head.compact {
  margin-top: 12px;
}

.client-form,
.analysis-controls {
  display: grid;
  gap: 10px;
}

label {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fffaf2;
  color: var(--ink);
  font-weight: 570;
}

textarea {
  resize: vertical;
  line-height: 1.35;
}

.check-row {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 640;
  line-height: 1.35;
}

.check-row input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 2px 0 0;
  accent-color: var(--teal);
}

.policy-copy {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
}

.form-actions,
.camera-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.control-button,
.icon-button,
.text-button,
.client-item,
.history-item,
.select-chip {
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, opacity 160ms ease, border-color 160ms ease;
}

.control-button:active,
.icon-button:active,
.text-button:active,
.client-item:active,
.history-item:active,
.select-chip:active {
  transform: translateY(1px) scale(0.99);
}

.control-button {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: white;
  font-weight: 760;
  text-decoration: none;
}

.control-button.primary {
  background: var(--ink);
}

.control-button.accent {
  background: var(--rose-dark);
}

.control-button:disabled,
.icon-button:disabled,
.text-button:disabled,
.select-chip:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background: #ebe6db;
  color: var(--ink);
}

.text-button,
.select-chip {
  min-height: 36px;
  padding: 0 11px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ebe6db;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 760;
  white-space: nowrap;
}

.text-button.danger {
  color: var(--danger);
}

.active-client {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f7f3eb;
  display: grid;
  gap: 4px;
}

.active-client strong,
.active-client span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.active-client span {
  color: var(--muted);
  font-size: 0.82rem;
}

.client-list,
.history-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.client-item,
.history-item {
  width: 100%;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fffaf2;
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: 4px;
}

.client-item.is-active,
.history-item:hover,
.client-item:hover {
  border-color: rgba(47, 111, 115, 0.38);
  background: #f1f6f3;
}

.client-item span,
.history-item span,
.history-item em {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
}

.capture-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(360px, 1.05fr) minmax(250px, 0.95fr);
  gap: 14px;
}

.camera-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.camera-frame {
  position: relative;
  min-height: 340px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #202522;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #202522;
}

video.is-mirrored {
  transform: scaleX(-1);
}

.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background:
    linear-gradient(150deg, rgba(31, 35, 33, 0.92), rgba(31, 35, 33, 0.68)),
    #202522;
  color: rgba(255, 255, 255, 0.78);
  transition: opacity 200ms ease, transform 200ms ease;
}

.camera-empty.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.02);
}

.empty-mark {
  width: 112px;
  height: 146px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: grid;
  place-items: center;
}

.face-guide {
  position: relative;
  width: min(45%, 285px);
  height: min(76%, 500px);
  min-width: 190px;
  min-height: 286px;
  border: 2px solid rgba(255, 255, 255, 0.94);
  border-radius: 50%;
  box-shadow:
    0 0 0 999px rgba(28, 32, 30, 0.36),
    inset 0 0 0 1px rgba(181, 138, 76, 0.45);
}

.guide-line {
  position: absolute;
  left: 50%;
  width: 28%;
  height: 2px;
  background: rgba(255, 255, 255, 0.72);
  transform: translateX(-50%);
}

.guide-top {
  top: 18%;
}

.guide-bottom {
  bottom: 18%;
}

.capture-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: white;
  opacity: 0;
}

.capture-flash.is-flashing {
  animation: flash 280ms ease-out;
}

.camera-actions {
  grid-template-columns: minmax(110px, 1fr) minmax(110px, 1fr) 46px 46px;
}

.analysis-panel {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 13px;
}

.analysis-controls {
  grid-template-columns: minmax(115px, 0.7fr) minmax(130px, 0.7fr) auto;
  align-items: end;
}

.paid-row {
  min-height: 42px;
  align-content: center;
}

.notes-field {
  min-width: 0;
  grid-column: 1 / -1;
}

.analysis-output {
  min-height: 120px;
}

.analysis-card {
  display: grid;
  gap: 13px;
}

.analysis-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-row span {
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 10px;
  background: #edf4ef;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 760;
}

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

.product-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf2;
  display: grid;
  gap: 8px;
}

.product-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.38;
}

.product-card a {
  color: var(--rose-dark);
  font-weight: 760;
  text-decoration: none;
}

.analysis-card section {
  display: grid;
  gap: 8px;
}

.analysis-card ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.explanation {
  margin: 0;
  color: var(--ink);
  line-height: 1.42;
}

.disclaimer,
.provider-error {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.38;
}

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

.professional-box {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.gallery-grid {
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 10px;
  padding-right: 2px;
}

.photo-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffaf2;
}

.photo-card.is-selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(47, 111, 115, 0.16);
}

.photo-card.is-pending {
  opacity: 0.72;
}

.photo-card.is-failed {
  border-color: var(--danger);
}

.photo-open {
  width: 100%;
  aspect-ratio: 4 / 5;
  padding: 0;
  display: block;
  background: #d8d0c4;
  overflow: hidden;
}

.photo-open img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.photo-meta {
  min-height: 44px;
  padding: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.photo-meta time {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 690;
}

.select-chip {
  min-height: 30px;
  padding: 0 8px;
  background: #ede7da;
  font-size: 0.76rem;
}

.photo-card.is-selected .select-chip {
  background: var(--teal);
  color: white;
}

.history-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
}

.empty-state {
  min-height: 54px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  font-size: 0.86rem;
  line-height: 1.35;
}

.empty-state.is-hidden {
  display: none;
}

.notice {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 40;
  max-width: min(560px, calc(100% - 28px));
  min-height: 44px;
  padding: 12px 15px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: white;
  box-shadow: 0 20px 50px rgba(31, 35, 33, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 0.9rem;
  font-weight: 710;
  text-align: center;
}

.notice.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.notice[data-tone="success"] {
  background: var(--teal);
}

.notice[data-tone="error"] {
  background: var(--danger);
}

.loading-block {
  min-height: 120px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
}

.loading-block span {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(47, 111, 115, 0.18);
  border-top-color: var(--teal);
  border-radius: 999px;
  animation: spin 900ms linear infinite;
}

.photo-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 22px;
}

.photo-modal.is-open {
  display: grid;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(19, 22, 20, 0.72);
}

.modal-body {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
  max-height: calc(100dvh - 44px);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  display: grid;
  gap: 10px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.34);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-body img {
  width: 100%;
  max-height: calc(100dvh - 160px);
  border-radius: 8px;
  object-fit: contain;
  background: #1c211e;
}

.modal-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

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

@keyframes breathe {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.68;
  }
  50% {
    transform: scale(1.42);
    opacity: 1;
  }
}

@keyframes flash {
  0% {
    opacity: 0.78;
  }
  100% {
    opacity: 0;
  }
}

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

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(300px, 0.85fr) minmax(430px, 1.15fr);
  }

  .gallery-panel {
    grid-column: 1 / -1;
    grid-template-rows: auto auto auto auto;
  }

  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: 360px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  h1 {
    font-size: 1.55rem;
  }

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

  .capture-panel {
    grid-template-rows: auto auto;
  }

  .camera-frame {
    min-height: 320px;
  }

  .analysis-controls,
  .professional-box,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
  }
}

@media (max-width: 520px) {
  .panel,
  .analysis-panel,
  .topbar {
    padding: 12px;
  }

  .camera-actions {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px 44px;
  }

  .control-button,
  .icon-button {
    min-height: 44px;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

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

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

  .face-guide {
    min-width: 168px;
    min-height: 252px;
  }
}
