:root {
  --primary: #378ADD;
  --primary-dark: #0C447C;
  --primary-light: #E6F1FB;
  --border: #E0E0E0;
  --bg: #F5F7FA;
  --card-bg: #FFFFFF;
  --text: #1A1A2E;
  --text-muted: #6C757D;
  --text-light: #ADB5BD;
  --danger: #E24B4A;
  --success: #1D9E75;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --header-h: 56px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.app-header .logo {
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}
.app-header .search-box {
  flex: 1;
  max-width: 360px;
  position: relative;
}
.app-header .search-box input {
  width: 100%;
  height: 34px;
  border: none;
  border-radius: 17px;
  padding: 0 12px 0 34px;
  font-size: 13px;
  background: rgba(255,255,255,0.2);
  color: #fff;
}
.app-header .search-box input::placeholder { color: rgba(255,255,255,0.7); }
.app-header .search-box input:focus { background: #fff; color: var(--text); outline: none; }
.app-header .search-box .icon {
  position: absolute;
  left: 10px;
  top: 8px;
  width: 18px;
  height: 18px;
  opacity: 0.7;
}
.app-header .user-area {
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-header .user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.app-header .btn-logout {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.app-header .btn-logout:hover { background: rgba(255,255,255,0.3); }
.app-header .btn-admin {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 28px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; text-align: center; }
.login-card .sub { color: var(--text-muted); font-size: 13px; text-align: center; margin-bottom: 24px; }
.login-card .field { margin-bottom: 16px; }
.login-card .field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.login-card .field input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.login-card .field input:focus { border-color: var(--primary); outline: none; }
.login-card .btn-login {
  width: 100%;
  height: 44px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.login-card .btn-login:hover { background: var(--primary-dark); }
.login-card .err { color: var(--danger); font-size: 13px; text-align: center; margin-bottom: 12px; }
.login-card .hint { color: var(--text-light); font-size: 12px; text-align: center; margin-top: 16px; }

/* Product Grid */
.page-wrap { padding: 16px; max-width: 1200px; margin: 0 auto; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 600px) { .product-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .product-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1200px) { .product-grid { grid-template-columns: repeat(5, 1fr); } }

.product-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.15s, box-shadow 0.15s;
}
.product-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.product-card .img-wrap {
  width: 100%;
  aspect-ratio: 1;
  background: #F0F0F0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.product-card .img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-card .img-wrap .placeholder { color: var(--text-light); font-size: 12px; }
.product-card .card-body { padding: 8px 10px; text-align: center; }
.product-card .card-code { font-size: 13px; font-weight: 600; color: var(--text); word-break: break-all; }
.product-card .card-name { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Pagination */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.pagination button {
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.pagination button:hover { border-color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; font-size: 13px; }
.breadcrumb a { color: var(--primary); cursor: pointer; text-decoration: none; }
.breadcrumb .sep { color: var(--text-light); }
.breadcrumb .current { color: var(--text-muted); font-weight: 500; }

/* Product Detail */
.detail-header { display: flex; gap: 16px; margin-bottom: 20px; align-items: center; }
.detail-header .detail-img { width: 120px; height: 120px; border-radius: 8px; background: #F0F0F0; overflow: hidden; flex-shrink: 0; }
.detail-header .detail-img img { width: 100%; height: 100%; object-fit: cover; }
.detail-header .detail-info h2 { font-size: 18px; margin-bottom: 4px; }
.detail-header .detail-info .code-tag { font-size: 13px; color: var(--text-muted); }

.section-title { font-size: 15px; font-weight: 600; margin: 20px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title .count { font-size: 13px; color: var(--text-muted); font-weight: 400; }

/* Parts list */
.parts-list { display: flex; flex-direction: column; gap: 12px; }

.part-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.part-card .part-main { display: flex; gap: 12px; padding: 12px; align-items: flex-start; }
.part-card .part-img {
  width: 80px; height: 80px;
  border-radius: 8px; background: #F0F0F0;
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.part-card .part-img img { width: 100%; height: 100%; object-fit: cover; }
.part-card .part-img .placeholder { font-size: 11px; color: var(--text-light); }
.part-card .part-info { flex: 1; min-width: 0; }
.part-card .part-code { font-size: 14px; font-weight: 600; }
.part-card .part-name { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.part-card .part-expand-btn {
  background: var(--primary-light);
  border: none;
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

.part-params {
  border-top: 1px solid var(--border);
  padding: 12px;
  background: #FAFBFC;
}
.part-params .param-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 16px;
}
@media (min-width: 600px) { .part-params .param-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .part-params .param-grid { grid-template-columns: 1fr 1fr 1fr; } }
.part-params .param-item { display: flex; gap: 6px; font-size: 13px; padding: 3px 0; }
.part-params .param-label { color: var(--text-muted); min-width: 50px; flex-shrink: 0; }
.part-params .param-value { color: var(--text); word-break: break-all; }
.part-params .param-empty { color: var(--text-light); font-size: 12px; }

/* Admin */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.admin-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.admin-table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { background: #F5F7FA; padding: 10px 12px; text-align: left; font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--border); }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .row-img { width: 50px; height: 50px; border-radius: 6px; object-fit: cover; }
.admin-table .row-actions { display: flex; gap: 6px; }
.admin-table .btn-sm {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}
.admin-table .btn-sm:hover { border-color: var(--primary); }
.admin-table .btn-sm.danger { color: var(--danger); }
.admin-table .btn-sm.danger:hover { border-color: var(--danger); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn-outline:hover { border-color: var(--primary); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 460px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h3 { font-size: 16px; margin-bottom: 16px; }
.modal-card .field { margin-bottom: 14px; }
.modal-card .field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.modal-card .field input, .modal-card .field select, .modal-card .field textarea {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.modal-card .field textarea { height: auto; padding: 8px 10px; }
.modal-card .field input:focus, .modal-card .field select:focus, .modal-card .field textarea:focus { border-color: var(--primary); outline: none; }
.modal-card .file-input { font-size: 12px; }
.modal-card .file-input input { width: 100%; border: 1px dashed var(--border); padding: 8px; border-radius: 6px; }
.modal-card .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 300;
  animation: toastIn 0.2s;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty .icon { font-size: 36px; margin-bottom: 8px; opacity: 0.4; }

/* Loading */
.loading { text-align: center; padding: 40px; color: var(--text-muted); }

/* Admin layout helpers */
.admin-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 8px; flex-wrap: wrap; }
.admin-bar h3 { font-size: 16px; }
.image-preview { width: 60px; height: 60px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); }

/* Comment badge */
.comment-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 18px;
  height: 18px;
  background: #E24B4A;
  color: #fff;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  z-index: 5;
}
.product-card { position: relative; }
.part-card { position: relative; }
.part-card .part-badge-inline {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #FCEBEB;
  color: #E24B4A;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  margin-left: 6px;
}

/* Comments section */
.comments-section { margin-top: 28px; }
.comments-list { display: flex; flex-direction: column; gap: 12px; }
.comment-item {
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 12px;
}
.comment-item.unread { border-left: 3px solid #E24B4A; }
.comment-item.reply { margin-left: 32px; background: #FAFBFC; }
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.comment-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.comment-username { font-size: 13px; font-weight: 600; }
.comment-time { font-size: 11px; color: var(--text-light); }
.comment-unread-tag {
  font-size: 10px; color: #E24B4A; background: #FCEBEB;
  padding: 1px 6px; border-radius: 8px;
}
.comment-body { font-size: 13px; color: var(--text); line-height: 1.5; word-break: break-all; }
.comment-image { max-width: 200px; max-height: 200px; border-radius: 6px; margin-top: 6px; cursor: pointer; }
.comment-actions { display: flex; gap: 8px; margin-top: 6px; }
.comment-actions button {
  background: none; border: none; color: var(--text-muted);
  font-size: 12px; cursor: pointer; padding: 2px 4px;
}
.comment-actions button:hover { color: var(--primary); }
.comment-actions button.danger:hover { color: var(--danger); }

.comment-form { margin-top: 16px; }
.comment-form textarea {
  width: 100%; min-height: 70px;
  padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; resize: vertical;
  font-family: inherit;
}
.comment-form textarea:focus { border-color: var(--primary); outline: none; }
.comment-form .form-bottom { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.comment-form .file-btn {
  font-size: 12px; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; cursor: pointer;
}
.comment-form .file-btn:hover { border-color: var(--primary); }
.comment-form .file-preview { font-size: 12px; color: var(--text-muted); }
.comment-form .submit-btn {
  background: var(--primary); color: #fff; border: none;
  padding: 8px 20px; border-radius: 6px; font-size: 13px;
  cursor: pointer; font-weight: 500; margin-left: auto;
}
.comment-form .submit-btn:hover { background: var(--primary-dark); }
.comment-form .reply-to {
  background: var(--primary-light); padding: 4px 10px;
  border-radius: 6px; font-size: 12px; color: var(--primary-dark);
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.comment-form .reply-to button { background: none; border: none; cursor: pointer; color: var(--primary); font-size: 14px; }

.comment-image-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.8); display: flex;
  align-items: center; justify-content: center; padding: 20px;
}
.comment-image-modal img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }

/* Settings */
.settings-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 600px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.setting-info { flex: 1; }
.setting-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.setting-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.2s;
}
.toggle-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.stat-item { text-align: center; min-width: 80px; }
.stat-value { font-size: 20px; font-weight: 600; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ICP Footer */
.icp-footer {
  text-align: center;
  padding: 16px 12px 20px;
  font-size: 12px;
  color: var(--text-light);
}
.icp-footer a {
  color: var(--text-light);
  text-decoration: none;
}
.icp-footer a:hover {
  color: var(--text-muted);
}

