:root {
  --pad: 14px;
  --gap: 10px;
  --br: 12px;
  --line: #e7e7e7;
  --bg: #f6f7f8;
  --fg: #222;
  --muted: #666;
  --card: #fff;
  --icon: #f1f3f5;
  --pill-bg: #edf2ff;
  --pill-fg: #2f5dfc;
  --focus: #2f5dfc40;
  --primary: #1f6feb;
  --danger-bg: #ffe3e3;
  --danger-fg: #c92a2a;
  --ok-bg: #e6fcf5;
  --ok-fg: #087f5b;
  --warn: #f59f00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #f2f3f5;
    --muted: #b3b7c0;
    --card: #161a22;
    --line: #232838;
    --icon: #1b2130;
    --pill-bg: #182446;
    --pill-fg: #8fb1ff;
    --focus: #8fb1ff45;
    --danger-bg: #3d1f1f;
    --danger-fg: #ff8787;
    --ok-bg: #0d3d32;
    --ok-fg: #63e6be;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

[hidden] { display: none !important; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px var(--pad);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.app-header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 800;
  white-space: nowrap;
}

.app-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.app-nav a {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 13px;
  background: var(--icon);
}

.app-nav a.active {
  background: var(--pill-bg);
  color: var(--pill-fg);
}

.sp { flex: 1; min-width: 12px; }

/* Pills & badges */
.pill {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-fg);
  font-weight: 800;
  font-size: 12px;
  display: inline-block;
}

.pill.danger, .danger-pill { background: var(--danger-bg); color: var(--danger-fg); }
.pill.ok, .ok-pill { background: var(--ok-bg); color: var(--ok-fg); }

.badge {
  font-size: 12px;
  border-radius: 999px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  background: var(--icon);
  display: inline-block;
}

.badge.warn { background: #fff3bf; border-color: #ffe066; }
.badge.ok { background: var(--ok-bg); border-color: #c3fae8; }
.badge.err { background: var(--danger-bg); border-color: #ffc9c9; }

/* Forms */
input, button, select, textarea { font: inherit; color: inherit; }

input[type="email"],
input[type="password"],
input[type="text"],
input[type="date"],
input[type="url"],
input[type="datetime-local"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

input[type="email"], input[type="password"] {
  padding: 8px 10px;
  width: auto;
}

label {
  font-weight: 700;
  font-size: 12px;
  display: block;
  margin: 10px 0 6px;
}

button, .btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

button:disabled, .btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-ghost, button.btn-ghost {
  background: var(--icon);
  color: var(--fg);
}

.btn-warn, button.warn { background: var(--warn); color: #fff; }
.btn-danger, button.danger { background: var(--danger-bg); color: var(--danger-fg); }
.btn-ok, button.ok { background: var(--ok-bg); color: var(--ok-fg); }

.btn-sm { padding: 6px 10px; font-size: 12px; }

textarea { min-height: 120px; line-height: 1.5; white-space: pre-wrap; }

.muted { color: var(--muted); font-size: 12px; }

/* Layout */
main.page-main {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

main.page-main.split {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 16px;
}

@media (max-width: 1024px) {
  main.page-main.split { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--br);
  padding: var(--pad);
}

.row {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
  flex-wrap: wrap;
}

.row > * { flex: 1; min-width: 0; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.form-actions > * { flex: 0 0 auto; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 10px;
  align-items: start;
}

.item img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--icon);
  border: 1px solid var(--line);
}

.item.item-lg img { width: 64px; height: 64px; }

.item > div { min-width: 0; }

.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

.desc {
  color: var(--muted);
  margin-top: 6px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.scroll-list { max-height: calc(100vh - 260px); overflow: auto; }

/* Toggles */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--bg);
  cursor: pointer;
}

/* Tables */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.toolbar input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding: 8px;
}

table.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

table.data-table th,
table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
}

table.data-table th {
  background: var(--bg);
  font-weight: 800;
  font-size: 12px;
  color: var(--muted);
}

table.data-table tr:last-child td { border-bottom: 0; }

.nowrap { white-space: nowrap; }
.ellipsis {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.seg {
  display: flex;
  gap: 6px;
  background: var(--icon);
  padding: 4px;
  border-radius: 999px;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--fg);
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}

.seg button.active {
  background: var(--card);
  border: 1px solid var(--line);
}

/* Dashboard */
.dashboard-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 16px;
}

@media (max-width: 720px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

a.module-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  transition: box-shadow .2s ease, transform .04s ease;
}

a.module-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,.08); }
a.module-card:active { transform: translateY(1px); }
a.module-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.module-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--icon);
  font-size: 22px;
  flex-shrink: 0;
}

