/* ============================================================
   CadBlock Cloud — Admin Console
   Design: Pinguo Apple — same tokens as web, dark sidebar
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600;9..40,700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --brand-500: #007aff;
  --brand-600: #0064d6;
  --brand-50:  #e8f2ff;

  --bg-0:  #ffffff;
  --bg-1:  #f7f7fa;
  --bg-2:  #f5f5f7;
  --bg-3:  #ececef;
  --bg-4:  #d1d1d6;
  --bg-6:  #8e8e93;
  --bg-7:  #3a3a3c;
  --bg-8:  #1c1c1e;
  --bg-9:  #000000;

  --ink-1: #1d1d1f;
  --ink-2: #48484a;
  --ink-3: #6e6e73;
  --ink-4: #8e8e93;
  --ink-5: #aeaeb2;

  --green: #34c759;
  --red:   #ff3b30;

  --font-sans: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;

  --radius: 1.2rem;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05), 0 1px 3px -1px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 8px -2px rgba(0,0,0,0.06), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 24px -8px rgba(0,0,0,0.08);
  --shadow-xl: 0 16px 40px -10px rgba(0,0,0,0.10);

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --t-fast: 150ms;
  --t-med:  250ms;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  color: var(--ink-1);
  background: var(--bg-1);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-500); text-decoration: none; }
a:hover { opacity: 0.72; }
button, input, select, textarea {
  font: inherit; color: inherit; margin: 0; padding: 0; border: 0; background: none; outline: 0;
}
button { cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--ink-4); }
ul, ol { list-style: none; padding: 0; margin: 0; }
h1, h2, h3, h4, h5, h6, p { margin: 0; }
img, svg { display: block; max-width: 100%; }

/* ---- Login page ---- */
.login-page {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-9);
  padding: 24px;
}
.login-card {
  background: var(--bg-0);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-xl);
}
.login-card h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--ink-1);
  margin-bottom: 6px;
}
.login-card h1 em { font-style: normal; color: var(--brand-500); }
.login-card .muted {
  color: var(--ink-3);
  font-size: 14px;
  letter-spacing: -0.01em;
  margin-bottom: 24px;
}
.login-card .field { margin-bottom: 12px; }
.login-card .field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}
.login-card .field input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font-size: 15px;
  letter-spacing: -0.01em;
  background: var(--bg-0);
  color: var(--ink-1);
  border: 1px solid var(--border, var(--bg-4));
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.login-card .field input:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}
.login-card .msg {
  color: var(--red);
  font-size: 12.5px;
  min-height: 18px;
  margin: 4px 0 0;
}
.login-card button[type=submit] {
  width: 100%;
  height: 44px;
  margin-top: 6px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: var(--brand-500);
  border-radius: var(--r-pill);
  transition: filter var(--t-fast) var(--ease);
}
.login-card button[type=submit]:hover { filter: brightness(0.96); }

/* ---- Admin layout: dark sidebar + light main ---- */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-9);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--bg-8);
}
.sidebar-brand svg { width: 18px; height: 18px; color: #fff; }
.sidebar-brand-text {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.sidebar-brand-text small {
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--ink-4);
  font-family: var(--font-mono);
}
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 12px;
  font-size: 13.5px;
  font-weight: 400;
  letter-spacing: -0.005em;
  color: var(--ink-4);
  border-radius: var(--r-md);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  cursor: pointer;
}
.nav-item:hover { background: var(--bg-8); color: #fff; }
.nav-item.active {
  background: var(--bg-8);
  color: #fff;
  font-weight: 500;
}
.nav-item svg { color: inherit; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--bg-8);
}
.sidebar-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--ink-4);
}
.sidebar-footer-row strong { color: #fff; font-weight: 500; }
.btn-link {
  font-size: 12px;
  color: var(--brand-500);
  background: transparent;
  transition: opacity var(--t-fast) var(--ease);
}
.btn-link:hover { opacity: 0.72; }

/* Content */
.content {
  flex: 1;
  min-width: 0;
  background: var(--bg-1);
  padding: 36px 40px 80px;
}
@media (max-width: 800px) { .content { padding: 24px 20px 60px; } }

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.022em;
  line-height: 1.1;
  color: var(--ink-1);
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stat-grid { grid-template-columns: 1fr; } }
.stat-card {
  padding: 22px 22px 24px;
  background: var(--bg-0);
  border: 1px solid var(--bg-3);
  border-radius: var(--radius);
}
.stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-family: var(--font-sans);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar input,
.toolbar select {
  height: 36px;
  padding: 0 14px;
  font-size: 13.5px;
  letter-spacing: -0.005em;
  color: var(--ink-1);
  background: var(--bg-0);
  border: 1px solid var(--bg-3);
  border-radius: var(--r-pill);
  min-width: 200px;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}
