:root {
  --bg: #0c0d10;
  --bg-elevated: #14161c;
  --bg-card: #1a1d26;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --gold: #d4a853;
  --gold-soft: rgba(212, 168, 83, 0.15);
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.12);
  --success: #34d399;
  --danger: #f87171;
  --sidebar-w: 260px;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--gold); text-decoration: none; transition: color 0.15s; }
a:hover { color: #e8c47a; }

/* ---- Login ---- */
body.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(212, 168, 83, 0.18), transparent),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(139, 92, 246, 0.12), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(26, 29, 38, 0.92);
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) + 4px);
  padding: 36px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand .logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--gold), #a67c2e);
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: 0 8px 24px rgba(212, 168, 83, 0.25);
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.login-brand p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ---- App shell ---- */
.admin-app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #12141a 0%, #0e1015 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand .logo-sm {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--gold), #9a7232);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-brand strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
}

.sidebar-brand span {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-link.active {
  background: var(--gold-soft);
  color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(212, 168, 83, 0.2);
}

.nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  opacity: 0.9;
}

.sidebar-footer {
  padding: 16px 12px 20px;
  border-top: 1px solid var(--border);
}

.nav-link.logout:hover {
  background: rgba(248, 113, 113, 0.1);
  color: var(--danger);
}

.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 13, 16, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 50;
  overflow: visible;
}

.topbar-title {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.user-pill-role {
  margin-left: 4px;
}

.user-pill-name {
  color: var(--text);
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.content {
  flex: 1;
  padding: 28px;
  max-width: 1280px;
  width: 100%;
}

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  max-width: 560px;
}

.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- Cards & stats ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), transparent);
  opacity: 0.7;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.stat-value {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-card.purple::before { background: linear-gradient(90deg, var(--accent), transparent); }
.stat-card.green::before { background: linear-gradient(90deg, var(--success), transparent); }

/* ---- Table ---- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data-table th {
  text-align: left;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

table.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.table-empty td {
  text-align: center;
  color: var(--text-muted);
  padding: 32px !important;
}

/* ---- Forms & buttons ---- */
label {
  display: block;
  margin-top: 16px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

label:first-child { margin-top: 0; }

input, textarea, select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(212, 168, 83, 0.5);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

input[type="file"] { padding: 9px; font-size: 0.82rem; }

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  min-width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--gold, #d4a853);
  cursor: pointer;
}

label.form-check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  width: fit-content;
  max-width: 100%;
}

label.form-check.full {
  width: auto;
}

label.form-check input[type="checkbox"],
label.form-check input[type="radio"] {
  margin-top: 0;
}

.form-section {
  grid-column: 1 / -1;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border, #333);
}

.form-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.form-section h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--text);
}

.form-section .page-subtitle,
.form-hint {
  margin: 0 0 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.form-warn {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(180, 60, 40, 0.12);
  border: 1px solid rgba(180, 60, 40, 0.35);
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
  text-decoration: none;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--gold), #b8893a);
  color: #1a1200;
  box-shadow: 0 4px 14px rgba(212, 168, 83, 0.3);
}

.btn-primary:hover { color: #1a1200; box-shadow: 0 6px 20px rgba(212, 168, 83, 0.4); }

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover { color: var(--text); background: rgba(255, 255, 255, 0.1); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.btn-danger { background: rgba(248, 113, 113, 0.15); color: var(--danger); border: 1px solid rgba(248,113,113,0.25); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}

.form-grid .full { grid-column: 1 / -1; }

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ---- Badges & flash ---- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge-gold { background: var(--gold-soft); color: var(--gold); }
.badge-green { background: rgba(52, 211, 153, 0.12); color: var(--success); }
.badge-purple { background: var(--accent-soft); color: var(--accent); }
.badge-muted { background: rgba(255,255,255,0.06); color: var(--text-muted); }

.flash {
  padding: 14px 16px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 0.875rem;
  border: 1px solid transparent;
}

.flash.success, .flash:not(.error) {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.25);
  color: #a7f3d0;
}

.flash.error {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.25);
  color: #fecaca;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 4px;
}

code {
  background: rgba(255,255,255,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

.form-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.form-section-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] { display: none !important; }

body.modal-open { overflow: hidden; }

.modal-card {
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: calc(var(--radius) + 2px);
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.lang-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.lang-tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
}

.lang-tab.active {
  background: var(--gold-soft);
  border-color: rgba(212, 168, 83, 0.45);
  color: var(--gold);
}

.lang-panel { display: none; }
.lang-panel.active { display: block; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.device-edit-row td {
  background: rgba(255, 255, 255, 0.02);
  padding-top: 0;
  padding-bottom: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.locale-flag,
.locale-flag-emoji {
  display: block;
  width: 22px;
  height: 15px;
  border-radius: 3px;
  object-fit: cover;
  flex-shrink: 0;
}

.locale-flag-emoji {
  width: auto;
  height: auto;
  font-size: 16px;
  line-height: 1;
}

.locale-dropdown {
  position: relative;
  flex-shrink: 0;
}

.locale-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.locale-dropdown-trigger:hover,
.locale-dropdown.is-open > .locale-dropdown-trigger {
  background: var(--gold-soft);
  border-color: rgba(212, 168, 83, 0.35);
  box-shadow: 0 0 0 1px rgba(212, 168, 83, 0.1);
}

.locale-dropdown-flag {
  display: flex;
  align-items: center;
}

.locale-dropdown-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.locale-dropdown-chevron {
  color: var(--text-dim);
  transition: transform 0.2s, color 0.15s;
  flex-shrink: 0;
}

.locale-dropdown.is-open > .locale-dropdown-trigger .locale-dropdown-chevron {
  transform: rotate(180deg);
  color: var(--gold);
}

.locale-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  padding: 6px;
  background: #14161c;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: 200;
}

.locale-dropdown.is-open .locale-dropdown-menu {
  display: block;
  animation: localeMenuIn 0.15s ease-out;
}

@keyframes localeMenuIn {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.locale-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}

.locale-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.locale-dropdown-item.is-active {
  background: var(--gold-soft);
  color: var(--gold);
}

.locale-dropdown-item-flag {
  display: flex;
  align-items: center;
}

.locale-dropdown-item-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.locale-dropdown-item-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: inherit;
  line-height: 1.2;
}

.locale-dropdown-item-code {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.65;
  line-height: 1.2;
}

.locale-dropdown-check {
  font-size: 0.82rem;
  color: var(--gold);
  font-weight: 700;
}

.login-locale-wrap {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10;
}

.login-locale-wrap .locale-dropdown-menu {
  right: 0;
}

@media (max-width: 900px) {
  .admin-app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
  }
  .sidebar-footer { display: none; }
  .nav-link.logout { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 20px 16px; }
  .user-pill-name { display: none; }
  .locale-dropdown-label { display: none; }
  .user-pill { padding: 6px 10px 6px 6px; gap: 8px; }
}
