:root {
  --primary: #6C5CE7;
  --primary-dark: #5A48D8;
  --primary-light: #EFECFD;
  --bg: #F6F6FB;
  --card: #FFFFFF;
  --border: #E7E7F2;
  --text: #1F2130;
  --text-muted: #8A8AA3;
  --success: #16A34A;
  --success-bg: #E9F9EF;
  --danger: #DC2626;
  --danger-bg: #FDEDED;
  --warning: #D97706;
  --warning-bg: #FFF6E6;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { text-decoration: none; color: inherit; }

/* ---------- Layout ---------- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  font-weight: 700;
  font-size: 18px;
  border-bottom: 1px solid var(--border);
}
.admin-badge {
  font-size: 11px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 6px;
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  cursor: pointer;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-ico { width: 18px; display: inline-block; text-align: center; }

.nav-parent { cursor: default; }
.nav-subitem {
  display: block;
  padding: 8px 12px 8px 40px;
  font-size: 13.5px;
  color: var(--text-muted);
  border-radius: 10px;
}
.nav-subitem:hover { background: var(--bg); color: var(--text); }

.nav-badge {
  background: var(--danger);
  color: white;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  margin-left: auto;
}

.nav-section {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 16px 12px 6px;
  text-transform: uppercase;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.sidebar-user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-email { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-logout {
  background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px;
}
.sidebar-logout:hover { color: var(--danger); }

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.balance-pill {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
}

.content {
  padding: 28px 32px;
  max-width: 1200px;
}

/* ---------- Cards / grid ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .cards-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.product-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.product-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
}
.product-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 3px 8px;
  border-radius: 20px;
}
.product-card ul {
  margin: 0 0 16px;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.9;
}
.product-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #fadada; }
.btn-success { background: var(--success-bg); color: var(--success); }
.btn-success:hover { background: #d3f3de; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=file], select, textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }

.two-col {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-warning { background: var(--warning-bg); color: var(--warning); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-muted { background: var(--bg); color: var(--text-muted); }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 18px;
  font-weight: 500;
}
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #EFECFD 0%, #F6F6FB 60%);
  padding: 20px;
}
.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 18px;
  padding: 34px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(108,92,231,0.08);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 6px;
  justify-content: center;
}
.auth-sub { text-align: center; color: var(--text-muted); font-size: 13.5px; margin-bottom: 24px; }
.auth-footer { text-align: center; font-size: 13.5px; color: var(--text-muted); margin-top: 18px; }
.auth-footer a { color: var(--primary); font-weight: 600; }

/* ---------- Misc ---------- */
.section-title { font-size: 16px; font-weight: 700; margin: 0 0 14px; }
.muted { color: var(--text-muted); }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.copy-box {
  display: flex;
  gap: 8px;
  align-items: center;
}
.copy-box input { flex: 1; }
.tag-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tag-tab {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.tag-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.proxy-list-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
}
code.inline { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: 13px; }

/* ---------- Language switcher ---------- */
.lang-switcher { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 3px; }
.lang-switcher a {
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.lang-switcher a.active { background: var(--card); color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.lang-switcher a:hover { color: var(--text); }
.auth-lang-switcher { display: flex; justify-content: center; margin-bottom: 18px; }

/* ---------- Locked / readonly fields ---------- */
.input-locked {
  background: #ECECF4 !important;
  color: var(--text-muted) !important;
  cursor: not-allowed;
}

/* ---------- Support chat ---------- */
.chat-window {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
  padding: 6px 2px 14px;
}
.chat-bubble {
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}
.chat-bubble-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.chat-bubble-admin {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-meta { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.chat-input-row { display: flex; gap: 10px; margin-top: 14px; }
.chat-input-row textarea { flex: 1; min-height: 46px; max-height: 46px; }
.thread-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.thread-row:hover { background: var(--bg); }
