:root {
  --bg: #0f1014;
  --bg-elevated: #16181d;
  --surface: #1c1f26;
  --surface-2: #252830;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f5f7;
  --muted: #8b919a;
  --accent: #5865f2;
  --accent-soft: rgba(88, 101, 242, 0.15);
  --accent-hover: #4752c4;
  --green: #3ba55d;
  --green-soft: rgba(59, 165, 93, 0.15);
  --red: #ed4245;
  --red-soft: rgba(237, 66, 69, 0.15);
  --amber: #faa81a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --sidebar-w: 260px;
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Brand */
.brand-mark {
  display: block;
  flex-shrink: 0;
}

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

.brand-lockup-center {
  flex-direction: column;
  text-align: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-lockup-lg .brand-name {
  font-size: 1.5rem;
}

.brand-name {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-tagline {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px 56px;
}

.login-panel-brand {
  background:
    radial-gradient(ellipse 120% 80% at 0% 0%, rgba(88, 101, 242, 0.18), transparent),
    linear-gradient(160deg, var(--bg-elevated) 0%, var(--bg) 100%);
  border-right: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.login-panel-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, black, transparent 85%);
  pointer-events: none;
}

.login-panel-inner {
  position: relative;
  z-index: 1;
  max-width: 400px;
}

.login-features {
  list-style: none;
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-features li {
  font-size: 0.92rem;
  color: var(--muted);
  padding-left: 22px;
  position: relative;
  line-height: 1.45;
}

.login-features li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(88, 101, 242, 0.6);
}

.login-footer-note {
  position: relative;
  z-index: 1;
  margin-top: auto;
  padding-top: 48px;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.7;
}

.login-panel-form {
  align-items: center;
  background: var(--bg);
}

.login-card {
  width: min(400px, 100%);
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.login-hint {
  margin-top: 24px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.btn-discord {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: #5865f2;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.35);
}

.btn-discord:hover {
  background: #4752c4;
  box-shadow: 0 6px 20px rgba(88, 101, 242, 0.45);
}

.btn-discord-icon {
  flex-shrink: 0;
  opacity: 0.95;
}

@media (max-width: 900px) {
  .login-screen {
    grid-template-columns: 1fr;
  }
  .login-panel-brand {
    display: none;
  }
  .login-panel-form {
    padding: 32px 24px;
    min-height: 100vh;
  }
}

/* Dashboard layout — sidebar LEFT */
.dashboard {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.main {
  padding: 28px 32px 48px;
  overflow-x: hidden;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-brand-text .brand-name {
  font-size: 0.95rem;
}

.sidebar-brand-text .brand-tagline {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 14px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: #fff;
}

.nav-svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.75;
}

.nav-item.active .nav-svg {
  opacity: 1;
}

.sidebar-user {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 12px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}

.user-chip img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.user-chip .name { font-weight: 600; font-size: 0.9rem; }
.user-chip .role { font-size: 0.75rem; color: var(--muted); }

/* Page header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}

.page-eyebrow {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.page-title { font-size: 1.75rem; font-weight: 700; }

/* Cards & stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-card .label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2, .card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.toolbar .field {
  width: auto;
  min-width: 160px;
  margin: 0;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.field textarea { min-height: 80px; resize: vertical; }

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-inline input { width: auto; margin: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.98); }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); border: 1px solid rgba(237, 66, 69, 0.3); }
.btn-success { background: var(--green-soft); color: var(--green); border: 1px solid rgba(59, 165, 93, 0.3); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }

/* Tickets */
.ticket-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ticket-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.ticket-card:hover {
  border-color: rgba(88, 101, 242, 0.4);
  background: var(--surface-2);
}

.ticket-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.ticket-card h3 { font-size: 1rem; font-weight: 600; }

.ticket-meta {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge.open { background: var(--green-soft); color: var(--green); }
.badge.closed { background: var(--red-soft); color: var(--red); }

/* Detail */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.message-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
}

.msg {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border-left: 3px solid var(--border);
}

.msg.dm { border-left-color: var(--green); }
.msg.staff { border-left-color: var(--accent); }

.msg-meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 6px; }
.msg-content { white-space: pre-wrap; word-break: break-word; font-size: 0.92rem; }
.msg-att img { max-width: 100%; max-height: 240px; border-radius: 8px; margin-top: 8px; }
.msg.msg-deleted { opacity: 0.65; border-left-color: var(--red, #ed4245); }
.msg.msg-edited { border-left-width: 4px; }
.msg-content.deleted { text-decoration: line-through; opacity: 0.75; }
.msg-badge { font-size: 0.68rem; padding: 2px 6px; border-radius: 4px; margin-left: 6px; vertical-align: middle; }
.msg-badge.deleted { background: #ed4245; color: #fff; }
.msg-badge.edited { background: #f0b232; color: #1e1f22; }
.edit-history { margin-top: 8px; font-size: 0.82rem; color: var(--muted); }
.edit-history ul { margin: 6px 0 0 16px; padding: 0; }
.event-meta { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

/* Table */
.table-wrap {
  overflow-x: auto;
  margin-top: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.data-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

/* Perm list */
.perm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.effect-tag {
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.effect-tag.allow { background: var(--accent-soft); color: #aab0ff; }
.effect-tag.bypass { background: var(--green-soft); color: var(--green); }
.effect-tag.deny { background: var(--red-soft); color: var(--red); }

.muted-tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

/* Autocomplete Discord */
.autocomplete-wrap {
  position: relative;
  width: 100%;
}

.autocomplete-wrap .ac-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.autocomplete-wrap .ac-input.hidden {
  display: none;
}

.ac-dropdown {
  position: absolute;
  z-index: 200;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ac-item:hover {
  background: var(--accent-soft);
}

.ac-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ac-avatar-ph {
  display: grid;
  place-items: center;
  background: var(--surface);
  font-size: 1rem;
}

.ac-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ac-item-text strong {
  font-size: 0.9rem;
}

.ac-item-text small {
  font-size: 0.75rem;
  color: var(--muted);
}

.ac-empty {
  padding: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.ac-selected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.ac-chip {
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ac-chip code {
  font-size: 0.75rem;
  color: var(--muted);
}

.ac-chip-type {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  padding: 2px 6px;
  background: var(--accent-soft);
  border-radius: 4px;
}

.ac-clear {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.ac-clear:hover {
  color: var(--text);
}

.search-input {
  flex: 1;
  min-width: 200px;
  max-width: 400px;
  padding: 10px 14px 10px 36px;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b919a' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.1a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E") no-repeat 12px center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.alert-error { background: var(--red-soft); color: var(--red); border: 1px solid rgba(237, 66, 69, 0.3); }
.alert-success { background: var(--green-soft); color: var(--green); border: 1px solid rgba(59, 165, 93, 0.3); }

/* Toast */
.toast-host {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: slideIn 0.25s ease;
}

.toast.error { border-color: rgba(237, 66, 69, 0.5); }
.toast.success { border-color: rgba(59, 165, 93, 0.5); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal */
.modal-host {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 9000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(480px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 { margin-bottom: 16px; }

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

@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 8px;
    z-index: 100;
  }
  .sidebar-brand, .sidebar-user, .nav-label { display: none; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; }
  .nav-item { white-space: nowrap; font-size: 0.8rem; padding: 8px 10px; }
  .main { padding-bottom: 80px; }
}
