/* ═══════════ Тема ═══════════ */
:root {
  --bg: #f4f1ea;
  --surface: #fbf9f4;
  --surface-2: #efebe2;
  --border: #e3ddd0;
  --text: #29271f;
  --muted: #78726a;
  --accent: #b4532a;
  --accent-hover: #9a4522;
  --accent-soft: #f3e3d8;
  --ok: #3f7a52;
  --ok-soft: #e1eee3;
  --warn: #a8741a;
  --warn-soft: #f5ead2;
  --danger: #b23a3a;
  --danger-soft: #f6dfdc;
  --info: #3f6390;
  --info-soft: #e0e8f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(41, 39, 31, .04), 0 4px 16px rgba(41, 39, 31, .05);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1e1b; --surface: #282723; --surface-2: #302e2a; --border: #3b3934;
    --text: #ece8df; --muted: #a29d93; --accent: #d9774f; --accent-hover: #e48b66; --accent-soft: #3d2a22;
    --ok: #7bbf8e; --ok-soft: #22342a; --warn: #d9a84d; --warn-soft: #3a3020;
    --danger: #e37b7b; --danger-soft: #3d2424; --info: #8cb0dd; --info-soft: #222f3d;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { font-family: var(--serif); font-weight: 500; letter-spacing: -.01em; margin: 0 0 .5em; }
h1 { font-size: 30px; } h2 { font-size: 22px; } h3 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

/* ═══════════ Кнопки и формы ═══════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 500 14px var(--sans); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin: 0 0 6px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 14px var(--sans); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; font-weight: 400; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }

/* ═══════════ Карточки, таблицы, бейджи ═══════════ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat .value { font-family: var(--serif); font-size: 30px; line-height: 1.2; }
.stat .label { color: var(--muted); font-size: 13px; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-new { background: var(--info-soft); color: var(--info); }
.badge-awaiting_payment { background: var(--surface-2); color: var(--muted); }
.badge-payment_check { background: var(--warn-soft); color: var(--warn); }
.badge-paid { background: var(--accent-soft); color: var(--accent); }
.badge-in_progress { background: var(--warn-soft); color: var(--warn); }
.badge-done { background: var(--ok-soft); color: var(--ok); }
.badge-cancelled { background: var(--danger-soft); color: var(--danger); }
.badge-on { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--surface-2); color: var(--muted); }

.flash { padding: 11px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { padding: 6px 12px; border-radius: 99px; font-size: 13px; color: var(--muted); border: 1px solid transparent; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); box-shadow: var(--shadow); }
.tab .count { color: var(--muted); margin-left: 4px; }

/* ═══════════ Админка: каркас ═══════════ */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface-2); border-right: 1px solid var(--border); padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { font-family: var(--serif); font-size: 21px; padding: 0 10px 18px; display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 14px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--text); font-size: 14px; margin-bottom: 2px; }
.nav a:hover { background: var(--border); }
.nav a.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 500; }
.nav .ico { width: 18px; text-align: center; opacity: .8; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 6px; }
.sidebar .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); font-size: 13px; }
.main { padding: 32px 40px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.menu-toggle { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .main { padding: 20px 16px 50px; }
  .menu-toggle { display: inline-flex; }
}

.bars { display: flex; align-items: flex-end; gap: 10px; height: 120px; padding-top: 10px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar .fill { width: 100%; max-width: 42px; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 3px; opacity: .85; }
.bar .lbl { font-size: 11px; color: var(--muted); }
.bar .num { font-size: 12px; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 20px; }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.seg label { margin: 0; padding: 4px 9px; font-size: 12px; cursor: pointer; color: var(--muted); border-right: 1px solid var(--border); }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg input:checked + span { color: var(--text); font-weight: 600; }
.seg label:has(input:checked) { background: var(--surface-2); }
.seg label.grant:has(input:checked) { background: var(--ok-soft); }
.seg label.revoke:has(input:checked) { background: var(--danger-soft); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }

/* ═══════════ Магазин / Mini App ═══════════ */
.shop { max-width: 980px; margin: 0 auto; padding: 0 20px 80px; }
.shop-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 0; }
.hero { padding: 56px 0 40px; text-align: center; }
.hero h1 { font-size: clamp(32px, 6vw, 52px); line-height: 1.1; margin-bottom: 14px; }
.hero p { color: var(--muted); font-size: 17px; max-width: 560px; margin: 0 auto; }
.section-title { font-family: var(--serif); font-size: 22px; margin: 36px 0 14px; }
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.product { display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, transform .15s; }
.product:hover { border-color: var(--accent); transform: translateY(-2px); }
.product h3 { margin: 0; font-size: 19px; }
.product .desc { color: var(--muted); font-size: 14px; flex: 1; white-space: pre-line; }
.price { font-family: var(--serif); font-size: 24px; }
.price .stars { font-family: var(--sans); font-size: 13px; color: var(--muted); margin-left: 8px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 40px 0 0; }

.modal-bg { position: fixed; inset: 0; background: rgba(30, 28, 24, .45); display: none; align-items: flex-end; justify-content: center; z-index: 50; padding: 0; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0; padding: 24px 22px 28px; max-height: 90vh; overflow-y: auto; animation: up .2s ease-out; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.methods { display: grid; gap: 8px; margin-top: 10px; }
.method { text-align: left; justify-content: flex-start; padding: 13px 16px; font-size: 15px; }
.method:hover { border-color: var(--accent); }
.instructions { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 14px; font-size: 14px; margin: 12px 0; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
