/* ============ THEME ============ */
:root {
  --bg: #0a0e1a;
  --bg-elev: #121829;
  --bg-card: #1a2138;
  --line: #2a3553;
  --line-soft: #1e2845;
  --text: #e8ecf5;
  --text-mute: #8895b0;
  --text-dim: #5a6785;
  --accent: #ffd64a;
  --green: #3ee08a;
  --red: #ff5a6a;
  --orange: #ff9f43;
  --blue: #4ab8ff;
  --purple: #a47bff;
  --shadow: 0 8px 32px rgba(0,0,0,.4);
  --radius: 10px;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --display: 'Bebas Neue', 'Arial Black', sans-serif;
  --body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  background-image:
    radial-gradient(at 15% 0%, rgba(255,214,74,.05) 0%, transparent 50%),
    radial-gradient(at 90% 100%, rgba(74,184,255,.04) 0%, transparent 50%);
}
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea { font-family: inherit; outline: none; }
a { color: inherit; text-decoration: none; }

/* ============ LOGIN SCREEN ============ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 100;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--green), var(--blue));
}
.login-logo {
  font-family: var(--display);
  font-size: 32px;
  letter-spacing: 2px;
  margin-bottom: 4px;
  color: var(--accent);
}
.login-sub {
  color: var(--text-mute);
  font-size: 13px;
  margin-bottom: 32px;
  letter-spacing: 0.5px;
}
.login-error {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255,90,106,.1);
  border-left: 3px solid var(--red);
  border-radius: 4px;
  color: var(--red);
  font-size: 13px;
  display: none;
}
.login-error.show { display: block; }
.input-group { margin-bottom: 18px; }
.input-group label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-mute);
  margin-bottom: 8px;
  font-weight: 600;
}
.input-group input, .input-group select, .input-group textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  transition: border .15s;
}
.input-group input:focus, .input-group select:focus, .input-group textarea:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #000;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 6px;
  font-size: 14px;
  text-transform: uppercase;
  transition: transform .15s, box-shadow .15s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(255,214,74,.3); }

/* ============ APP LAYOUT ============ */
.topbar {
  height: 64px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 10;
  gap: 24px;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display);
  color: #000;
  font-size: 20px;
}
.brand-name {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 1.5px;
}
.brand-sub {
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.topnav {
  display: flex; gap: 6px;
  flex: 1;
}
.nav-link {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-mute);
  transition: all .15s;
}
.nav-link:hover { color: var(--text); background: var(--bg-card); }
.nav-link.active { color: var(--accent); background: var(--bg-card); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 30px;
  font-size: 13px;
}
.user-avatar {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, var(--accent), var(--orange));
  border-radius: 50%;
  color: #000; font-weight: 700; font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}
.btn-logout {
  background: transparent;
  color: var(--text-mute);
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  transition: all .15s;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 28px;
}
.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 28px; flex-wrap: wrap; gap: 16px;
}
.page-title {
  font-family: var(--display);
  font-size: 36px;
  letter-spacing: 2px;
  line-height: 1;
}
.page-subtitle {
  color: var(--text-mute);
  font-size: 13px;
  margin-top: 6px;
}
.actions { display: flex; gap: 10px; }
.btn {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-accent { background: var(--accent); color: #000; }
.btn-accent:hover { box-shadow: 0 4px 16px rgba(255,214,74,.3); }
.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-ghost:hover { border-color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ============ STATS ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute; right: -10px; top: -10px;
  width: 60px; height: 60px;
  background: var(--accent);
  opacity: .04;
  border-radius: 50%;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-mute);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 1px;
  line-height: 1;
}
.stat-value.green { color: var(--green); }
.stat-value.orange { color: var(--orange); }
.stat-value.red { color: var(--red); }
.stat-value.blue { color: var(--blue); }

/* ============ FILTER ============ */
.filter-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 18px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.search-box { flex: 1; min-width: 200px; }
.search-box input {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.search-box input:focus { border-color: var(--accent); }
.filter-chip {
  padding: 7px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 30px;
  font-size: 12px;
  color: var(--text-mute);
  transition: all .15s;
}
.filter-chip.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.filter-chip:hover:not(.active) { color: var(--text); border-color: var(--text-mute); }

/* ============ ACCOUNT CARD ============ */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}
.account-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.account-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.account-card[data-mode="1"] { border-left: 3px solid var(--green); }
.account-card[data-mode="2"] { border-left: 3px solid var(--orange); }
.account-card[data-mode="3"] { border-left: 3px solid var(--red); }
.account-card[data-mode="4"] { border-left: 3px solid var(--blue); }

.acc-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 14px;
}
.acc-id-block { display: flex; flex-direction: column; min-width: 0; }
.acc-id { font-family: var(--mono); font-size: 17px; color: var(--text); font-weight: 600; }
.acc-name {
  font-size: 12px; color: var(--text-mute); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.acc-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-on { background: rgba(62,224,138,.15); color: var(--green); }
.badge-soft { background: rgba(255,159,67,.15); color: var(--orange); }
.badge-hard { background: rgba(255,90,106,.15); color: var(--red); }
.badge-freeze { background: rgba(74,184,255,.15); color: var(--blue); }

.acc-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px 0;
  border-top: 1px dashed var(--line-soft);
  border-bottom: 1px dashed var(--line-soft);
  margin-bottom: 14px;
}
.meta-item .meta-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.meta-item .meta-value {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  margin-top: 3px;
}
.meta-value.green { color: var(--green); }
.meta-value.red { color: var(--red); }

