:root {
  color-scheme: light;
  --bg: #f1f4f6;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e3a5f;
  --ink: #0f1a1c;
  --muted: #6b7c7a;
  --subtle: #94a3a4;
  --line: #dee6e4;
  --line-light: #edf2f0;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-glow: rgba(37, 99, 235, 0.2);
  --warn: #b85a30;
  --warn-bg: #fef4ed;
  --warn-border: #f7d5c2;
  --danger: #c24141;
  --danger-bg: #fef2f2;
  --danger-border: #f5cdcd;
  --success: #2563eb;
  --success-bg: #eff6ff;
  --success-border: #bfdbfe;
  --shadow-sm: 0 1px 3px rgba(15, 26, 28, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 26, 28, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 26, 28, 0.10);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "SF Mono", "SFMono-Regular", Consolas, "JetBrains Mono", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: var(--transition);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

input, select, textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: var(--surface);
  color: var(--ink);
  transition: var(--transition);
  font-size: 14px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.hidden {
  display: none !important;
}

/* ============ LOGIN ============ */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(37, 99, 235, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(184, 90, 48, 0.05) 0%, transparent 50%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 20px;
  padding: 40px 36px 36px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(222, 230, 228, 0.6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  animation: fadeUp 0.5s ease both;
}

.login-panel h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--ink);
}

.login-panel .eyebrow,
.topbar .eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.login-panel .muted {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-panel .error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

/* ============ BUTTONS ============ */

.primary, .secondary, .ghost, .danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

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

.primary:hover {
  background: var(--primary-strong);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.primary:active {
  transform: translateY(0);
  box-shadow: none;
}

.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
}

.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

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

.ghost:hover {
  color: var(--primary);
  background: rgba(37, 99, 235, 0.06);
  border-color: var(--line);
}

.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1.5px solid var(--danger-border);
}

.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ============ APP LAYOUT ============ */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

/* ============ SIDEBAR ============ */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 14px;
  background: linear-gradient(180deg, #0f172a 0%, #1e3a5f 100%);
  color: #cbd5e1;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px 16px;
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.5px;
}

.brand strong {
  display: block;
  font-size: 15px;
  color: #f1f5f9;
}

.brand small {
  display: block;
  margin-top: 1px;
  color: #64748b;
  font-size: 11px;
  letter-spacing: 0.5px;
}

#navList {
  display: grid;
  gap: 2px;
  flex: 1;
  padding: 8px 0;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -3px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.nav-item span:last-child {
  opacity: 0.5;
  font-size: 16px;
}

.nav-item:hover span:last-child,
.nav-item.active span:last-child {
  opacity: 0.8;
}

#logoutButton {
  margin-top: auto;
  width: 100%;
  color: #64748b;
  font-size: 13px;
  justify-content: center;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 14px 12px 4px;
  border-radius: 0;
}

#logoutButton:hover {
  color: #f87171;
  background: transparent;
}

/* ============ WORKSPACE ============ */

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  background: rgba(241, 244, 246, 0.88);
  border-bottom: 1px solid var(--line-light);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--ink);
}

.topbar .eyebrow {
  font-size: 11px;
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.admin-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 14px;
}

.admin-meta #adminName {
  font-weight: 600;
  color: var(--ink);
}

/* ============ CONTENT ============ */

.content {
  display: grid;
  gap: 20px;
  padding: 28px 32px 48px;
  animation: fadeIn 0.35s ease both;
}

/* ============ SKELETON LOADING ============ */

.skeleton {
  display: grid;
  gap: 18px;
}

.skeleton-row {
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--line-light) 25%, var(--line) 50%, var(--line-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-row:first-child {
  width: 40%;
  height: 24px;
}

.skeleton-row:nth-child(2) {
  width: 70%;
}

.skeleton-row:nth-child(3) {
  width: 55%;
}

.skeleton-row:nth-child(4) {
  width: 85%;
}

.skeleton-row:nth-child(5) {
  width: 30%;
}

.skeleton-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.skeleton-card {
  height: 80px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--line-light) 25%, var(--line) 50%, var(--line-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

/* ============ METRICS ============ */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.metric:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--ink);
}

.metric-alert strong {
  color: var(--warn);
}

/* ============ PANELS ============ */

.panel {
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--line-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.table-panel {
  background: var(--surface);
  border: 1px solid var(--line-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-light);
}

.table-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.table-head .muted {
  font-size: 13px;
  color: var(--subtle);
}

/* ============ TABLE ============ */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-light);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafa;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

td {
  color: var(--ink);
}

tbody tr {
  transition: var(--transition);
}

tbody tr:hover {
  background: #f8fafa;
}

tbody tr:last-child td {
  border-bottom: none;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.clip {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ TAGS ============ */

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-strong);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.2px;
}

.tag[class*="pending"] {
  background: #fef9e7;
  color: #b8860b;
}

.tag[class*="processing"] {
  background: #e8f4fd;
  color: #1d6fa7;
}

.tag[class*="resolved"],
.tag[class*="sent"] {
  background: var(--success-bg);
  color: var(--success);
}

.tag[class*="cancelled"] {
  background: var(--danger-bg);
  color: var(--danger);
}

.tag[class*="vip"],
.tag[class*="premium"] {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
}

.tag-success {
  background: #dcfce7 !important;
  color: #16a34a !important;
}

/* ============ FILTERS ============ */

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  align-items: end;
}

.filters label {
  margin-bottom: 0;
}

/* ============ PAGINATION ============ */

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-top: 1px solid var(--line-light);
  font-size: 13px;
  color: var(--muted);
}

.pagination .secondary {
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
}

/* ============ ROW ACTIONS ============ */

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions .secondary,
.row-actions .danger {
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
}

/* ============ SPLIT LAYOUT ============ */

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.55fr);
  gap: 20px;
}

/* ============ FORM GRID ============ */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

/* ============ JSON BOX ============ */

.json-box {
  max-height: 300px;
  overflow: auto;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #bfdbfe;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}

/* ============ TOAST ============ */

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: 380px;
  padding: 14px 20px;
  border-radius: var(--radius);
  background: #0f1a1c;
  color: #e2e8f0;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(15, 26, 28, 0.2);
  animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  backdrop-filter: blur(8px);
}

.toast.hiding {
  opacity: 0;
  transform: translateX(20px) scale(0.95);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* ============ ANIMATIONS ============ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ============ RESPONSIVE ============ */

@media (max-width: 1024px) {
  .content {
    padding: 24px;
  }
  .topbar {
    padding: 0 24px;
  }
  .split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 14px 12px;
    gap: 2px;
  }

  .brand {
    padding-bottom: 12px;
  }

  #navList {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 4px 0;
  }

  .nav-item {
    font-size: 13px;
    min-height: 34px;
  }

  .nav-item span:last-child {
    display: none;
  }

  .topbar {
    min-height: 64px;
    padding: 0 18px;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .topbar h2 {
    font-size: 18px;
  }

  .content {
    padding: 18px;
    gap: 16px;
  }

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

  .table-panel {
    border-radius: var(--radius-sm);
  }

  .table-head {
    padding: 14px 16px;
  }

  .pagination {
    padding: 12px 16px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .login-panel {
    padding: 28px 24px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
    max-width: none;
  }
}

@media (max-width: 480px) {
  #navList {
    grid-template-columns: 1fr 1fr;
  }

  .topbar .admin-meta {
    width: 100%;
    justify-content: space-between;
  }

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