/* ============================================================
   Apple-style Light Theme · readable, high-contrast
   ============================================================ */

:root {
  /* Light palette (iOS) */
  --bg-primary:     #f2f2f7;   /* системный фон */
  --bg-secondary:   #ffffff;   /* карточки/поверхность */
  --bg-tertiary:    #f7f7fa;   /* hover/легкая поверхность */
  --bg-quaternary:  #e5e5ea;   /* разделители блоков */

  --text-primary:   #1c1c1e;   /* основной текст */
  --text-secondary: #3a3a3c;   /* второстепенный */
  --text-tertiary:  #636366;   /* подсказки/плейсхолдеры */
  --text-on-accent: #ffffff;

  --accent:         #0a84ff;
  --accent-pressed: #0066cc;
  --success:        #34c759;
  --warning:        #ff9f0a;
  --danger:         #ff3b30;

  --border-light:   rgba(60, 60, 67, 0.18);
  --border-heavy:   rgba(60, 60, 67, 0.32);
  --separator:      rgba(60, 60, 67, 0.10);

  --shadow-sm:      0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md:      0 4px 14px rgba(0, 0, 0, 0.10);
  --shadow-lg:      0 12px 32px rgba(0, 0, 0, 0.14);

  --radius-xs:      6px;
  --radius-sm:      10px;
  --radius-md:      14px;
  --radius-lg:      18px;
  --radius-xl:      22px;

  --topbar-h:       60px;
  --tabbar-h:       66px;
  --safe-bottom:    env(safe-area-inset-bottom, 0px);
  --safe-top:       env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

body { overflow-x: hidden; }

body.tg-web-app {
  /* Поверх Telegram theme можем взять системный фон только если он светлый */
  background: var(--bg-primary);
  color: var(--text-primary);
}

::selection { background: rgba(10, 132, 255, 0.25); color: var(--text-primary); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-heavy); border-radius: 8px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

[hidden] { display: none !important; }

h1, h2, h3, h4 {
  margin: 0 0 0.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
h1 { font-size: 1.7rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 0.75rem; color: var(--text-secondary); }
small, .small { font-size: 0.78rem; color: var(--text-tertiary); }

.muted, .text-muted { color: var(--text-tertiary) !important; }
.text-dim    { color: var(--text-secondary); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.text-accent { color: var(--accent); }

/* ===== form controls ==================================== */
input, select, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.9rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.18);
  background: #fff;
}
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-bottom: 0.3rem;
  letter-spacing: 0;
}
.field { margin-bottom: 0.85rem; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 0; }

/* ===== topbar =========================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(0.5rem + var(--safe-top)) 1rem 0.5rem;
  height: calc(var(--topbar-h) + var(--safe-top));
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.topbar-left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 0.4rem; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  background: var(--accent); color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.meta .name {
  font-weight: 600; font-size: 0.95rem; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 50vw;
}
.meta .role { font-size: 0.72rem; color: var(--text-tertiary); text-transform: capitalize; }

.balance {
  font-weight: 600; font-size: 0.82rem; color: #14a83b;
  padding: 4px 10px;
  background: rgba(52, 199, 89, 0.12);
  border: 1px solid rgba(52, 199, 89, 0.32);
  border-radius: 999px;
}

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem; color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.96); }

/* ===== drawer =========================================== */
.drawer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.18);
  backdrop-filter: blur(4px);
  display: flex; justify-content: flex-end;
  animation: fade-in 0.2s ease;
}
.drawer-inner {
  background: var(--bg-secondary);
  width: min(80%, 300px);
  padding: calc(1.25rem + var(--safe-top)) 0.75rem calc(1rem + var(--safe-bottom));
  border-left: 1px solid var(--separator);
  display: flex; flex-direction: column; gap: 0.25rem;
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.22s cubic-bezier(0.2, 0.9, 0.4, 1);
  overflow-y: auto;
}
.drawer a {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  color: var(--text-primary);
  font-weight: 500;
  transition: background 0.1s;
}
.drawer a:hover { background: var(--bg-tertiary); }

@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ===== main view ======================================== */
.view {
  padding: 1rem 1rem calc(var(--tabbar-h) + var(--safe-bottom) + 1rem);
  max-width: 820px;
  margin: 0 auto;
  animation: fade-in 0.18s ease;
}

