/*
 * Sonnix Mini-App — стиль галереи.
 * Палитра: тёплый кремовый фон + янтарный акцент. Светлая тема первична.
 * Тёмная тема — для системного prefers-color-scheme: dark.
 */

:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --surface-2: #F2EBDE;
  --border: #EDE5D8;
  --text: #2A2118;
  --text-soft: #6B5F50;
  --text-muted: #9C8E7C;
  --accent: #D4945C;          /* Sonnix sun */
  --accent-soft: #FBEFE0;
  --warn: #C99A2A;
  --danger: #C04B4B;
  --shadow: 0 2px 12px rgba(42, 33, 24, 0.06);
  --shadow-hover: 0 6px 24px rgba(42, 33, 24, 0.10);
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1B1712;
    --surface: #25201A;
    --surface-2: #2E2820;
    --border: #3B342A;
    --text: #F4EEE4;
    --text-soft: #C2B6A4;
    --text-muted: #8A7E6B;
    --accent: #E0A958;
    --accent-soft: #3A2E1D;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  padding-top: calc(14px + env(safe-area-inset-top, 0));
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.app-header.scrolled { border-bottom-color: var(--border); }

.app-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-align: center;
  color: var(--text);
}

.header-btn {
  background: transparent;
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.header-btn:hover,
.header-btn:active { background: var(--surface-2); }

.header-btn[hidden] { display: none; }

/* ── Main ────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  padding: 8px 16px 100px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-soft);
  margin: 4px 0 14px;
  padding: 0 4px;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 0 12px;
  margin: 0 -4px 8px;
}

.filters::-webkit-scrollbar { display: none; }

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-soft);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

/* ── Grid ────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
}

.tile {
  position: relative;
  aspect-ratio: 4 / 5;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

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

.tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}

.tile-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 10px 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  color: #fff;
}

.tile-overlay-title {
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-overlay-date {
  font-size: 11px;
  opacity: 0.9;
}

.tile-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.tile-fav {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 16px;
  background: rgba(255,255,255,0.85);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

/* ── Skeleton ────────────────────────────────────────────────────── */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  padding: 8px 0 0;
}

.skeleton-tile {
  aspect-ratio: 4 / 5;
  background: var(--surface);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}

.skeleton-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--surface-2), transparent);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ── Empty / Error states ────────────────────────────────────────── */
.placeholder {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-soft);
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.7;
}

.placeholder-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}

.placeholder-text {
  font-size: 14px;
  margin: 0 0 20px;
}

/* ── Detail view (карточка работы) ───────────────────────────────── */
.detail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-img-wrap {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  box-shadow: var(--shadow);
}

.detail-img {
  width: 100%;
  height: auto;
  display: block;
}

.detail-meta {
  padding: 0 4px;
}

.detail-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.detail-date {
  font-size: 13px;
  color: var(--text-soft);
}

.extend-block {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.extend-info {
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.extend-info-icon { font-size: 14px; }

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

.action-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
}

.action-btn:hover { background: var(--surface-2); }
.action-btn:active { transform: scale(0.98); }

.action-btn-icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
}

.action-btn-label { flex: 1; }
.action-btn-aside { font-size: 13px; color: var(--text-soft); }

.action-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  justify-content: center;
  font-weight: 600;
}

.action-btn.primary:hover { background: color-mix(in srgb, var(--accent) 90%, black); }

.action-btn.danger { color: var(--danger); }

/* ── FAB (плавающая кнопка «Создать новую») ──────────────────────── */
.fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 14px 24px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(212, 148, 92, 0.4);
  z-index: 5;
  transition: transform 0.15s;
}

.fab:active { transform: translateX(-50%) scale(0.96); }

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-hover);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  white-space: nowrap;
}

.toast[data-show] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Modal ───────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  animation: fadeIn 0.15s;
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-hover);
  animation: slideUp 0.2s ease-out;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--text);
}

.modal-text {
  font-size: 14px;
  color: var(--text-soft);
  margin: 0 0 18px;
}

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

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