.module-title { font-weight: 800; margin: 0 0 4px; }
.module-desc { color: var(--muted); margin: 0; font-size: 13px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-card {
  width: min(980px, 96vw);
  max-height: 90vh;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
}

.modal-head,
.modal-foot {
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.modal-head h3 { margin: 0; font-size: 15px; font-weight: 800; }
.modal-body { padding: 12px; overflow: auto; }

#cropContainer {
  position: relative;
  min-height: 300px;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#cropImage { max-width: 100%; display: block; }

/* Images manager */
.images { display: flex; flex-direction: column; gap: 8px; }
.imglist { display: flex; flex-direction: column; gap: 8px; }

.imgitem {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--card);
}

.imgitem img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--icon);
  border: 1px solid var(--line);
}

.imgitem .url {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #111;
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(8px);
  transition: .25s;
  z-index: 2000;
}

.toast.show { opacity: 1; transform: none; }

main.page-main.members-layout {
  max-width: min(1400px, 98vw);
}

main.page-main.members-layout.split {
  grid-template-columns: minmax(380px, 1fr) minmax(320px, 420px);
}

.member-item {
  grid-template-columns: 64px 1fr auto;
  align-items: center;
}

.member-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.member-email {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-wrap,
.member-thumb.avatar-wrap,
.member-avatar.avatar-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.member-avatar.avatar-wrap {
  width: 72px;
  height: 72px;
}

.avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--icon);
  display: block;
}

.member-avatar.avatar-wrap img,
.member-avatar.avatar-fallback {
  border-radius: 50%;
}

.avatar-wrap .avatar-fallback {
  display: none;
  width: 100%;
  height: 100%;
  border-radius: 12px;
}

.member-avatar.avatar-wrap .avatar-fallback,
.member-avatar.avatar-fallback {
  border-radius: 50%;
}

.avatar-wrap.is-fallback img,
.avatar-wrap img[hidden] {
  display: none;
}

.avatar-wrap.is-fallback .avatar-fallback {
  display: flex;
}

.member-thumb.avatar-fallback,
.member-avatar.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #5c7cfa 0%, #7048e8 100%);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.03em;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.item.item-lg .member-thumb.avatar-fallback {
  width: 64px;
  height: 64px;
}

.member-avatar.avatar-fallback {
  width: 72px;
  height: 72px;
  font-size: 18px;
}

/* Member detail */
.member-header {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.member-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--icon);
  border: 2px solid var(--line);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.stat-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}

.stat-box strong { display: block; font-size: 20px; }
.stat-box span { font-size: 11px; color: var(--muted); }

main.page-main.deals-layout {
  max-width: min(1680px, 98vw);
}

main.page-main.deals-layout.split {
  grid-template-columns: minmax(560px, 1.2fr) minmax(300px, 0.8fr);
}

@media (max-width: 1100px) {
  main.page-main.deals-layout.split { grid-template-columns: 1fr; }
}

.row-ids { grid-template-columns: 1fr 1fr; }

.merchant-block { margin-top: 12px; }

.merchant-hint { margin: 4px 0 10px; font-size: 12px; }

.merchant-offers {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.merchant-section-title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.merchant-thead,
.merchant-row {
  display: grid;
  grid-template-columns: 28px minmax(88px, 110px) minmax(0, 1fr) minmax(100px, 130px);
  gap: 8px;
  align-items: center;
}

.merchant-thead {
  padding: 0 6px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.merchant-table {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.merchant-table.cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
}

.merchant-table.cols-2 .merchant-thead {
  grid-column: 1 / -1;
}

.merchant-row {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.merchant-row .toggle {
  margin: 0;
  justify-content: center;
}

.merchant-row input[type="url"],
.merchant-row input[type="text"] {
  width: 100%;
  font-size: 12px;
  padding: 6px 8px;
  min-width: 0;
}

.merchant-row.is-off input {
  opacity: 0.5;
}

.merchant-row .merchant-label {
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 700px) {
  .merchant-table.cols-2 { grid-template-columns: 1fr; }
  .merchant-thead,
  .merchant-row {
    grid-template-columns: 24px 80px 1fr;
  }
  .merchant-thead .th-pid,
  .merchant-row .merchant-pid { display: none; }
}
