:root {
  --bg: #07111d;
  --panel: #0c1a28;
  --panel-soft: #102233;
  --line: rgba(148, 178, 201, .17);
  --line-strong: rgba(148, 178, 201, .3);
  --text: #edf7f4;
  --muted: #8fa5b4;
  --muted-strong: #b8c8d2;
  --green: #39e6a5;
  --green-deep: #13bd82;
  --red: #ff6b7d;
  --gold: #ffce73;
  --blue: #68aaf9;
  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 22px 72px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 83% -10%, rgba(57, 230, 165, .13), transparent 34%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  content: "";
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, .018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .018) 1px, transparent 1px);
  background-size: 42px 42px;
}

button,
input,
textarea,
select { font: inherit; }

button { border: 0; }
.hidden { display: none !important; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(12, 26, 40, .94);
  box-shadow: var(--shadow);
}

small {
  color: var(--green);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .14em;
}

button {
  position: relative;
  min-height: 40px;
  padding: 10px 15px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--green), var(--green-deep));
  color: #052117;
  font-weight: 850;
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease, border-color .16s ease;
}

button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.07); }
button:disabled { cursor: wait; opacity: .68; }
button.ghost { border: 1px solid var(--line); background: rgba(255, 255, 255, .025); color: var(--muted-strong); }
button.ghost:hover:not(:disabled) { border-color: var(--line-strong); background: rgba(255, 255, 255, .055); }
button.danger { background: rgba(255, 107, 125, .11); color: var(--red); }
button.danger.ghost { border-color: rgba(255, 107, 125, .2); }

button.is-loading { padding-left: 35px; }
button.is-loading::before {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 13px;
  height: 13px;
  margin-top: -7px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin .7s linear infinite;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid #2a4050;
  border-radius: var(--radius-sm);
  outline: 0;
  background: #07121e;
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease;
}

input,
select { min-height: 44px; padding: 0 13px; }
textarea { min-height: 96px; padding: 13px; resize: vertical; }
input:focus,
textarea:focus,
select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(57, 230, 165, .1); }
input::placeholder { color: #607888; }

label { display: grid; gap: 7px; margin: 16px 0; color: var(--muted-strong); font-weight: 700; }

/* Login */
.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(450px, 100%);
  padding: 38px;
  background:
    radial-gradient(circle at 95% 0, rgba(57, 230, 165, .09), transparent 34%),
    rgba(12, 26, 40, .97);
}

.logo { display: flex; height: 30px; align-items: end; gap: 5px; margin-bottom: 20px; }
.logo i { width: 7px; border-radius: 8px; background: var(--green); animation: pulse 1.4s ease-in-out infinite; }
.logo i:nth-child(1) { height: 12px; }
.logo i:nth-child(2) { height: 26px; animation-delay: .2s; }
.logo i:nth-child(3) { height: 18px; animation-delay: .4s; }
@keyframes pulse { 50% { opacity: .35; transform: scaleY(.7); } }
.login-card h1 { margin: 8px 0; font-size: 32px; letter-spacing: -.04em; }
.login-card p { margin-bottom: 26px; color: var(--muted); line-height: 1.7; }
#login-form button { width: 100%; margin-top: 8px; }
#login-error { display: block; min-height: 22px; margin-top: 12px; color: var(--red); }

/* Application */
header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(7, 17, 29, .86);
  backdrop-filter: blur(16px);
}

header > div { display: flex; align-items: center; gap: 15px; }
header strong { font-size: 12px; letter-spacing: .09em; }
header #admin-name { color: var(--muted); font-size: 12px; }

main { max-width: 1240px; margin: auto; padding: 34px 24px 80px; }

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  overflow: hidden;
  padding: 30px;
  background:
    radial-gradient(circle at 88% 25%, rgba(57, 230, 165, .11), transparent 28%),
    rgba(12, 26, 40, .94);
}
.hero h1 { margin: 5px 0; font-size: clamp(28px, 4vw, 38px); letter-spacing: -.045em; }
.hero p { margin: 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0; }
.stats > div { position: relative; overflow: hidden; padding: 21px; box-shadow: none; }
.stats > div::after { position: absolute; top: -18px; right: -18px; width: 64px; height: 64px; border: 1px solid rgba(57, 230, 165, .08); border-radius: 50%; content: ""; }
.stats span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .11em; }
.stats strong { display: block; margin-top: 8px; font-size: 26px; letter-spacing: -.03em; }
.safe { color: var(--green); font-size: 17px !important; }

