:root {
  --bg: #14100d;
  --paper: #faf6f0;
  --ink: #2b2118;
  --muted: #8a7a68;
  --line: #e5dbcc;
  --accent: #b08454;
  --accent-dark: #8d6839;
  --danger: #b3453a;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(43, 33, 24, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

body.dark { background: var(--bg); color: var(--paper); }

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0 0 12px; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
p { line-height: 1.55; margin: 0 0 12px; }
a { color: var(--accent-dark); }

.wrap { max-width: 860px; margin: 0 auto; padding: 24px 18px 64px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }

input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px; /* 16px не даёт iOS зумить форму */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f2ece2; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 7px 12px; font-size: 13px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- камера */

body.camera {
  background: #000;
  color: #fff;
  overflow: hidden;
  height: 100%;
  position: fixed;
  inset: 0;
  width: 100%;
}

#stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#view { max-width: 100%; max-height: 100%; display: block; }
#video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease-out;
}
#flash.on { opacity: 0.92; transition: none; }

.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: linear-gradient(rgba(0,0,0,0.55), rgba(0,0,0,0));
  font-size: 13px;
  z-index: 5;
}

.controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 20px 24px calc(env(safe-area-inset-bottom) + 26px);
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.6));
  z-index: 5;
}

#shutter {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.22);
  cursor: pointer;
  transition: transform 0.1s;
}
#shutter:active { transform: scale(0.9); }
#shutter:disabled { opacity: 0.4; }

.icon-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}

.pill {
  background: rgba(0,0,0,0.45);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 9, 7, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  z-index: 20;
}
.overlay h1 { color: #fff; }
.overlay p { color: #d8cbba; max-width: 340px; }

/* ------------------------------------------------------------ галерея */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 6px;
}
.grid img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  background: #e8e0d4;
  cursor: pointer;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 82vh; border-radius: 8px; }
.lightbox .bar {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  display: flex; gap: 10px;
}
.lightbox .close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 14px); right: 16px;
  background: rgba(255,255,255,0.16);
  color: #fff; border: 0; border-radius: 50%;
  width: 40px; height: 40px; font-size: 20px; cursor: pointer;
}

/* ------------------------------------------------------------- админка */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.qr-box { text-align: center; padding: 18px; }
.qr-box img { width: 100%; max-width: 280px; border-radius: 10px; }

.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 100;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}
