:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-tint: #f0faf6;
  --ink: #0f172a;
  --ink-light: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #c8d5e0;
  --accent: #059669;
  --accent-dark: #047857;
  --accent-soft: #ecfdf5;
  --accent-mid: #d1fae5;
  --accent-ring: rgba(5, 150, 105, 0.16);
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --danger-soft: #fef2f2;
  --shadow-xs: 0 1px 2px rgba(15,23,42,0.06), 0 1px 4px rgba(15,23,42,0.04);
  --shadow-sm: 0 2px 6px rgba(15,23,42,0.06), 0 6px 16px rgba(15,23,42,0.04);
  --shadow: 0 8px 24px rgba(15,23,42,0.09), 0 2px 8px rgba(15,23,42,0.04);
  --shadow-lg: 0 20px 48px rgba(15,23,42,0.12), 0 6px 16px rgba(15,23,42,0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background:
    radial-gradient(ellipse 90% 60% at 85% -5%, rgba(5,150,105,0.07) 0%, transparent 55%),
    radial-gradient(ellipse 60% 50% at 5% 95%, rgba(99,102,241,0.05) 0%, transparent 55%),
    linear-gradient(180deg, #fff 0%, #f6f9fd 35%, var(--bg) 100%);
}

a {
  color: inherit;
}

/* ── Layout shells ─────────────────────────────── */

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(20px, 4vw, 48px);
}

.workspace,
.admin {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 2.5vw, 32px);
}

/* ── Surfaces ──────────────────────────────────── */

.panel,
.hero-panel,
.card,
.stat,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.panel {
  width: min(740px, 100%);
  padding: clamp(28px, 5vw, 52px);
  box-shadow: var(--shadow-lg);
}

.panel-small {
  width: min(440px, 100%);
}

.auth-panel,
.hero-panel {
  position: relative;
  overflow: hidden;
}

.auth-panel::before,
.hero-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, #34d399 55%, #818cf8 100%);
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(420px, 1.28fr);
  gap: clamp(24px, 3.5vw, 44px);
  align-items: center;
  padding: clamp(24px, 3.2vw, 40px);
  background:
    linear-gradient(135deg, rgba(240,250,246,0.78) 0%, rgba(255,255,255,0.94) 34%, #fff 100%);
}

.hero-panel > div:first-child {
  max-width: 390px;
}

/* ── Topbar ────────────────────────────────────── */

.topbar,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.topbar {
  position: sticky;
  top: 14px;
  z-index: 10;
  margin-bottom: 28px;
  padding: 10px 16px;
  border: 1px solid rgba(226,232,240,0.9);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.88);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ── Interactive base ──────────────────────────── */

.topbar nav a,
.link,
.table-action,
.primary-link,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

.topbar nav a,
.link {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-light);
  font-size: 13px;
  box-shadow: var(--shadow-xs);
}

.topbar nav a:hover,
.link:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  color: var(--ink);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

button.link {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-light);
  box-shadow: var(--shadow-xs);
}

button.link:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ── Typography ────────────────────────────────── */

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: -0.025em;
  text-wrap: balance;
  font-weight: 800;
}

h1 {
  font-size: clamp(28px, 3.5vw, 44px);
}

h2 {
  font-size: clamp(20px, 2.5vw, 30px);
}

.panel h1,
.hero-panel h2 {
  margin-bottom: 22px;
}

/* ── Upload zone ───────────────────────────────── */

.uploader,
.stack {
  display: grid;
  gap: 12px;
}

.uploader {
  align-self: stretch;
  padding: 4px;
}

.dropzone {
  position: relative;
  min-height: 94px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 13px;
  padding: 14px 16px;
  border: 1px solid rgba(5,150,105,0.18);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.84) 0%, rgba(236,253,245,0.86) 100%);
  text-align: left;
  cursor: pointer;
  transition: all 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: rgba(5,150,105,0.42);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.92) 0%, rgba(209,250,229,0.92) 100%);
  box-shadow: 0 0 0 4px var(--accent-ring), var(--shadow-sm);
  transform: translateY(-1px);
}

.file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.icon {
  grid-row: 1 / span 2;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, #34d399 100%);
  color: #fff;
  font-size: 24px;
  font-weight: 200;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(5,150,105,0.22), 0 2px 6px rgba(5,150,105,0.12);
}

