/* ==== common.css ====
   Общий визуальный слой мини-приложения и админки: переменные, звёздный фон, стекло, кнопки,
   поля, модалки, тосты, каркас (сайдбар → иконки → нижняя панель). Брейкпоинты: 1024px и 768px.
   Используется в: app.html, admin.html, znakomstvo.html */

/* ---- CSS_VARS ---- */
:root {
  --bg-0: #07061a;
  --bg-1: #0e0b2e;
  --bg-2: #1a1446;
  --glass: rgba(255, 255, 255, 0.055);
  --glass-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f3eefe;
  --muted: #a69fc7;
  --gold: #e8c77a;
  --gold-2: #f6e2a8;
  --violet: #9d7bff;
  --rose: #ff8fb1;
  --green: #6fe3b4;
  --red: #ff7a8a;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 10px 40px rgba(5, 3, 20, 0.55);
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Cormorant Garamond", "Playfair Display", Georgia, serif;
  --sidebar-w: 236px;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 700px at 80% -10%, #2b1d6e 0%, transparent 60%),
              radial-gradient(900px 600px at -10% 110%, #3a1450 0%, transparent 55%),
              linear-gradient(180deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---- STARS_BG: мерцающее небо (чистый CSS, без нагрузки на JS) ---- */
.stars-bg, .stars-bg::before, .stars-bg::after {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-repeat: repeat;
}
.stars-bg {
  background-image:
    radial-gradient(1px 1px at 20px 30px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 120px 80px, #cfc6ff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 200px 160px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 260px 40px, #ffe9b3 50%, transparent 51%),
    radial-gradient(1px 1px at 330px 220px, #fff 50%, transparent 51%);
  background-size: 360px 260px;
  opacity: .55;
}
.stars-bg::before {
  content: "";
  background-image:
    radial-gradient(1.5px 1.5px at 60px 120px, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 170px 20px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 300px 300px, #f6e2a8 50%, transparent 51%);
  background-size: 420px 380px;
  animation: stars-twinkle 6s ease-in-out infinite alternate;
}
.stars-bg::after {
  content: "";
  background-image: radial-gradient(1px 1px at 90px 200px, #fff 50%, transparent 51%),
                    radial-gradient(1px 1px at 240px 110px, #b9a8ff 50%, transparent 51%);
  background-size: 300px 300px;
  animation: stars-twinkle 9s ease-in-out infinite alternate-reverse;
}
@keyframes stars-twinkle { from { opacity: .15; } to { opacity: .8; } }

/* ---- TYPO ---- */
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: .2px; margin: 0 0 8px; overflow-wrap: anywhere; font-variant-numeric: lining-nums; }
h1 { font-size: 34px; line-height: 1.1; }
h2 { font-size: 26px; }
h3 { font-size: 20px; }
p { margin: 0 0 10px; line-height: 1.55; }
.muted { color: var(--muted); }
.gold { color: var(--gold); }
.small { font-size: 13px; }
.gold-text {
  background: linear-gradient(90deg, var(--gold), var(--gold-2), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---- GLASS_CARD ---- */
.card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  animation: card-rise .45s ease both;
}
.card + .card { margin-top: 14px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-title h3 { margin: 0; }
@keyframes card-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-2 > .card + .card, .grid-3 > .card + .card { margin-top: 0; }
.grid-2 + .card, .grid-3 + .card, .card + .grid-2, .card + .grid-3 { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.hidden { display: none !important; }

/* ---- BUTTONS (минимум 44px) ---- */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--glass-strong); color: var(--text); font: 600 15px var(--font);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  transition: transform .15s ease, background .2s ease, box-shadow .2s ease, opacity .2s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-gold {
  background: linear-gradient(135deg, #f3d48d, #c9963f); color: #2a1a00; border: none;
  box-shadow: 0 6px 24px rgba(232, 199, 122, .35);
}
.btn-gold:hover { background: linear-gradient(135deg, #f8dfa3, #d6a54d); }
.btn-violet { background: linear-gradient(135deg, #a98bff, #6b4fe0); border: none; box-shadow: 0 6px 24px rgba(157, 123, 255, .35); }
.btn-danger { background: rgba(255, 122, 138, .14); border-color: rgba(255, 122, 138, .4); color: #ffc3cb; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 13px; }
.icon-btn { width: 44px; min-width: 44px; height: 44px; padding: 0; border-radius: 12px; }

/* ---- FORMS ---- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(10, 8, 30, .55); color: var(--text);
  font: 15px var(--font); outline: none; transition: border-color .2s, box-shadow .2s;
  color-scheme: dark;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232, 199, 122, .18); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; user-select: none; }
.check input { width: 22px; height: 22px; accent-color: var(--gold); }

/* Переключатель */
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: 30px; background: rgba(255, 255, 255, .15); transition: .25s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .25s; }
.switch input:checked + .track { background: linear-gradient(135deg, #f3d48d, #c9963f); }
.switch input:checked + .track::after { transform: translateX(22px); }

/* Автодополнение */
.autocomplete { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  background: #15113a; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.ac-item { padding: 12px 14px; min-height: 44px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: rgba(232, 199, 122, .12); }

/* ---- CHIPS / BADGES ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line); font-size: 13px; cursor: pointer;
}
.chip.active { background: rgba(232, 199, 122, .18); border-color: rgba(232, 199, 122, .55); color: var(--gold-2); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips-scroll::-webkit-scrollbar { display: none; }
.badge { display: inline-block; white-space: normal; padding: 3px 9px; border-radius: 999px; font-size: 12px; background: rgba(157, 123, 255, .2); color: #d7caff; }
.badge-gold { background: rgba(232, 199, 122, .18); color: var(--gold-2); }
.badge-red { background: rgba(255, 122, 138, .18); color: #ffc3cb; }
.badge-green { background: rgba(111, 227, 180, .16); color: #b9f5dc; }

/* ---- LAYOUT: компьютер — боковое меню с текстом ---- */
.shell { position: relative; z-index: 1; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 22px 14px; border-right: 1px solid var(--line);
  background: rgba(8, 6, 26, .55); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-family: var(--font-display); font-size: 22px; }
.brand-logo { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 20px;
  background: radial-gradient(circle at 30% 30%, #f6e2a8, #b9822e); color: #2a1a00; box-shadow: 0 0 24px rgba(232,199,122,.45); }
.nav-item {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 14px; border-radius: 14px;
  color: var(--muted); cursor: pointer; border: 1px solid transparent; font-weight: 600; text-decoration: none;
  transition: background .2s, color .2s;
}
.nav-item .nav-ico { font-size: 20px; width: 24px; text-align: center; }
.nav-item:hover { background: var(--glass); color: var(--text); }
.nav-item.active { background: rgba(232, 199, 122, .12); color: var(--gold-2); border-color: rgba(232, 199, 122, .3); }
.sidebar-foot { margin-top: auto; }
.main { padding: 26px 30px 40px; max-width: 1180px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.tabbar { display: none; }

/* ---- MODAL / TOAST / LOADER ---- */
.modal-back {
  position: fixed; inset: 0; z-index: 100; background: rgba(3, 2, 12, .7); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade-in .2s ease;
}
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; background: linear-gradient(180deg, #1a1446, #110d33);
  border: 1px solid var(--line); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); animation: modal-pop .25s ease;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { opacity: 0; transform: scale(.95) translateY(10px); } to { opacity: 1; transform: none; } }
.toast-wrap { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 13px 16px; border-radius: 14px; background: #221a55; border: 1px solid var(--line); box-shadow: var(--shadow); animation: modal-pop .2s ease; font-size: 14px; }
.toast.ok { border-color: rgba(111, 227, 180, .5); }
.toast.err { border-color: rgba(255, 122, 138, .6); }
.loader { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--gold); animation: spin .8s linear infinite; }
.loader-block { display: flex; justify-content: center; padding: 30px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, rgba(255,255,255,.04), rgba(255,255,255,.1), rgba(255,255,255,.04)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 12px; min-height: 18px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- TABLE → карточки на телефоне ---- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: rgba(255,255,255,.03); }

/* ---- PAGER ---- */
.pager { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; }
.pager .pager-info { color: var(--muted); font-size: 14px; min-width: 70px; text-align: center; }

.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .empty-ico { font-size: 40px; display: block; margin-bottom: 8px; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.pre { white-space: pre-line; line-height: 1.6; }

/* ===== ПЛАНШЕТ (768–1024px): меню сжимается до иконок ===== */
@media (max-width: 1024px) {
  :root { --sidebar-w: 78px; }
  .brand span, .nav-item .nav-label, .sidebar-foot .nav-label { display: none; }
  .brand { justify-content: center; padding: 4px 0 18px; }
  .nav-item { justify-content: center; padding: 0; }
  .main { padding: 22px 20px 36px; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 30px; }
}

/* ===== ТЕЛЕФОН (<768px): нижняя панель вкладок, таблицы → карточки ===== */
@media (max-width: 768px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main { padding: 16px 14px calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(10, 8, 30, .85); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--line);
  }
  .tab-item {
    flex: 1; min-width: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; text-decoration: none;
  }
  .tab-item .tab-ico { font-size: 22px; transition: transform .2s; }
  .tab-item.active { color: var(--gold-2); }
  .tab-item.active .tab-ico { transform: translateY(-2px) scale(1.08); filter: drop-shadow(0 0 8px rgba(232,199,122,.6)); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 27px; }
  h2 { font-size: 22px; }
  .card { padding: 15px; border-radius: 18px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .modal { padding: 18px; border-radius: 20px; }
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-bottom-left-radius: 0; border-bottom-right-radius: 0; max-height: 92vh; }
  .modal-actions .btn { flex: 1; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; padding: 6px 4px; background: var(--glass); }
  .table td { border: none; padding: 7px 10px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  .toast-wrap { bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); }
  .btn { min-height: 46px; }
}