.toolbar select { min-width: 140px; }

/* Buttons (admin variants) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  background: var(--bg-0);
  color: var(--ink-1);
  border: 1px solid var(--bg-3);
  border-radius: var(--r-pill);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.005em;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--bg-2); }
.btn.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn.btn-bronze,
.btn.btn-primary {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}
.btn.btn-bronze:hover,
.btn.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); filter: none; }
.btn.btn-highlight { background: var(--brand-500); color: #fff; border-color: var(--brand-500); }
.btn.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.btn-danger:hover { background: #d62f25; }

/* Data tables */
.form-card {
  background: var(--bg-0);
  border: 1px solid var(--bg-3);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 560px;
}
.table-wrap {
  background: var(--bg-0);
  border: 1px solid var(--bg-3);
  border-radius: var(--radius);
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  letter-spacing: -0.005em;
}
.data-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 12px 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--bg-3);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--bg-3);
  color: var(--ink-1);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--bg-1); }
.cell-name { font-weight: 500; color: var(--ink-1); }
.row-with-thumb { display: flex; align-items: center; gap: 12px; }
.thumb {
  width: 44px; height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
}
.thumb-empty {
  display: grid; place-items: center;
  color: var(--ink-5);
  font-size: 16px;
}

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--ink-2);
  margin-right: 4px;
}
.tag-success { background: rgba(52,199,89,0.12); color: #1f7a36; }
.tag-danger  { background: rgba(255,59,48,0.10); color: #c12a22; }
.tag-vip     { background: var(--ink-1); color: #fff; }

.text-center { text-align: center; }
.text-muted  { color: var(--ink-3); }
.text-mono   { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
}
.pager button {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-1);
  background: transparent;
  border-radius: var(--r-pill);
  transition: background var(--t-fast) var(--ease);
}
.pager button:hover:not(:disabled) { background: var(--bg-2); }
.pager button.active { background: var(--ink-1); color: #fff; }
.pager button:disabled { color: var(--ink-5); cursor: not-allowed; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0,0,0,0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease);
}
.modal.show { display: flex; opacity: 1; }
.modal-card {
  background: var(--bg-0);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: translateY(8px);
  transition: transform var(--t-med) var(--ease);
}
.modal.show .modal-card { transform: translateY(0); }
.modal-card h3 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink-1);
  margin-bottom: 4px;
}
.modal-card h3 em { font-style: normal; color: var(--brand-500); }
.modal-card p {
  font-size: 13.5px;
  color: var(--ink-3);
  letter-spacing: -0.01em;
  margin-bottom: 18px;
}
.modal-card form { display: flex; flex-direction: column; gap: 10px; }
.modal-card .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-card .field { display: flex; flex-direction: column; gap: 4px; }
.modal-card .field label {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-3);
}
.modal-card .field input,
.modal-card .field select,
.modal-card .field textarea {
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--ink-1);
  background: var(--bg-0);
  border: 1px solid var(--bg-3);
  border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.modal-card .field textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.modal-card .field input:focus,
.modal-card .field select:focus,
.modal-card .field textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
}
.modal-card .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--bg-3);
}

/* Spinner */
.spinner {
  width: 18px; height: 18px;
  border: 1.5px solid var(--bg-3);
  border-top-color: var(--ink-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 10px 20px;
  background: rgba(29,29,31,0.94);
  color: #fff;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mobile collapse: simple stack */
@media (max-width: 800px) {
  .admin-layout { flex-direction: column; }
  .sidebar { position: relative; width: 100%; height: auto; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { flex: 1; min-width: 100px; justify-content: center; }
}