/* ===== cards ============================================ */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
}
.card.interactive { cursor: pointer; }
.card.interactive:hover { background: var(--bg-tertiary); border-color: var(--border-light); }
.card.interactive:active { transform: scale(0.99); }
.card h3 { margin-bottom: 0.5rem; color: var(--text-primary); }

/* ===== buttons ========================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  min-height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: 600; font-size: 0.92rem;
  transition: background 0.12s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-pressed); }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn.secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
.btn.secondary:hover { background: var(--bg-tertiary); }

.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: rgba(10, 132, 255, 0.1); }

.btn.danger  { background: var(--danger); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.warning { background: var(--warning); color: #fff; }

.btn.block { width: 100%; }
.btn.sm { padding: 0.4rem 0.85rem; min-height: 34px; font-size: 0.8rem; border-radius: 10px; }
.btn.lg { padding: 0.85rem 1.4rem; min-height: 52px; font-size: 1rem; }

.link-btn {
  background: none; border: none; padding: 0;
  color: var(--accent); font-weight: 600; cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

/* ===== hero ============================================= */
.hero-btn {
  width: 100%;
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-pressed));
  border: none; border-radius: var(--radius-lg);
  color: #fff;
  font-weight: 700; font-size: 1rem;
  text-align: left;
  box-shadow: var(--shadow-md);
  margin-bottom: 0.75rem;
  transition: filter 0.15s, transform 0.06s;
}
.hero-btn:hover { filter: brightness(1.04); }
.hero-btn:active { transform: scale(0.99); }
.hero-btn .ico {
  width: 44px; height: 44px;
  background: rgba(255,255,255,0.18);
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.hero-btn .txt { flex: 1; }
.hero-btn .txt small { display: block; color: rgba(255,255,255,0.85); font-size: 0.75rem; }
.hero-btn::after { content: '→'; opacity: 0.85; font-size: 1.2rem; transition: transform 0.15s; }
.hero-btn:hover::after { transform: translateX(3px); }
.hero-btn.green { background: linear-gradient(135deg, var(--success), #14a83b); }
.hero-btn.amber { background: linear-gradient(135deg, var(--warning), #e08200); }

/* ===== tabs ============================================= */
.tabs {
  display: flex; gap: 0.4rem;
  margin-bottom: 0.75rem;
  background: var(--bg-quaternary);
  padding: 4px;
  border-radius: 12px;
}
.tabs button {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 9px;
  color: var(--text-secondary);
  font-weight: 600; font-size: 0.85rem;
}
.tabs button.active {
  background: #fff;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ===== seats ============================================ */
.list { display: flex; flex-direction: column; gap: 0.7rem; }
.grid-seats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.6rem;
  margin: 0.75rem 0;
}
.seat {
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-light);
  border-radius: 12px;
  padding: 0.75rem 0.25rem;
  text-align: center;
  cursor: pointer; transition: all 0.1s;
  color: var(--text-primary);
}
.seat .num { font-size: 1.15rem; font-weight: 700; }
.seat .price { font-size: 0.7rem; color: var(--text-tertiary); }
.seat.free { border-color: rgba(52,199,89,0.55); background: rgba(52,199,89,0.10); }
.seat.free:hover { background: rgba(52,199,89,0.18); }
.seat.booked { border-color: rgba(255,159,10,0.55); background: rgba(255,159,10,0.10); cursor: not-allowed; }
.seat.busy { border-color: rgba(255,59,48,0.55); background: rgba(255,59,48,0.10); cursor: not-allowed; }
.seat.selected { border-color: var(--accent); background: rgba(10,132,255,0.12); }

/* ===== chat ============================================= */
.chat-box {
  display: flex; flex-direction: column;
  height: 65vh;
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.chat-msgs { flex: 1; overflow-y: auto; padding: 0.85rem; display: flex; flex-direction: column; gap: 0.5rem; }
.msg {
  max-width: 80%;
  padding: 0.55rem 0.85rem;
  border-radius: 16px;
  background: var(--bg-quaternary);
  color: var(--text-primary);
  border: 1px solid transparent;
  font-size: 0.9rem;
  word-break: break-word;
}
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; }
.msg .time { font-size: 0.65rem; color: var(--text-tertiary); margin-top: 0.25rem; }
.msg.mine .time { color: rgba(255,255,255,0.78); }
.chat-input {
  display: flex; gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--separator);
  background: var(--bg-secondary);
}

/* ===== chips ============================================ */
.chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.72rem; font-weight: 600;
  background: var(--bg-quaternary);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  color: var(--text-primary);
}
.chip.success { background: rgba(52,199,89,0.16); color: #1a8a3e; border-color: rgba(52,199,89,0.4); }
.chip.warn    { background: rgba(255,159,10,0.16); color: #b66600; border-color: rgba(255,159,10,0.4); }
.chip.danger  { background: rgba(255,59,48,0.16); color: #b81c14; border-color: rgba(255,59,48,0.4); }
.chip.info    { background: rgba(10,132,255,0.14); color: #074aa4; border-color: rgba(10,132,255,0.32); }

/* ===== stats ============================================ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat {
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  padding: 0.85rem;
  box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-tertiary); }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; color: var(--text-primary); }

/* ===== toast ============================================ */
.toast {
  position: fixed; left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 1rem);
  transform: translateX(-50%) translateY(0.5rem);
  background: rgba(28,28,30,0.95);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  z-index: 120;
  font-size: 0.85rem; font-weight: 500;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.toast:not([hidden]) { opacity: 1; transform: translateX(-50%) translateY(0); }
/* Явный цвет текста: иначе общий класс .error (ниже) перекрывает color и даёт красный на красном */
.toast.error {
  background: var(--danger);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}
.toast.success {
  background: var(--success);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

/* ===== modal ============================================ */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  animation: fade-in 0.15s ease;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(8px); }
.modal-box {
  position: relative;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--separator);
  border-radius: var(--radius-xl);
  padding: 1.2rem;
  max-width: 520px; width: 92%;
  max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ===== misc ============================================= */
.loader {
  display: inline-block; width: 22px; height: 22px;
  border: 3px solid var(--bg-quaternary);
  border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint { color: var(--text-tertiary); font-size: 0.74rem; margin-top: 0.25rem; }
.switch { display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none; margin: 0.4rem 0; }
/* Не трогаем .toast.error — у тоста отдельные правила выше */
.error:not(.toast) {
  color: var(--danger);
  font-size: 0.78rem;
  margin-top: 0.25rem;
}

.empty { padding: 3rem 1rem; text-align: center; color: var(--text-tertiary); }
.empty .em { font-size: 3rem; margin-bottom: 0.4rem; opacity: 0.7; }

/* autocomplete */
.datalist-wrap { position: relative; }
.suggest {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  margin-top: 4px;
  max-height: 220px; overflow-y: auto;
  z-index: 15;
  box-shadow: var(--shadow-md);
}
.suggest div {
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--separator);
  color: var(--text-primary);
}
.suggest div:last-child { border-bottom: none; }
.suggest div:hover { background: var(--bg-tertiary); }

/* ===== bottom tabbar ==================================== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 25;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--separator);
  display: flex; justify-content: space-around; align-items: stretch;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.15rem;
  color: var(--text-tertiary); font-size: 0.68rem; font-weight: 500;
  transition: color 0.1s;
  text-decoration: none;
}
.tabbar a .ic { font-size: 1.3rem; }
.tabbar a.active { color: var(--accent); }

/* ===== boot screen ====================================== */
.boot-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
}
.boot-screen[hidden] { display: none !important; }
.boot-text { color: var(--text-tertiary); font-size: 0.88rem; }
.boot-loader {
  width: 36px; height: 36px;
  border: 3px solid var(--bg-quaternary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ===== utility helpers ================================== */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4 { gap: 0.25rem; } .gap-6 { gap: 0.375rem; } .gap-8 { gap: 0.5rem; } .gap-10 { gap: 0.625rem; } .gap-12 { gap: 0.75rem; }
.mt-4 { margin-top: 0.25rem; } .mt-8 { margin-top: 0.5rem; } .mt-12 { margin-top: 0.75rem; } .mt-16 { margin-top: 1rem; }
.mb-4 { margin-bottom: 0.25rem; } .mb-8 { margin-bottom: 0.5rem; } .mb-12 { margin-bottom: 0.75rem; } .mb-16 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.grow { flex-grow: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 1.1rem 0 0.6rem;
}
.section-head h3 { margin: 0; }

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

/* OpenStreetMap (Leaflet) container */
.leaflet-map {
  width: 100%;
  height: 320px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--separator);
  overflow: hidden;
}

/* ===== responsive ======================================= */
@media (max-width: 640px) {
  .grid-seats { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
