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

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --sidebar-width: 240px;
  --sidebar-collapsed: 68px;
  --topbar-height: 56px;
  --transition-sidebar: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.18), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.login-card .subtitle {
  margin: 0 0 1.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.form-group input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  width: 100%;
  color: #fff;
  background: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--bg);
}

.alert {
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  border-radius: 6px;
}

.alert-error {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* Admin shell + sidebar */
.admin-body {
  overflow-x: hidden;
}

.admin-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: width var(--transition-sidebar);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border-radius: 8px;
}

.sidebar-title {
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 1;
  transition: opacity var(--transition-sidebar);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-footer {
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  text-decoration: none;
}

.sidebar-link.is-active {
  color: #fff;
  background: rgba(59, 130, 246, 0.2);
}

.sidebar-link-logout:hover {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.12);
}

.sidebar-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}

.sidebar-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar-label {
  font-size: 0.9rem;
  opacity: 1;
  transition: opacity var(--transition-sidebar);
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transform: translateY(-50%);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.sidebar-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.sidebar-toggle svg {
  width: 14px;
  height: 14px;
}

.toggle-icon-expand {
  display: none;
}

.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed);
  overflow: visible;
}

.sidebar-collapsed .sidebar-title,
.sidebar-collapsed .sidebar-label {
  display: none;
}

.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0.85rem 0;
  overflow: visible;
}

.sidebar-collapsed .sidebar-nav {
  align-items: center;
  padding-inline: 0.5rem;
  overflow-x: visible;
}

.sidebar-collapsed .sidebar-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-inline: 0.5rem;
}

.sidebar-collapsed .sidebar-link {
  justify-content: center;
  gap: 0;
  width: 44px;
  min-width: 44px;
  margin-inline: auto;
  padding: 0.55rem;
  overflow: visible;
}

.sidebar-collapsed .sidebar-link.is-active {
  border-radius: 10px;
}

.sidebar-collapsed .toggle-icon-collapse {
  display: none;
}

.sidebar-collapsed .toggle-icon-expand {
  display: block;
}

.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition-sidebar);
}

.sidebar-collapsed .admin-main {
  margin-left: var(--sidebar-collapsed);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: var(--topbar-height);
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.topbar-menu-btn svg {
  width: 20px;
  height: 20px;
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.topbar-user {
  font-size: 0.875rem;
  color: var(--muted);
}

.topbar-username::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 0.5rem;
  background: var(--success);
  border-radius: 50%;
}

.main-content {
  flex: 1;
  padding: 1.5rem;
  max-width: 1100px;
  width: 100%;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-sidebar), width var(--transition-sidebar);
  }

  .admin-main {
    margin-left: 0;
  }

  .sidebar-collapsed .admin-main {
    margin-left: 0;
  }

  .sidebar-mobile-open .sidebar {
    transform: translateX(0);
    width: var(--sidebar-width);
  }

  .sidebar-mobile-open .sidebar-title,
  .sidebar-mobile-open .sidebar-label {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-mobile-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.5);
  }

  .topbar-menu-btn {
    display: flex;
  }

  .sidebar-toggle {
    display: none;
  }
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.welcome-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
}

.welcome-card p {
  margin: 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.stat-box {
  padding: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stat-box .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-box p {
  margin: 0;
}

.stat-box .value {
  margin-top: 0.35rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.hint {
  margin-top: 1.5rem;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

.hint a {
  color: var(--accent);
}

/* Admin pages */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-header .btn-accent {
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
  line-height: 1.25;
  white-space: nowrap;
}

.page-header .btn-accent svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.page-header .btn-accent span {
  white-space: nowrap;
}

.page-heading {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.page-desc {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.page-desc a {
  color: var(--accent);
  text-decoration: none;
}

.page-desc a:hover {
  text-decoration: underline;
}

.card-panel,
.card-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card-table-wrap {
  padding: 0;
  overflow-x: auto;
}

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

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

.data-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 2rem !important;
}

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.inline-form {
  display: inline;
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
  border-radius: 4px;
}

.badge-muted {
  color: var(--muted);
  background: rgba(139, 156, 179, 0.15);
}

.badge-success {
  color: #86efac;
  background: rgba(34, 197, 94, 0.15);
}

.badge-danger {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.15);
}

.btn-accent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: auto;
  color: #fff;
  background: var(--accent);
  border: none;
  text-decoration: none;
}

.btn-accent:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.alert-success {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.admin-form {
  max-width: 480px;
}

.form-row {
  margin-bottom: 1.1rem;
}

.form-row label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.form-row input[type="text"],
.form-row input[type="password"],
.form-row select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.required {
  color: var(--danger);
}

.form-row-check .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 0.5rem;
}

.role-card {
  margin-bottom: 1.25rem;
}

.role-card-header h3 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.role-card-header p {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.perm-group {
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.perm-group legend {
  padding: 0 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.perm-check {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem 0;
  cursor: pointer;
}

.perm-check small {
  color: var(--muted);
  font-size: 0.7rem;
}

.role-legend {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.role-legend li {
  margin: 0.35rem 0;
}

.config-form {
  max-width: 640px;
}

.config-section {
  border: none;
  margin: 0 0 1.75rem;
  padding: 0 0 1rem;
  border-bottom: 1px solid var(--border);
}

.config-section legend {
  font-weight: 600;
  font-size: 1rem;
  padding: 0 0 0.75rem;
  color: var(--text);
}

.config-meta {
  margin-bottom: 1rem;
}

.field-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.field-inline input[type="number"] {
  width: 9rem;
}

.config-key-once {
  display: inline-block;
  padding: 0.35rem 0.6rem;
  background: var(--surface-elevated, #1a1d24);
  border-radius: 4px;
  font-size: 0.95rem;
  word-break: break-all;
}

/* settings.php — collapsible snapshot history */
.config-snapshots {
  padding: 0;
}

.config-snapshots-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 1.25rem 2rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.config-snapshots-summary::-webkit-details-marker {
  display: none;
}

.config-snapshots-summary::before {
  content: "▸ ";
  color: var(--accent);
  font-size: 0.85rem;
}

.config-snapshots[open] > .config-snapshots-summary::before {
  content: "▾ ";
}

.config-snapshots-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.config-snapshots-meta {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
}

.config-snapshots-body {
  padding: 0 2rem 1.5rem;
  border-top: 1px solid var(--border);
}

.config-snapshots-hint {
  margin-top: 1rem;
  margin-bottom: 1rem;
}

.config-subheading {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.config-winmm-global .admin-form {
  max-width: 640px;
}

.data-table-winmm .winmm-cell {
  min-width: 14rem;
  vertical-align: top;
}

.winmm-status {
  margin-bottom: 0.5rem;
}

.winmm-status .hint {
  display: block;
  margin-top: 0.25rem;
  padding: 0;
  border: none;
  background: transparent;
}

.winmm-upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.winmm-file-input {
  max-width: 11rem;
  font-size: 0.8rem;
}

.btn-muted {
  opacity: 0.85;
}
