@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f1f3fb;
  --bg-gradient: linear-gradient(160deg, #eef0ff 0%, #f6f3ff 40%, #fdf2f8 100%);
  --card: #ffffff;
  --card-alt: #f8f9fe;
  --text: #171923;
  --muted: #6b7280;
  --border: #e5e7f0;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --primary-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #d946ef 100%);
  --accent: #ec4899;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --shadow: 0 4px 20px rgba(76, 60, 160, 0.08);
  --shadow-lg: 0 12px 40px rgba(76, 60, 160, 0.16);
  --radius: 14px;
  --radius-sm: 10px;
}

:root[data-theme="dark"] {
  --bg: #12121c;
  --bg-gradient: linear-gradient(160deg, #14142a 0%, #1a1030 45%, #200f24 100%);
  --card: #1c1c2e;
  --card-alt: #22223a;
  --text: #f1f1fb;
  --muted: #9497b3;
  --border: #302f4a;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-gradient);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background 0.2s, color 0.2s;
}

a { color: inherit; }
h1, h2, h3 { font-weight: 800; letter-spacing: -0.02em; }

/* ---------- Icon / theme buttons ---------- */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.login-theme-toggle { position: absolute; top: 20px; right: 20px; }

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 44px 36px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: var(--primary-grad);
}

.login-badge {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: var(--primary-grad);
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 4px auto 18px;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.login-card h1 {
  font-size: 24px;
  margin: 0 0 6px;
  background: var(--primary-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 26px; }

.field { text-align: left; margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

input[type="text"], input[type="email"], input[type="password"], input[type="url"], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--card-alt);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 16px auto 0;
}

.hidden { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--primary-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5); }

.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 6px 18px rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: var(--danger-dark); }

.btn-ghost { background: var(--card); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--card-alt); }

.btn-soft { background: rgba(99, 102, 241, 0.12); color: var(--primary); }
:root[data-theme="dark"] .btn-soft { color: #a5a6ff; }
.btn-soft:hover { background: rgba(99, 102, 241, 0.2); }

.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ---------- Shell / topbar ---------- */
.admin-wrap, .edit-wrap { max-width: 980px; margin: 0 auto; padding: 24px 16px 70px; }

.topbar {
  background: var(--primary-grad);
  border-radius: 18px;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-lg);
  color: #fff;
  margin-bottom: 18px;
}

.topbar h1 { font-size: 24px; margin: 0; color: #fff; }
.topbar .sub { font-size: 13px; opacity: 0.85; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .icon-btn { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.25); color: #fff; }
.topbar-actions .btn-ghost { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.3); color: #fff; }
.topbar-actions .btn-ghost:hover { background: rgba(255, 255, 255, 0.28); }

/* ---------- Stat cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 720px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .stat-icon { font-size: 20px; margin-bottom: 6px; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ---------- Controls row ---------- */
.controls-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.controls-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.controls-row > * { flex: 1; min-width: 140px; }
.checkbox-row { display: flex; align-items: center; gap: 6px; flex: 0 0 auto !important; min-width: auto !important; font-size: 13.5px; color: var(--muted); }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }

.toolbar { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 8px; margin-top: 12px; }
@media (max-width: 560px) { .toolbar { grid-template-columns: 1fr 1fr; } }

/* ---------- Bulk action bar ---------- */
.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card-alt);
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  flex-wrap: wrap;
}
.bulk-bar .bulk-count { font-weight: 700; color: var(--primary); }
.bulk-bar .bulk-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- User list ---------- */
.user-list { display: flex; flex-direction: column; gap: 10px; }

.user-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, transform 0.15s;
}
.user-row:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.user-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }

.avatar {
  position: relative;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  overflow: hidden;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.avatar-clickable { cursor: pointer; transition: transform 0.12s; }
.avatar-clickable:hover { transform: scale(1.06); }

.user-info { flex: 1; min-width: 0; }
.user-info .name-row { display: flex; align-items: center; gap: 6px; }
.user-info .name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.user-info .details { color: var(--muted); font-size: 13px; white-space: pre-line; overflow-wrap: anywhere; margin-top: 1px; }

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: #fff;
}

.user-actions { display: flex; gap: 6px; flex-shrink: 0; }

.empty-state { text-align: center; color: var(--muted); padding: 50px 0; }
.empty-state .empty-emoji { font-size: 36px; margin-bottom: 8px; }

/* ---------- Edit form ---------- */
.edit-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  background: var(--primary-grad);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow-lg);
  color: #fff;
}

.edit-header h1 { font-size: 20px; margin: 0; flex: 1; overflow-wrap: anywhere; color: #fff; }
.edit-header .avatar { width: 50px; height: 50px; font-size: 19px; border: 2px solid rgba(255,255,255,0.5); }

.back-link {
  text-decoration: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.section > summary {
  list-style: none;
  cursor: pointer;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary .chev { margin-left: auto; color: var(--muted); transition: transform 0.15s; }
.section[open] > summary .chev { transform: rotate(90deg); }
.section > summary .section-icon { font-size: 18px; }

.section-body {
  padding: 4px 18px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 640px) { .section-body { grid-template-columns: 1fr; } }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  grid-column: 1 / -1;
}
.toggle-row .toggle-label { font-weight: 600; font-size: 14px; }
.toggle-row .toggle-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px;
  cursor: pointer; transition: background 0.2s;
}
.switch-track::before {
  content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch input:checked + .switch-track { background: var(--primary-grad); }
.switch input:checked + .switch-track::before { transform: translateX(20px); }

.account-row { display: flex; gap: 18px; align-items: flex-start; padding: 4px 18px 18px; }
.account-row .section-body { flex: 1; padding: 0; }
.avatar-preview-row { display: flex; justify-content: center; flex-shrink: 0; padding-top: 4px; }

@media (max-width: 480px) {
  .account-row { flex-direction: column; align-items: center; }
}

.image-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  margin-top: 8px;
  cursor: pointer;
  transition: transform 0.12s;
}
.image-thumb:hover { transform: scale(1.05); }

.password-group { position: relative; }
.password-group input { padding-right: 42px; }
.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 6px 8px;
  color: var(--muted);
  border-radius: 6px;
}
.password-toggle:hover { background: var(--card-alt); }

.input-group { display: flex; }
.input-group .input-prefix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--card-alt);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.input-group input {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.import-export-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.save-row { margin-top: 16px; }
.delete-row { margin-top: 8px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 30, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h3 { margin: 0 0 12px; font-size: 18px; }
.modal-message { color: var(--text); font-size: 14px; line-height: 1.5; white-space: pre-wrap; }

.modal-image { max-width: 480px; text-align: center; }
.modal-image img { max-width: 100%; max-height: 65vh; border-radius: var(--radius-sm); display: block; margin: 0 auto; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.option-list { display: flex; flex-direction: column; gap: 4px; }

.option-item {
  text-align: left;
  background: none;
  border: none;
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}
.option-item:hover { background: var(--card-alt); }

.paste-area {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1100;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
