:root {
  --bg: #f3f5fb;
  --bg-accent: #eaf0fe;
  --card: #ffffff;
  --border: #e4e8f0;
  --border-strong: #d5dce8;
  --text: #1a2233;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-darker: #1e40af;
  --primary-soft: #eef4ff;
  --primary-soft-2: #dbe7ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(30, 64, 175, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px rgba(30, 64, 175, 0.12), 0 4px 8px rgba(15, 23, 42, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--bg-accent) 0%, var(--bg) 220px);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
header.topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 30;
}

header.topbar h1 {
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

header.topbar a.admin-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.2s;
}
header.topbar a.admin-link:hover { color: var(--primary); }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

/* ---------- Hero (home) ---------- */
.hero {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 26px;
}
.hero-icon {
  flex: none;
  width: 60px;
  height: 60px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-darker) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
}
.hero-icon svg { width: 30px; height: 30px; }
.hero-text h2 {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.hero-text p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Search ---------- */
.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

input, select, textarea {
  font: inherit;
  padding: 10px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

.search-row input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding-left: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 13px center;
}

/* ---------- Device (category) grid ---------- */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}
.cat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.cat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-soft-2);
}
.cat-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.cat-card-head { display: flex; align-items: flex-start; gap: 16px; }
.cat-info { flex: 1; min-width: 0; }
.cat-info h3 { margin: 0 0 6px; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
.cat-desc { margin: 0; font-size: 13.5px; line-height: 1.55; color: #475569; }
.cat-photo {
  flex: none;
  width: 92px;
  height: 72px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.cat-photo img { width: 100%; height: 100%; object-fit: cover; }
.cat-photo svg { width: 34px; height: 34px; }
.cat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.cat-count { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.cat-go {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--primary);
}
.cat-go svg { transition: transform 0.2s; }
.cat-card:hover .cat-go svg { transform: translateX(3px); }

/* ---------- Model detail ---------- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 6px 0;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.18s;
}
.back-btn:hover { color: var(--primary); }
.detail-head {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}
.detail-photo {
  flex: none;
  width: 104px;
  height: 82px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.detail-photo svg { width: 38px; height: 38px; }
.detail-title h2 { margin: 0 0 4px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.detail-title p { margin: 0 0 6px; color: var(--muted); font-size: 14px; }

/* ---------- Package grid (home) ---------- */
.pkg-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}

.pkg-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.pkg-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-soft-2);
}

.pkg-card-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.pkg-thumb {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
}
.pkg-thumb svg { width: 24px; height: 24px; }
.pkg-thumb.has-img { background: #fff; border: 1px solid var(--border); padding: 4px; }
.pkg-thumb.has-img img { width: 100%; height: 100%; object-fit: contain; border-radius: 8px; }

.pkg-info { flex: 1; min-width: 0; }
.pkg-info h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.pkg-version {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 6px;
  padding: 2px 7px;
}
.pkg-cat {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 6px;
  padding: 3px 9px;
}
.pkg-desc {
  font-size: 13.5px;
  line-height: 1.6;
  color: #475569;
  flex: 1;
}
.pkg-foot {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}
.pkg-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.pkg-meta span { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.18s, box-shadow 0.18s, transform 0.1s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}
.btn.secondary:hover { background: var(--primary-soft); border-color: var(--primary); box-shadow: none; }
.btn.danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #f0c8c8;
  box-shadow: none;
}
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); box-shadow: none; }
.btn:disabled,
.btn[aria-disabled="true"] {
  background: #e5e9f0;
  color: #94a3b8;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 56px 0;
  font-size: 14px;
}

/* ---------- Admin: login ---------- */
.login-box {
  max-width: 380px;
  margin: 8vh auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 34px 32px;
  box-shadow: var(--shadow-lg);
}
.login-box h2 { margin: 0 0 20px; font-size: 21px; font-weight: 700; }
.field {
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label { font-size: 13px; font-weight: 500; color: var(--muted); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 4px; }

/* ---------- Admin: layout ---------- */
.admin-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.admin-tab {
  padding: 11px 18px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.18s, border-color 0.18s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active {
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 650;
}

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border-strong);
}
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: #f8fafc; }
td input { padding: 7px 10px; width: 100%; }
td .btn { padding: 6px 12px; font-size: 12.5px; }
td .btn + .btn { margin-left: 6px; }

.photo-cell { display: flex; align-items: center; gap: 10px; }
.cat-thumb {
  width: 56px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex: none;
}
.cat-thumb.empty {
  display: grid;
  place-items: center;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}
.photo-upload { cursor: pointer; }

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 12px;
}
.form-row .field { margin-bottom: 0; min-width: 160px; flex: 1; }
.form-row .btn { flex: none; }

.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 8px 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #101828;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.22s, transform 0.22s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  main { padding: 20px 16px 40px; }
  header.topbar { padding: 12px 16px; }
  .hero-text h2 { font-size: 20px; }
  .pkg-list, .cat-grid { grid-template-columns: 1fr; }
  .detail-head { gap: 14px; }
  .detail-photo { width: 84px; height: 66px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .pkg-card:hover { transform: none; }
}
