/* ==========================================================================
   «Ярдик Фото» — стили. Mobile-first, светлая/тёмная тема, без внешних ресурсов.
   ========================================================================== */

:root {
  color-scheme: light dark;

  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-soft: #f1f2f9;
  --header-bg: rgba(255, 255, 255, 0.86);
  --overlay: rgba(18, 21, 32, 0.55);

  --text: #171a23;
  --text-soft: #3d4453;
  --muted: #6b7280;
  --border: #e6e8f2;

  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --warn: #f59e0b;
  --ok: #16a34a;

  --radius: 20px;
  --radius-sm: 14px;
  --radius-xs: 10px;

  --shadow: 0 12px 32px rgba(23, 26, 40, 0.08);
  --shadow-sm: 0 4px 16px rgba(23, 26, 40, 0.06);

  --tap: 52px;
  --speed: 0.18s;
  --content: 640px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --bg-elev: #171a22;
    --bg-soft: #1e222c;
    --header-bg: rgba(23, 26, 34, 0.88);
    --overlay: rgba(0, 0, 0, 0.68);

    --text: #f2f4f8;
    --text-soft: #c9cfdb;
    --muted: #98a0b3;
    --border: #282d3a;

    --danger: #f87171;
    --danger-soft: #2a1b1e;
    --warn: #fbbf24;
    --ok: #4ade80;

    --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.32);
  }
}

/* ---------- база ---------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body.is-locked { overflow: hidden; }

img { display: block; max-width: 100%; }

[hidden] { display: none !important; }

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

/* ---------- хедер ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: env(safe-area-inset-top);
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--content);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--bg-soft);
}

.brand-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.tabs {
  margin-left: auto;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-soft);
  border-radius: 999px;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--speed) ease, color var(--speed) ease;
}

.tab.is-active {
  background: var(--grad);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.header-inner > .btn-ghost { margin-left: auto; }
.tabs + .btn-ghost { margin-left: 8px; }

/* ---------- каркас ---------- */

.app-main {
  max-width: var(--content);
  margin: 0 auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

.view { animation: fade-up 0.22s ease both; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---------- кнопки ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  min-height: var(--tap);
  padding: 12px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--speed) ease, filter var(--speed) ease,
              background var(--speed) ease, box-shadow var(--speed) ease,
              opacity var(--speed) ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.985); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.32);
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-secondary {
  background: var(--bg-elev);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  min-height: 40px;
  padding: 8px 12px;
}

.btn-lg { min-height: var(--tap); font-size: 16.5px; }

.btn-sm {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 12px;
}

.btn-tiny {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 13px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-block { width: 100%; }

/* ---------- поля ---------- */

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.req { color: var(--accent); }

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  transition: border-color var(--speed) ease, background var(--speed) ease,
              box-shadow var(--speed) ease;
  -webkit-appearance: none;
  appearance: none;
}

.input::placeholder { color: var(--muted); opacity: 0.75; }

.input:focus {
  outline: none;
  background: var(--bg-elev);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.4;
}

select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

.field.is-invalid .input {
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: none;
}

.form-error {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--danger);
}

.hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* ---------- вход ---------- */

.login-wrap {
  padding-top: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-logo {
  width: 104px;
  height: 104px;
  border-radius: 28px;
  object-fit: cover;
  background: var(--bg-soft);
  box-shadow: var(--shadow);
}

.login-title {
  margin: 16px 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14.5px;
  text-align: center;
}

.login-card { width: 100%; }

.login-hint {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------- приветствие ---------- */

.hero {
  background: var(--grad);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 30px rgba(99, 102, 241, 0.28);
}

.hero-avatar {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  border-radius: 20px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.25);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.hero-text {
  margin: 0;
  font-size: 15.5px;
  font-weight: 550;
  line-height: 1.35;
}

/* ---------- миниатюры выбранных фото ---------- */

.thumbs {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.thumb {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--bg-soft);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  animation: fade-up 0.2s ease both;
}

.thumb.is-error { border-color: var(--danger); }

.thumb-media {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--bg-elev);
}

.thumb-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.thumb-name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumb-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}

.thumb-status {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.thumb-status.is-done { color: var(--ok); font-size: 15px; }
.thumb-status.is-error { color: var(--danger); font-size: 15px; }

.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-elev);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* ---------- прогресс ---------- */

.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.bar-sm { height: 5px; background: var(--bg-elev); }

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--grad);
  transition: width var(--speed) ease;
}

.bar-fill.is-warn { background: linear-gradient(135deg, #f59e0b, #fb923c); }
.bar-fill.is-danger { background: linear-gradient(135deg, #ef4444, #f87171); }

/* ---------- «отправлено» ---------- */

.done {
  text-align: center;
  padding: 32px 20px;
}

.done-emoji { font-size: 52px; line-height: 1; }

.done-title {
  margin: 12px 0 6px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.done-sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14.5px;
}

/* ---------- хранилище ---------- */

.storage { padding: 14px 16px; }

.storage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 14px;
}

.storage-label { font-weight: 650; }
.storage-text { color: var(--muted); font-size: 13px; }

/* ---------- фильтры ---------- */

.filters { padding: 14px; }

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

.filters-grid .field { gap: 4px; }

.filters-grid .input { min-height: 44px; padding: 9px 12px; font-size: 15px; }

.filters-grid .field:nth-child(6),
.filters-grid .reset-btn { grid-column: 1 / -1; }

.reset-btn { min-height: 44px; font-size: 15px; }

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

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 2px 12px;
}

.gallery-count {
  font-size: 13.5px;
  color: var(--muted);
  font-weight: 600;
}

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

.tile {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  padding: 0;
  overflow: hidden;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--speed) ease, box-shadow var(--speed) ease;
  display: flex;
  flex-direction: column;
}

.tile:active { transform: scale(0.985); }
.tile:hover { box-shadow: var(--shadow); }

.tile-media {
  display: block;
  aspect-ratio: 1 / 1;
  background: var(--bg-soft);
  overflow: hidden;
}

.tile-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px 11px;
}

.tile-name {
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-sub,
.tile-date {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty {
  margin: 28px 0;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

.load-more-wrap {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

/* ---------- модалка ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in 0.18s ease both;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: var(--content);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: fade-up 0.2s ease both;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 22, 32, 0.55);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

.modal-media {
  background: var(--bg-soft);
  max-height: 62vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.modal-media img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
}

.modal-body { padding: 16px; }

.modal-name {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 680;
  word-break: break-word;
}

.meta-list {
  margin: 0 0 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 14px;
}

.meta-list dt { color: var(--muted); }

.meta-list dd {
  margin: 0;
  font-weight: 550;
  word-break: break-word;
}

.modal-comment {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

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

/* ---------- баннер установки и тост ---------- */

.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 70;
  max-width: calc(var(--content) - 24px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: fade-up 0.25s ease both;
}

.install-text {
  flex: 1 1 auto;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
}

.install-close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 80;
  transform: translate(-50%, 10px);
  max-width: min(92vw, 480px);
  padding: 11px 18px;
  background: #1f2230;
  color: #fff;
  font-size: 14px;
  font-weight: 550;
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  text-align: center;
}

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

/* ---------- десктоп ---------- */

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .thumbs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters-grid .field:nth-child(6) { grid-column: span 2; }
  .filters-grid .reset-btn { grid-column: 1 / -1; }
  .modal-actions { flex-direction: row; }
  .modal-actions .btn { flex: 1 1 0; }
}

@media (min-width: 900px) {
  .app-main { padding-top: 24px; }
  .grid { gap: 14px; }
}

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