.dropzone strong {
  grid-column: 2;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.dropzone small {
  grid-column: 2;
}

.dropzone small,
.muted {
  color: var(--muted);
  font-size: 12px;
}

/* ── Buttons ───────────────────────────────────── */

button,
.primary-link {
  min-height: 42px;
  border: 1px solid transparent;
  padding: 0 20px;
  background: linear-gradient(135deg, var(--accent) 0%, #047857 100%);
  color: #fff;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 3px rgba(5,150,105,0.25), 0 6px 18px rgba(5,150,105,0.18);
}

button:hover,
.primary-link:hover {
  background: linear-gradient(135deg, #0a8a68 0%, #036248 100%);
  box-shadow: 0 1px 3px rgba(5,150,105,0.3), 0 10px 24px rgba(5,150,105,0.22);
  transform: translateY(-1px);
}

button:active,
.primary-link:active,
.link:active,
.table-action:active {
  transform: translateY(0);
}

button.danger {
  background: linear-gradient(135deg, var(--danger) 0%, var(--danger-dark) 100%);
  box-shadow: 0 1px 3px rgba(220,38,38,0.25), 0 6px 18px rgba(220,38,38,0.16);
}

button.danger:hover {
  background: linear-gradient(135deg, #e53030 0%, #a51515 100%);
  box-shadow: 0 1px 3px rgba(220,38,38,0.3), 0 10px 24px rgba(220,38,38,0.2);
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  width: 100%;
}

/* ── Labels & inputs ───────────────────────────── */

label {
  display: grid;
  gap: 5px;
  color: var(--ink-light);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input,
select {
  min-height: 36px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs);
  padding: 0 11px;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  box-shadow: inset 0 1px 2px rgba(15,23,42,0.03), 0 1px 0 rgba(255,255,255,0.65);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input::placeholder {
  color: #94a3b8;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 12px;
  padding: 14px;
  border: 1px solid rgba(226,232,240,0.9);
  border-radius: var(--radius-sm);
  background: rgba(248,250,252,0.78);
}

select {
  width: auto;
  min-width: 86px;
  padding: 0 36px 0 13px;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 16px) 50% / 5px 4px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 11px) 50% / 5px 4px no-repeat,
    var(--surface);
}

/* ── Alerts ────────────────────────────────────── */

.alert {
  max-width: 1240px;
  margin: 0 auto 18px;
  padding: 11px 16px 11px 14px;
  border: 1px solid rgba(5,150,105,0.22);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-xs);
  background: var(--accent-soft);
  color: #065f46;
  font-size: 13px;
  font-weight: 600;
}

.alert.error {
  border-color: rgba(220,38,38,0.18);
  border-left-color: var(--danger);
  background: var(--danger-soft);
  color: #991b1b;
}

/* ── Stats & admin grid ────────────────────────── */

.stats-grid,
.admin-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-grid {
  grid-template-columns: minmax(260px, 0.54fr) minmax(560px, 1.46fr);
  align-items: start;
}

.stat,
.card {
  padding: 18px 20px;
}

.stat {
  display: grid;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: "";
  position: absolute;
  right: -8px;
  bottom: -12px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-mid);
  opacity: 0.55;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat strong {
  font-size: clamp(30px, 4vw, 40px);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.04em;
}

/* ── Sections ──────────────────────────────────── */

.section {
  margin-top: 24px;
}

.section-head {
  margin-bottom: 12px;
  align-items: center;
}

/* ── Pagination ────────────────────────────────── */

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.per-page label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pager a {
  min-width: 34px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--ink-light);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow-xs);
  transition: all 140ms ease;
}

.pager a:hover {
  border-color: rgba(5,150,105,0.32);
  background: var(--accent-soft);
  color: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.pager a.is-active {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, #047857 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5,150,105,0.28);
}

/* ── Tables ────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}

.compact {
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
}

.compact table {
  min-width: 760px;
}

th,
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  word-break: normal;
  overflow-wrap: normal;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f6f9;
  color: #64748b;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 2px solid var(--line);
}

th:last-child,
td:last-child {
  width: 200px;
}

.compact th:first-child,
.compact td:first-child {
  min-width: 150px;
}

.compact th:nth-child(2),
.compact td:nth-child(2) {
  min-width: 130px;
}

.compact th:nth-child(3),
.compact td:nth-child(3) {
  min-width: 120px;
}

.compact th:nth-child(4),
.compact td:nth-child(4) {
  min-width: 110px;
}

.compact th:nth-child(5),
.compact td:nth-child(5) {
  min-width: 170px;
}

td {
  background: var(--surface);
  font-size: 12px;
  color: var(--ink-light);
  transition: background 100ms ease;
}

td strong,
td b {
  color: var(--ink);
}

tbody tr:nth-child(even) td {
  background: #fafbfc;
}

tbody tr:hover td {
  background: var(--accent-soft) !important;
}

tr:last-child td {
  border-bottom: 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 36px 16px !important;
}

.table-action {
  min-height: 30px;
  border: 1px solid rgba(5,150,105,0.22);
  padding: 0 12px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  border-radius: var(--radius-xs);
}

.table-action:hover {
  border-color: var(--accent);
  background: var(--accent-mid);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(5,150,105,0.16);
}

/* ── User action forms ─────────────────────────── */

.actions {
  display: grid;
  gap: 6px;
  width: 100%;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: center;
}

.inline-form input {
  min-height: 34px;
  min-width: 0;
}

.inline-form .danger {
  justify-self: stretch;
}

.admin .topbar {
  margin-bottom: 18px;
}

.admin h1 {
  font-size: clamp(26px, 2.8vw, 36px);
}

.admin h2 {
  font-size: clamp(20px, 2vw, 28px);
}

.admin .stats-grid {
  gap: 12px;
  margin-bottom: 16px;
}

.admin .stat {
  min-height: 84px;
  padding: 16px 18px;
}

.admin .stat strong {
  font-size: clamp(26px, 3vw, 34px);
}

.admin .admin-grid {
  gap: 16px;
  margin-bottom: 18px;
}

.admin .card .section-head {
  margin-bottom: 10px;
}

.admin .card .stack {
  gap: 10px;
}

.admin .card input,
.admin .card button {
  min-height: 36px;
}

.admin .compact {
  border-radius: var(--radius-sm);
}

.admin .compact table {
  min-width: 640px;
}

.admin .compact th,
.admin .compact td {
  padding: 8px 12px;
}

.admin .compact tbody tr {
  height: 58px;
}

.admin .compact th:last-child,
.admin .compact td:last-child {
  width: 240px;
}

.admin .compact th:first-child,
.admin .compact td:first-child {
  min-width: 110px;
}

.admin .compact th:nth-child(2),
.admin .compact td:nth-child(2) {
  min-width: 100px;
}

.admin .compact th:nth-child(3),
.admin .compact td:nth-child(3) {
  min-width: 100px;
}

.admin .compact th:nth-child(4),
.admin .compact td:nth-child(4) {
  min-width: 90px;
}

.admin .compact th:nth-child(5),
.admin .compact td:nth-child(5) {
  min-width: 145px;
}

.admin .compact .actions {
  grid-template-columns: minmax(92px, 1fr) minmax(92px, 1fr);
  align-items: stretch;
}

.admin .compact .inline-form:first-child {
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) auto;
}

