:root {
  --blue: #0274df;
  --blue-dark: #0257ad;
  --ink: #111827;
  --ink-secondary: #4b5563;
  --bg: #ffffff;
  --bg-alt: #f5f7fa;
  --border: #e5e7eb;
  --radius: 14px;
  --max-width: 1200px;
  --red: #e5484d;
}

* {
  box-sizing: border-box;
}

/* .login-wrap sets display:flex and main.dashboard is a block element by
   default — both need to explicitly lose to the [hidden] attribute, since a
   later class selector otherwise beats the UA stylesheet's [hidden] rule. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

header.site {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

header.site .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  color: var(--ink);
}

.brand img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.brand .hero {
  color: var(--blue);
}

button,
input {
  font-family: inherit;
  font-size: 15px;
}

/* Login */
.login-wrap {
  min-height: calc(100vh - 61px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 32px;
}

.login-card h1 {
  font-size: 22px;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink-secondary);
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
}

.primary-button {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.primary-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.error-text {
  color: var(--red);
  font-size: 14px;
  margin-top: 12px;
}

/* Dashboard */
main.dashboard {
  padding: 28px 0 80px;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.dashboard-header h1 {
  font-size: 24px;
  margin: 0;
}

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

.link-button {
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 32px;
}

.stat-tile {
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}

.stat-tile .value {
  font-size: 26px;
  font-weight: 800;
}

.stat-tile .label {
  font-size: 13px;
  color: var(--ink-secondary);
  margin-top: 4px;
}

section.panel {
  margin-bottom: 36px;
}

section.panel h2 {
  font-size: 18px;
  margin: 0 0 14px;
}

.top-list {
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 8px 20px;
}

.top-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.top-row:last-child {
  border-bottom: none;
}

.top-row .rank {
  width: 20px;
  color: var(--ink-secondary);
  font-weight: 700;
  text-align: center;
}

.top-row .thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}

.top-row .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}

.top-row .main {
  flex: 1;
  min-width: 0;
}

.top-row .title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-row .sub {
  font-size: 13px;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-row .count {
  font-weight: 700;
  white-space: nowrap;
}

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

.search-input {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--ink);
  min-width: 240px;
}

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  white-space: nowrap;
}

table.users-table th,
table.users-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.users-table thead th {
  background: var(--bg-alt);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
}

table.users-table thead th:hover {
  color: var(--blue);
}

table.users-table tbody tr:hover {
  background: var(--bg-alt);
}

.muted {
  color: var(--ink-secondary);
}

.empty-state {
  color: var(--ink-secondary);
  padding: 16px 0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f3f4f6;
    --ink-secondary: #a1a8b3;
    --bg: #12151b;
    --bg-alt: #1a1e27;
    --border: #262b35;
  }
}