.control-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.ctrl-btn {
  padding: 9px 6px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: all .12s;
}
.ctrl-btn:hover { color: var(--text); border-color: var(--text-mute); }
.ctrl-btn.active-on { background: var(--green); color: #002a14; border-color: var(--green); }
.ctrl-btn.active-soft { background: var(--orange); color: #3d1e00; border-color: var(--orange); }
.ctrl-btn.active-hard { background: var(--red); color: #fff; border-color: var(--red); }
.ctrl-btn.active-freeze { background: var(--blue); color: #001a33; border-color: var(--blue); }
.ctrl-btn:disabled { opacity: .5; cursor: not-allowed; }

.acc-footer {
  margin-top: 12px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px;
  color: var(--text-dim);
}
.last-sync { display: flex; align-items: center; gap: 6px; }
.pulse-dot {
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}
.pulse-dot.offline { background: var(--red); animation: none; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(62,224,138,.4); }
  50% { box-shadow: 0 0 0 6px rgba(62,224,138,0); }
}

.acc-actions { display: flex; gap: 4px; }
.acc-action-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-mute);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 10px;
  transition: all .15s;
}
.acc-action-btn:hover { color: var(--text); border-color: var(--text-mute); }
.acc-action-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* ============ MODAL ============ */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-bg.active { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-title {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 1.5px;
  margin-bottom: 6px;
}
.modal-sub {
  color: var(--text-mute);
  font-size: 12px;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex; gap: 10px;
  margin-top: 20px;
}
.modal-actions .btn { flex: 1; justify-content: center; }

/* ============ TOAST ============ */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: 6px;
  font-size: 13px;
  min-width: 240px;
  box-shadow: var(--shadow);
  animation: slideIn .3s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--blue); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============ EMPTY ============ */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-mute);
  background: var(--bg-card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-icon { font-size: 48px; margin-bottom: 14px; opacity: .4; }

/* ============ TABLES (Users/Audit) ============ */
.data-table {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-collapse: collapse;
  overflow: hidden;
}
.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}
.data-table th {
  background: var(--bg-elev);
  color: var(--text-mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255,255,255,.02); }
.data-table .mono { font-family: var(--mono); }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.role-admin { background: rgba(255,214,74,.15); color: var(--accent); }
.role-client { background: rgba(74,184,255,.15); color: var(--blue); }

.action-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  background: var(--bg-elev);
  color: var(--text-mute);
}
.action-tag.success { color: var(--green); }
.action-tag.danger { color: var(--red); }
.action-tag.warning { color: var(--orange); }
.action-tag.info { color: var(--blue); }

/* Hide admin-only elements for non-admin users */
.is-client .admin-only { display: none !important; }

/* Loading state */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-mute);
  font-size: 14px;
}
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Credentials display */
.cred-box {
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 14px;
  margin: 14px 0;
}
.cred-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0;
  font-family: var(--mono);
  font-size: 13px;
}
.cred-row .label { color: var(--text-mute); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.cred-row .value {
  color: var(--accent);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: 700;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .topbar { padding: 0 14px; gap: 12px; }
  .topnav { gap: 2px; }
  .nav-link { padding: 6px 10px; font-size: 12px; }
  .brand-sub { display: none; }
  .brand-name { font-size: 18px; }
}
@media (max-width: 640px) {
  main { padding: 20px 14px; }
  .topbar { padding: 0 14px; height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .topnav { order: 3; width: 100%; overflow-x: auto; }
  .page-title { font-size: 28px; }
  .accounts-grid { grid-template-columns: 1fr; }
  .user-pill span { display: none; }
  .data-table { font-size: 11px; }
  .data-table th, .data-table td { padding: 8px; }
}