.admin .compact .inline-form input {
  min-height: 30px;
}

.admin .compact .button-small {
  min-height: 30px;
  padding: 0 10px;
}

/* ── Result page ───────────────────────────────── */

.result-panel {
  display: grid;
  gap: 24px;
}

.result-panel h1 {
  margin-bottom: 0;
}

.result-list {
  display: grid;
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.result-list div {
  display: grid;
  grid-template-columns: minmax(130px, 0.45fr) minmax(0, 1fr);
  gap: 16px;
  padding: 13px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  transition: background 120ms ease;
}

.result-list div:hover {
  background: var(--surface-soft);
}

.result-list div:last-child {
  border-bottom: 0;
}

.result-list dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-top: 2px;
}

.result-list dd {
  min-width: 0;
  margin: 0;
  font-weight: 700;
  color: var(--ink);
  overflow-wrap: anywhere;
}

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

/* ── Filter bar ────────────────────────────────── */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.filter-bar label {
  font-size: 11px;
  gap: 5px;
  flex-shrink: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.filter-bar input,
.filter-bar select {
  min-height: 34px;
  min-width: 130px;
  box-shadow: none;
  font-size: 13px;
}

.filter-bar button,
.filter-bar .link {
  min-height: 34px;
  font-size: 12px;
  padding: 0 14px;
  align-self: flex-end;
}

.bulk-panel {
  display: grid;
  gap: 12px;
}

.bulk-actions,
.bulk-actions-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.bulk-actions {
  justify-content: space-between;
}

.bulk-select-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
  font-size: 12px;
  color: var(--muted);
}

.bulk-select-user select {
  min-width: 220px;
  min-height: 34px;
}

.checkbox-col {
  width: 58px !important;
}

.checkbox-col input,
.row-checkbox {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
  box-shadow: none;
}

.checkbox-col,
.checkbox-cell {
  text-align: center;
}

/* ── Status badge ──────────────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.status-badge.active {
  background: var(--accent-soft);
  color: #065f46;
  border: 1px solid rgba(5,150,105,0.2);
}

.status-badge.blocked {
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid rgba(220,38,38,0.16);
}

/* ── Log section ───────────────────────────────── */

.log-section {
  margin-top: 24px;
}

.log-section summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 12px;
  user-select: none;
}

.log-section summary::-webkit-details-marker {
  display: none;
}

.log-section summary .toggle-hint {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}

.log-viewer {
  margin-top: 14px;
  max-height: 430px;
  overflow-y: auto;
  padding: 16px 18px;
  background: #0d1117;
  border-radius: var(--radius-sm);
  color: #c9d1d9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Responsive ────────────────────────────────── */

@media (max-width: 860px) {
  .hero-panel,
  .admin-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar,
  .section-head,
  .pagination-bar,
  .inline-form,
  .bulk-actions,
  .result-list div {
    display: grid;
  }

  .admin,
  .shell,
  .workspace {
    padding: 16px;
  }

  .panel,
  .hero-panel,
  .card,
  .stat {
    padding: 20px;
  }

  .dropzone {
    min-height: 94px;
    padding: 14px;
  }

  .topbar nav a,
  .link,
  .primary-link,
  button {
    width: 100%;
  }

  .inline-form input {
    min-width: 0;
  }

  .bulk-actions-group,
  .bulk-select-user {
    display: grid;
  }

  .bulk-select-user select {
    min-width: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 26px;
  }
}
