/* VTO Mini App — styles.css
   BEM, CSS custom properties, mobile-first 320–420px
   State-driven visibility via body[data-state] */

/* ─── Custom Properties (set by telegram.js at runtime) ─── */
:root {
  --vto-bg:          #ffffff;
  --vto-surface:     #f4f4f5;
  --vto-card:        #ffffff;
  --vto-text:        #1a1a1a;
  --vto-hint:        #888888;
  --vto-button-bg:   #2D2D2D;
  --vto-button-text: #ffffff;
  --vto-accent:      #2D2D2D;
  --vto-radius:      12px;
  --vto-radius-sm:   8px;
  --vto-spacing:     16px;
  --vto-upload-h:    170px;
  --vto-border:      1px solid rgba(0,0,0,0.08);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--vto-bg);
  color: var(--vto-text);
  font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screen visibility ─── */
.screen { display: none; width: 100%; height: 100%; }

body[data-state="loading"]    .screen--loading    { display: flex; }
body[data-state="initial"]    .screen--main       { display: flex; }
body[data-state="ready"]      .screen--main       { display: flex; }
body[data-state="processing"] .screen--processing { display: flex; }
body[data-state="success"]    .screen--success    { display: flex; }
body[data-state="error"]      .screen--error      { display: flex; }

/* ─── Loading screen ─── */
.screen--loading {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--vto-bg);
}

.loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--vto-surface);
  border-top-color: var(--vto-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader__text {
  color: var(--vto-hint);
  font-size: 14px;
}

/* ─── Main screen ─── */
.screen--main {
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--vto-bg);
}

/* ─── App header ─── */
.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px var(--vto-spacing);
  border-bottom: var(--vto-border);
  background: var(--vto-bg);
  min-height: 52px;
  flex-shrink: 0;
}

.app-header__logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.app-header__name {
  font-size: 16px;
  font-weight: 600;
  color: var(--vto-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Upload area ─── */
.upload-area {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: var(--vto-spacing);
  flex-shrink: 0;
}

/* ─── Upload zone ─── */
.upload-zone {
  position: relative;
  height: var(--vto-upload-h);
  background: var(--vto-surface);
  border-radius: var(--vto-radius);
  border: 2px dashed rgba(0,0,0,0.12);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.upload-zone:active {
  background: rgba(0,0,0,0.06);
}

.upload-zone--filled {
  border-style: solid;
  border-color: var(--vto-accent);
}

.upload-zone__placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 100%;
  padding: 12px;
  pointer-events: none;
}

.upload-zone--filled .upload-zone__placeholder {
  display: none;
}

.upload-zone__icon {
  width: 36px;
  height: 36px;
  color: var(--vto-hint);
  flex-shrink: 0;
}

.upload-zone__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--vto-text);
  text-align: center;
  line-height: 1.3;
}

.upload-zone__hint {
  font-size: 11px;
  color: var(--vto-hint);
  text-align: center;
}

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

/* ─── Category picker ─── */
.category-picker {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 2px;
}

.category-picker::-webkit-scrollbar { display: none; }

.category-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid rgba(0,0,0,0.12);
  background: transparent;
  color: var(--vto-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.category-btn--active {
  background: var(--vto-accent);
  color: var(--vto-button-text);
  border-color: var(--vto-accent);
}

/* ─── Processing screen ─── */
.screen--processing {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--vto-bg);
  padding: var(--vto-spacing);
  text-align: center;
}

.processing__spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--vto-surface);
  border-top-color: var(--vto-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.processing__text {
  font-size: 17px;
  font-weight: 600;
  color: var(--vto-text);
}

.processing__subtext {
  font-size: 13px;
  color: var(--vto-hint);
  margin-top: -12px;
}

/* ─── Success screen ─── */
.screen--success {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--vto-bg);
  padding-bottom: 80px; /* space for MainButton */
}

.result-container {
  width: 100%;
  max-width: 420px;
}

.result__image {
  width: 100%;
  display: block;
}

/* ─── Error screen ─── */
.screen--error {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--vto-bg);
  padding: var(--vto-spacing);
  text-align: center;
}

.error__icon {
  font-size: 48px;
  line-height: 1;
}

.error__message {
  font-size: 15px;
  color: var(--vto-text);
  max-width: 280px;
  line-height: 1.5;
}

/* ─── Animation ─── */
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Larger phones (390px+) ─── */
@media (min-width: 390px) {
  :root { --vto-upload-h: 190px; }
}
