:root {
  --ink: #12161d;
  --panel: #191f29;
  --panel-raised: #202836;
  --border: #2a3341;
  --text: #e7eaf1;
  --muted: #8b93a5;
  --accent: #d9a441;
  --accent-dim: #a67d34;
  --ok: #4fb787;
  --danger: #e0605a;
  --danger-dim: #7a3230;
  --radius: 6px;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  overflow-x: hidden;
  width: 100%;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), var(--ink));
}

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

.brand-mark {
  font-size: 20px;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(217, 164, 65, 0.08);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }

.brand-title {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 15px;
}

.brand-path {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

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

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s;
}
.status.ok .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.status.err .dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* ---- Content ---- */
.content {
  flex: 1;
  padding: 24px 28px 40px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.search-wrap { flex: 1; min-width: 200px; }

#searchInput {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: 14px;
}
#searchInput:focus { outline: none; border-color: var(--accent-dim); }

.btn {
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent-dim); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #17130a;
  font-weight: 600;
}
.btn-primary:hover { background: #e5b358; border-color: #e5b358; }

.btn-ghost { background: transparent; }

.btn-white {
  background: #f2f4f8;
  border-color: #f2f4f8;
  color: #17130a;
  font-weight: 600;
}
.btn-white:hover { background: #ffffff; border-color: #ffffff; }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #1c0d0c;
  font-weight: 600;
}
.btn-danger:hover { background: #e8756f; }

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 4px;
}

#statusFilter {
  cursor: pointer;
  min-width: 140px;
  font-family: var(--sans);
}
#statusFilter:focus { outline: none; border-color: var(--accent-dim); }

/* ---- Field-wise filters ---- */
.filter-row {
  display: none;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 14px;
  margin-bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-row.open { display: flex; }

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex: 1 1 150px;
  min-width: 130px;
}
.filter-field input {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 13px;
  text-transform: none;
  letter-spacing: normal;
}
.filter-field input:focus { outline: none; border-color: var(--accent-dim); }

#clearFiltersBtn { flex: 0 0 auto; }

.result-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  margin: -8px 0 12px 2px;
}

/* ---- Selection / bulk actions ---- */
.col-select { width: 36px; text-align: center; }
.col-select input[type="checkbox"],
.row-checkbox {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.bulk-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: rgba(217, 164, 65, 0.08);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
}
.bulk-bar.open { display: flex; }
.bulk-actions { display: flex; gap: 8px; }

/* ---- Table ---- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.user-table {
  width: 100%;
  border-collapse: collapse;
}

.user-table thead th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-raised);
}

.user-table tbody tr {
  border-bottom: 1px solid var(--border);
}
.user-table tbody tr:last-child { border-bottom: none; }
.user-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.user-table td {
  padding: 12px 16px;
  vertical-align: middle;
  font-size: 14px;
}

.uid-cell { font-family: var(--mono); color: var(--accent); }

.col-actions { text-align: right; }
.actions-cell { display: flex; gap: 8px; justify-content: flex-end; }

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge-active { color: var(--ok); border-color: rgba(79,183,135,0.4); background: rgba(79,183,135,0.08); }
.badge-locked { color: var(--danger); border-color: rgba(224,96,90,0.4); background: rgba(224,96,90,0.08); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,12,16,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-small { max-width: 420px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 17px; font-family: var(--mono); font-weight: 600; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}
.icon-btn:hover { color: var(--text); }

.modal-body { padding: 22px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field span small { color: var(--muted); font-weight: 400; }
.field input {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent-dim); }

.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 4px 0 0;
}

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

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-raised);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: rgba(224,96,90,0.5); color: #ffb3ae; }
.toast.success { border-color: rgba(79,183,135,0.5); color: #b6f0d8; }

/* ---- Login screen ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #1b2230, var(--ink) 60%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* =======================================================================
   Responsive layout
   Breakpoints: 900px (tablet: tighten spacing, stack toolbar controls),
   768px (table becomes stacked cards), 420px (extra-narrow phones).
   ======================================================================= */

@media (max-width: 900px) {
  .content { padding: 20px 16px 32px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: 0; }
  #statusFilter,
  #toggleFiltersBtn,
  #newUserBtn { width: 100%; }

  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-field { min-width: 0; }
  #clearFiltersBtn { width: 100%; }

  .bulk-bar { flex-direction: column; align-items: stretch; }
  .bulk-actions { justify-content: stretch; }
  .bulk-actions .btn { flex: 1; }
}

@media (max-width: 768px) {
  /* ---- Topbar: let brand/status wrap instead of overflowing ---- */
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
  }
  .topbar-right { flex-wrap: wrap; gap: 10px; }
  .brand-title { font-size: 14px; }
  .brand-path {
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .status .status-label {
    max-width: 40vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ---- Table -> stacked cards ---- */
  .table-wrap { border: none; background: transparent; overflow: visible; }
  .user-table, .user-table tbody, .user-table tr, .user-table td { display: block; width: 100%; }
  .user-table thead { display: none; }

  .user-table tbody tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 4px 14px;
  }
  .user-table tbody tr:last-child { margin-bottom: 0; }

  .user-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }
  .user-table td:last-child { border-bottom: none; }

  .user-table td[data-label]::before {
    content: attr(data-label);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: left;
    flex: 0 0 auto;
  }

  .user-table td.col-select {
    display: flex !important;
    justify-content: flex-start !important;
  }
  .user-table td.col-select::before { display: none; }

  .user-table td.actions-cell {
    display: flex !important;
    flex-wrap: wrap;
    justify-content: flex-end !important;
  }
  .user-table td.actions-cell::before { display: none; }

  .uid-cell { text-align: right; }

  .empty-row { display: block; text-align: center; }
}

@media (max-width: 640px) {
  .field-row { flex-direction: column; }
  .col-actions, .actions-cell { justify-content: flex-start; }
  .user-table { font-size: 13px; }

  /* ---- Modal: use nearly the full screen on phones ---- */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
  }
  .modal-body { padding: 18px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

@media (max-width: 420px) {
  .brand-mark { width: 30px; height: 30px; font-size: 17px; }
  .brand-title { font-size: 13px; }
  .btn { padding: 9px 12px; font-size: 13px; }
  .btn-small { padding: 6px 9px; font-size: 12px; }
  .user-table tbody tr { padding: 4px 12px; }
}