/* grorder Mini App styles. Single source of truth: the prototype in designs/ links this file.
 * Colors come from the Telegram theme (telegram-web-app.js sets --tg-theme-* on :root);
 * the fallbacks keep the page readable in a plain browser, light and dark.
 * color-scheme is set by app.js from Telegram.WebApp.colorScheme. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --separator: var(--tg-theme-section-separator-color, rgba(142, 142, 147, 0.3));
  --radius: 12px;
  --gap: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #708499);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --button: var(--tg-theme-button-color, #5288c1);
    --button-text: var(--tg-theme-button-text-color, #ffffff);
    --surface: var(--tg-theme-secondary-bg-color, #232e3c);
    --danger: var(--tg-theme-destructive-text-color, #ec3942);
    --separator: var(--tg-theme-section-separator-color, rgba(112, 132, 153, 0.3));
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
  word-break: break-word;
}

a { color: var(--link); text-decoration: none; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }

a:focus-visible, button:focus-visible { outline: 2px solid var(--button); outline-offset: 2px; }

/* #screen holds the current fragment; .screen-body and .cart are wrappers inside it. */
#screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px max(24px, env(safe-area-inset-bottom));
}
#screen, .screen-body, .cart { display: flex; flex-direction: column; gap: var(--gap); }

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0; }

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

/* --- surfaces --- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); }
.list > li + li { border-top: 1px solid var(--separator); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  color: var(--text);
  text-align: left;
}
a.row::after { content: "›"; color: var(--hint); font-size: 22px; line-height: 1; }
.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-side { color: var(--hint); font-size: 14px; white-space: nowrap; }

/* --- buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--link);
  text-align: center;
}
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-danger { color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.4; cursor: default; pointer-events: none; }
.btn.htmx-request { opacity: 0.6; }

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

/* Primary action pinned to the bottom of long forms. */
.sticky-actions {
  position: sticky;
  bottom: 0;
  margin: 0 -16px;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--separator);
}

/* --- cart --- */

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.item { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; }
.item-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.item-qty { color: var(--button); white-space: nowrap; }
.item-meta { color: var(--hint); font-size: 14px; margin-top: 2px; }
.item-error { color: var(--danger); font-size: 14px; margin-top: 6px; }
.is-sold-out .item-head { color: var(--hint); }

.stepper { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

.lines { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.lines li, .total { display: flex; justify-content: space-between; gap: 8px; }
.lines .short { color: var(--hint); font-size: 14px; }
.total { font-weight: 600; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--separator); }

/* --- marks (Забрал / Оплатил): toggle buttons with aria-pressed --- */

.marks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn[aria-pressed="true"] { background: var(--button); color: var(--button-text); }

/* --- notices --- */

.notice { border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.notice-warn { border-left: 4px solid var(--danger); }
.notice-info { border-left: 4px solid var(--button); }
.notice .actions { margin-top: 10px; }

.badge { font-size: 13px; color: var(--hint); white-space: nowrap; }
.badge-warn { color: var(--danger); }

/* --- forms --- */

.form { display: flex; flex-direction: column; gap: var(--gap); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; color: var(--hint); }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--separator);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* below 16px iOS zooms into the field */
}
textarea { min-height: 96px; resize: vertical; }
#catalog-text { min-height: 140px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input:focus, textarea:focus { outline: 2px solid var(--button); outline-offset: -1px; }
[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 14px; white-space: pre-line; }

/* --- text blocks to copy (chat post, seller order) --- */

.textblock {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  white-space: pre-wrap;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- collapsed secondary path (catalog «Вставить списком») --- */

details > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--link);
  font-weight: 500;
  cursor: pointer;
}
details[open] > summary { margin-bottom: 8px; }

/* --- bulk send progress --- */

progress { width: 100%; height: 8px; accent-color: var(--button); }

/* --- toast: short messages from the server (HX-Trigger "toast") --- */

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 448px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
}

/* app.js focuses the new screen's heading for screen readers; that is not a keyboard focus to show */
h1[tabindex="-1"]:focus { outline: none; }
