/* QRGen Admin — Dark Theme, BEM, Native CSS Nesting */

:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-surface-hover: #22262f;
  --color-border: #2e3340;
  --color-text: #e1e4eb;
  --color-text-muted: #8b90a0;
  --color-primary: #6c8cff;
  --color-primary-hover: #8aa4ff;
  --color-danger: #ff5c5c;
  --color-danger-hover: #ff7a7a;
  --color-warning: #ffb347;
  --color-success: #4caf50;
  --color-error: #ff5c5c;
  --radius: 6px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --max-width: 1200px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.admin {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--color-primary);
  text-decoration: none;

  &:hover {
    color: var(--color-primary-hover);
  }
}

/* --- Header --- */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;

  & .header__inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
  }

  & .header__brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
  }

  & .header__user {
    margin-left: auto;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
}

/* --- Nav --- */
.nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;

  & .nav__link {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;

    &:hover {
      background: var(--color-surface-hover);
      color: var(--color-text);
    }
  }
}

/* --- Main --- */
.main {
  flex: 1;
  padding: 2rem 1.5rem;

  & .main__inner {
    max-width: var(--max-width);
    margin: 0 auto;
  }
}

/* --- Footer --- */
.footer {
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);

  & .footer__inner {
    max-width: var(--max-width);
    margin: 0 auto;
  }
}

/* --- Auth pages --- */
.auth {
  max-width: 400px;
  margin: 2rem auto;

  & .auth__title {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    text-align: center;
  }

  & .auth__link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
  }
}

/* --- Forms --- */
.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;

  &.form--inline {
    flex-direction: row;
    align-items: flex-end;
    margin-bottom: 1.5rem;
  }

  & .form__group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;

    &.form__group--inline {
      flex-direction: row;
      gap: 0.5rem;
      align-items: center;
      flex-wrap: wrap;
    }
  }

  & .form__label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
  }

  & .form__input,
  & .form__select {
    padding: 0.5rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: var(--font);

    &:focus {
      outline: none;
      border-color: var(--color-primary);
      box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 25%, transparent);
    }
  }

  & .form__input--inline {
    width: auto;
    min-width: 160px;
  }
}

.inline-form {
  display: inline-flex;
  gap: 0.375rem;
  align-items: center;
  margin-right: 0.5rem;
  margin-bottom: 0.25rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;

  &.btn--primary {
    background: var(--color-primary);
    color: #fff;

    &:hover {
      background: var(--color-primary-hover);
    }
  }

  &.btn--secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);

    &:hover {
      background: var(--color-surface-hover);
    }
  }

  &.btn--danger {
    background: var(--color-danger);
    color: #fff;

    &:hover {
      background: var(--color-danger-hover);
    }
  }

  &.btn--warning {
    background: var(--color-warning);
    color: #000;

    &:hover {
      opacity: 0.85;
    }
  }

  &.btn--small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
  }
}

/* --- Alerts --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 1rem;

  &.alert--error {
    background: color-mix(in srgb, var(--color-error) 15%, var(--color-surface));
    border: 1px solid var(--color-error);
    color: var(--color-error);
  }

  &.alert--success {
    background: color-mix(in srgb, var(--color-success) 15%, var(--color-surface));
    border: 1px solid var(--color-success);
    color: var(--color-success);
  }
}

/* --- Badge --- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;

  &.badge--admin {
    background: color-mix(in srgb, var(--color-primary) 20%, transparent);
    color: var(--color-primary);
  }

  &.badge--viewer {
    background: color-mix(in srgb, var(--color-text-muted) 20%, transparent);
    color: var(--color-text-muted);
  }
}

/* --- Dashboard stats --- */
.dashboard {
  & .dashboard__title {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
  }
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;

  & .stats__card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
  }

  & .stats__label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 0.25rem;
  }

  & .stats__value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
  }
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
}

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

  & .table__head {
    background: var(--color-surface);
  }

  & .table__header {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--color-border);
  }

  & .table__row {
    border-bottom: 1px solid var(--color-border);

    &:hover {
      background: var(--color-surface-hover);
    }
  }

  & .table__cell {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    vertical-align: middle;

    &.table__cell--truncate {
      max-width: 250px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    &.table__cell--actions {
      white-space: nowrap;
    }
  }
}

/* --- Logs accordion --- */
.logs__row {
  cursor: pointer;
  transition: background 0.15s;

  &:hover {
    background: var(--color-surface-hover);
  }

  &.logs__row--expanded {
    background: var(--color-surface);
  }
}

.logs__details {
  visibility: collapse;

  & .table__cell {
    padding: 0;
    overflow: hidden;
  }

  & .logs__details-inner {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: start;
    padding: 0 0.75rem;
  }

  &.logs__details--open {
    visibility: visible;

    & .table__cell {
      padding: 0;
    }

    & .logs__details-inner {
      max-height: 250px;
      padding: 0.75rem;
    }
  }
}

.logs__details-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
}

.logs__details-preview {
  display: flex;
  align-items: center;
  justify-content: center;
}

.logs__details-qr {
  width: 150px;
  height: 150px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: #fff;
  object-fit: contain;
}

.logs__detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.logs__detail-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.logs__detail-value {
  font-size: 0.875rem;
  color: var(--color-text);
}

/* --- Pagination --- */
.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  justify-content: center;

  & .pagination__link {
    padding: 0.375rem 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;

    &:hover {
      background: var(--color-surface-hover);
    }
  }

  & .pagination__info {
    font-size: 0.875rem;
    color: var(--color-text-muted);
  }
}

/* --- Section titles --- */
.whitelist__title,
.logs__title,
.users__title {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
}

/* --- Users add section --- */
.users__add {
  margin-bottom: 1.5rem;

  & summary {
    cursor: pointer;
    list-style: none;

    &::-webkit-details-marker {
      display: none;
    }
  }

  & .form {
    margin-top: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    max-width: 400px;
  }
}

/* --- Landing page --- */
body.landing {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100dvh;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .header .header__inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .header .header__user {
    margin-left: 0;
  }

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

  .inline-form {
    display: flex;
    flex-wrap: wrap;
  }
}