.panel { margin-top: 18px; padding: 24px; box-shadow: none; }
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 18px; }
.panel h2 { margin: 4px 0 0; font-size: 23px; letter-spacing: -.035em; }
.panel-copy { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.user-toolbar { display: grid; grid-template-columns: minmax(230px, 1fr) 190px auto; align-items: end; gap: 12px; margin-bottom: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .02); }
.user-toolbar label { margin: 0; }
.user-toolbar label > span,
.audit-actions label > span { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.result-count { align-self: center; padding: 8px 11px; border-radius: 999px; background: rgba(57, 230, 165, .08); color: var(--green); font-size: 10px; font-weight: 850; white-space: nowrap; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th,
td { padding: 15px 11px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.user-table tbody tr { transition: background .14s ease; }
.user-table tbody tr:hover { background: rgba(255, 255, 255, .018); }

.user-identity { display: flex; min-width: 250px; align-items: center; gap: 12px; }
.user-avatar { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border: 1px solid rgba(57, 230, 165, .3); border-radius: 13px; background: rgba(57, 230, 165, .08); color: var(--green); font-size: 11px; font-weight: 900; }
.user-copy { display: flex; min-width: 0; flex-direction: column; gap: 4px; }
.user-copy strong { font-size: 13px; letter-spacing: .02em; }
.user-copy small { overflow: hidden; max-width: 330px; color: var(--muted); font-size: 10px; font-weight: 500; letter-spacing: 0; text-overflow: ellipsis; white-space: nowrap; }

.status { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 999px; background: rgba(57, 230, 165, .1); color: var(--green); font-size: 9px; font-weight: 900; letter-spacing: .06em; }
.status::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; box-shadow: 0 0 0 4px rgba(57, 230, 165, .07); }
.status.disabled { background: rgba(255, 107, 125, .1); color: var(--red); }
.locked-note { display: block; margin-top: 7px; color: var(--gold); font-size: 8px; font-weight: 700; letter-spacing: 0; }

.client-usage { display: grid; min-width: 100px; gap: 7px; }
.client-usage strong { font-size: 12px; }
.client-usage > span { display: block; overflow: hidden; width: 88px; height: 5px; border-radius: 999px; background: rgba(255, 255, 255, .08); }
.client-usage i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green-deep), var(--green)); }

.activity-cell { display: flex; min-width: 108px; flex-direction: column; gap: 6px; }
.activity-cell > span { align-self: flex-start; padding: 5px 8px; border-radius: 7px; font-size: 9px; font-weight: 850; }
.online-pill { background: rgba(57, 230, 165, .09); color: var(--green); }
.offline-pill { background: rgba(143, 165, 180, .08); color: var(--muted); }
.activity-cell small { color: var(--muted); font-size: 9px; font-weight: 500; letter-spacing: 0; }

.user-actions { min-width: 255px; white-space: nowrap; }
.user-actions button,
td button { min-height: 32px; margin: 2px 4px 2px 0; padding: 6px 9px; font-size: 9px; }
.empty-row { padding: 34px; color: var(--muted); text-align: center; }

.audit-head { align-items: center; }
.audit-actions { display: flex; align-items: end; gap: 9px; }
.audit-actions label { display: grid; min-width: 145px; gap: 6px; margin: 0; }
.audit-actions select { min-height: 38px; }
.audit-actions button { min-height: 38px; }
.audit-list { display: grid; gap: 8px; }
.audit { display: grid; grid-template-columns: 165px minmax(170px, .55fr) 1fr; align-items: center; gap: 13px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255, 255, 255, .017); }
.audit-time { color: var(--muted); font-size: 10px; }
.audit-action { overflow: hidden; color: var(--muted-strong); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.audit-subject { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

dialog { border: 0; background: transparent; color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .75); backdrop-filter: blur(5px); }
.dialog-card { width: min(540px, calc(100vw - 30px)); padding: 29px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.dialog-card h2 { margin: 7px 0 13px; }
.dialog-card p { color: var(--muted); }
.dialog-card dl { display: grid; grid-template-columns: 150px 1fr; gap: 10px; }
.dialog-card dt { color: var(--muted); }
.dialog-card dd { margin: 0; color: var(--gold); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.dialog-card img { display: block; width: 200px; height: 200px; margin: 20px auto; padding: 8px; border-radius: 8px; background: white; }
.dialog-card > button { width: 100%; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.dialog-actions button { width: 100%; }
.wide-dialog { width: min(920px, calc(100vw - 30px)); }
.wide-dialog td { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }

.toast { position: fixed; z-index: 50; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 14px 18px; border: 1px solid var(--line-strong); border-radius: 11px; background: #142633; color: var(--text); box-shadow: var(--shadow); opacity: 0; transform: translateY(15px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }

.loading-overlay { position: fixed; z-index: 100; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; background: rgba(7, 17, 29, .82); opacity: 0; visibility: hidden; backdrop-filter: blur(9px); transition: opacity .18s ease, visibility .18s ease; }
.loading-overlay.visible { opacity: 1; visibility: visible; }
.loading-overlay strong { color: var(--muted-strong); font-size: 12px; }
.spinner { width: 38px; height: 38px; border: 3px solid rgba(57, 230, 165, .18); border-top-color: var(--green); border-radius: 50%; animation: spin .75s linear infinite; }

@media (max-width: 960px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .user-toolbar { grid-template-columns: 1fr 180px; }
  .result-count { grid-column: 1 / -1; justify-self: start; }
  .panel-head.audit-head { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 720px) {
  header { padding: 0 16px; }
  header > div:first-child small { display: none; }
  header #admin-name { display: none; }
  main { padding: 24px 14px 60px; }
  .hero { align-items: flex-start; flex-direction: column; padding: 23px; }
  .hero button { width: 100%; }
  .panel { padding: 18px 14px; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .panel-head > button { width: 100%; }
  .user-toolbar { grid-template-columns: 1fr; }
  .audit-actions { width: 100%; align-items: stretch; flex-direction: column; }
  .audit-actions label { width: 100%; }
  .audit { grid-template-columns: 1fr; gap: 5px; }
  .audit-action,
  .audit-subject { white-space: normal; }
  .dialog-card dl { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .login-card { padding: 28px 21px; }
  .stats { grid-template-columns: 1fr; }
  .dialog-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
