:root {
  --primary: #800080;
  --primary-light: #9b4d9b;
  --primary-soft: #f3e8f3;
  --lavender: #e8dff5;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-light); }

.public-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.public-header .inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
}
.logo span { color: var(--primary); }
.nav-links { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.nav-links a { color: var(--text); font-weight: 500; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
  font-size: .925rem;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-danger { background: #dc2626; color: #fff; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 1rem;
  position: fixed;
  top: 0; bottom: 0;
  overflow-y: auto;
  z-index: 200;
  transform: translateX(0);
  transition: transform .25s;
}
.sidebar.admin { background: #1e1b2e; color: #e5e7eb; border-color: #2d2640; }
.sidebar.admin .sidebar-brand { color: #fff; }
.sidebar.admin .sidebar-nav a { color: #cbd5e1; }
.sidebar.admin .sidebar-nav a:hover,
.sidebar.admin .sidebar-nav a.active { background: rgba(128,0,128,.35); color: #fff; }
.sidebar-brand {
  font-weight: 700;
  padding: .75rem;
  margin-bottom: .5rem;
  display: block;
}
.sidebar-nav { display: flex; flex-direction: column; gap: .25rem; }
.sidebar-nav a {
  padding: .65rem .75rem;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
}
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: .85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar.admin { background: #252038; color: #fff; border-color: #3b3350; }
.content { padding: 1.25rem; max-width: 1400px; }
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .6rem;
  cursor: pointer;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 150;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title { margin: 0 0 1rem; font-size: 1.05rem; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat-card .label { color: var(--muted); font-size: .85rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; margin-top: .25rem; }
.stat-card .value.primary { color: var(--primary); }

.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .925rem;
}
table.data-table th, table.data-table td {
  padding: .75rem .65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
table.data-table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
table.data-table tbody tr:hover { background: #fafafa; }

.badge {
  display: inline-block;
  padding: .25rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-pending { background: #fce8e8; color: #9f4a4a; }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #e5e7eb; color: #374151; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: .35rem; font-weight: 600; font-size: .9rem; }
.form-control {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(128,0,128,.12);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.alert {
  padding: .85rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid transparent;
}
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

.hero {
  background: linear-gradient(135deg, #fff 0%, var(--lavender) 100%);
  padding: 3rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.hero .inner { max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: 1.2fr .8fr; gap: 2rem; align-items: center; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 .75rem; }
.hero p { color: var(--muted); font-size: 1.05rem; }
.hero-card { background: #fff; border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}

.pagination { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: 1rem; }
.pagination a, .pagination span {
  padding: .4rem .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: .875rem;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: linear-gradient(180deg, #fff, var(--lavender));
}
.auth-card { width: 100%; max-width: 440px; }

.auth-telegram {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 1rem;
  min-height: 44px;
}

.auth-telegram-hint {
  margin: 0 0 .75rem;
  font-size: .9rem;
  color: #4b5563;
  text-align: center;
}

.auth-telegram-botname {
  margin: 0 0 .65rem;
  font-size: .78rem;
  color: #6b7280;
  text-align: center;
}

.auth-telegram-botname strong {
  color: var(--lavender, #7c3aed);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 0 0 1rem;
  color: #6b7280;
  font-size: .85rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e5e7eb;
}

.auth-divider span { white-space: nowrap; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); }

.credit-pos { color: #059669; font-weight: 600; }
.credit-neg { color: #dc2626; font-weight: 600; }

.admin-filter-bar {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: end;
}
.admin-bulk-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  align-items: center;
  margin-bottom: .75rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.danger-zone {
  border-color: #fecaca !important;
  background: #fffbfb;
}
.danger-zone .card-title { color: #991b1b; }

@media (max-width: 992px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .hero .inner { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .stats-grid { grid-template-columns: 1fr; }
}
