:root {
  --admin-red: #8b1720;
  --admin-red-dark: #6f1118;
  --admin-gold: #b99042;
  --admin-ink: #20242c;
  --admin-muted: #69707d;
  --admin-line: #e5e7eb;
  --admin-soft: #f5f6f8;
  --admin-white: #ffffff;
  --admin-green: #287a52;
  --admin-danger: #b4232c;
  --sidebar-width: 232px;
}

* { box-sizing: border-box; }
html { background: var(--admin-soft); }
body {
  margin: 0;
  color: var(--admin-ink);
  background: var(--admin-soft);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    linear-gradient(135deg, rgb(139 23 32 / 10%), transparent 38%),
    linear-gradient(315deg, rgb(185 144 66 / 14%), transparent 42%),
    #f4f5f7;
}
.login-card {
  width: min(100%, 390px);
  border: 1px solid var(--admin-line);
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  box-shadow: 0 18px 48px rgb(24 28 38 / 12%);
}
.login-brand { display: flex; align-items: center; gap: 11px; }
.login-brand img { width: 40px; height: 40px; border-radius: 7px; object-fit: cover; }
.login-brand strong, .login-brand small { display: block; }
.login-brand strong { color: var(--admin-red); font-size: 16px; }
.login-brand small { margin-top: 2px; color: var(--admin-muted); font-size: 11px; }
.login-heading { margin: 30px 0 20px; }
.login-heading p, .login-heading h1 { margin: 0; }
.login-heading p { color: var(--admin-gold); font-size: 12px; font-weight: 700; }
.login-heading h1 { margin-top: 7px; font-size: 24px; line-height: 1.25; }
.login-fields { display: grid; gap: 14px; }
.login-fields .field { gap: 8px; }
.login-fields .field span { color: #4c525c; font-size: 12px; font-weight: 650; }
.login-error {
  margin: 14px 0 0;
  border: 1px solid #efc4c7;
  border-radius: 7px;
  padding: 10px 11px;
  color: var(--admin-danger);
  background: #fff6f6;
  font-size: 12px;
  line-height: 1.5;
}
.login-submit { width: 100%; margin-top: 18px; }

.admin-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  padding: 22px 16px 18px;
  color: #fff;
  background: #262329;
  border-right: 1px solid rgb(255 255 255 / 8%);
}
.admin-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; border-bottom: 1px solid rgb(255 255 255 / 10%); }
.admin-brand img { width: 38px; height: 38px; border-radius: 7px; object-fit: cover; }
.admin-brand span { min-width: 0; }
.admin-brand strong, .admin-brand small { display: block; }
.admin-brand strong { color: #f4d690; font-size: 16px; }
.admin-brand small { margin-top: 2px; color: rgb(255 255 255 / 54%); font-size: 11px; }
.admin-nav { display: grid; gap: 5px; margin-top: 22px; }
.admin-nav button {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 43px;
  border: 0;
  border-radius: 7px;
  padding: 0 12px;
  color: rgb(255 255 255 / 67%);
  background: transparent;
  text-align: left;
  font-size: 14px;
  transition: color .18s, background .18s;
}
.admin-nav button span { display: grid; place-items: center; width: 23px; height: 23px; border: 1px solid rgb(255 255 255 / 16%); border-radius: 5px; font-size: 11px; }
.admin-nav button:hover { color: #fff; background: rgb(255 255 255 / 7%); }
.admin-nav button.active { color: #fff; background: var(--admin-red); }
.admin-nav button.active span { border-color: rgb(255 255 255 / 30%); background: rgb(255 255 255 / 10%); }
.store-link { display: flex; align-items: center; justify-content: space-between; margin-top: auto; border-top: 1px solid rgb(255 255 255 / 10%); padding: 18px 10px 2px; color: rgb(255 255 255 / 66%); font-size: 13px; }
.store-link:hover { color: #fff; }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px 30px;
  border-bottom: 1px solid var(--admin-line);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(12px);
}
.topbar p, .topbar h1 { margin: 0; }
.topbar p { color: var(--admin-muted); font-size: 11px; }
.topbar h1 { margin-top: 3px; font-size: 20px; line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.connection-status { display: inline-flex; align-items: center; gap: 7px; color: var(--admin-muted); font-size: 12px; }
.connection-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--admin-green); box-shadow: 0 0 0 3px rgb(40 122 82 / 12%); }
.connection-status.offline i { background: var(--admin-danger); }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--admin-line); border-radius: 7px; color: var(--admin-muted); background: #fff; font-size: 20px; line-height: 1; }
.icon-button:hover { color: var(--admin-red); border-color: #d5b3b6; }
.view { width: min(100%, 1480px); padding: 26px 30px 50px; }

.loading-state, .empty-state { display: grid; place-items: center; min-height: 360px; color: var(--admin-muted); text-align: center; }
.loading-state span { width: 30px; height: 30px; border: 3px solid #ddd; border-top-color: var(--admin-red); border-radius: 50%; animation: spin .8s linear infinite; }
.loading-state p { margin: 14px 0 0; font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.summary-card { min-height: 128px; border: 1px solid var(--admin-line); border-radius: 8px; padding: 20px; background: #fff; }
.summary-card header { display: flex; align-items: center; justify-content: space-between; color: var(--admin-muted); font-size: 13px; }
.summary-card header span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; color: var(--admin-red); background: #f7e9ea; font-weight: 700; }
.summary-card strong { display: block; margin-top: 15px; font-size: 29px; line-height: 1; }
.summary-card small { display: block; margin-top: 9px; color: #9096a1; font-size: 11px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(300px, .8fr); gap: 15px; margin-top: 15px; }
.panel { border: 1px solid var(--admin-line); border-radius: 8px; background: #fff; }
.panel-header { display: flex; align-items: center; justify-content: space-between; min-height: 58px; padding: 13px 18px; border-bottom: 1px solid var(--admin-line); }
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-header p { margin: 4px 0 0; color: var(--admin-muted); font-size: 11px; }
.panel-body { padding: 18px; }
.category-bars { display: grid; gap: 15px; }
.category-bar header { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 7px; font-size: 12px; }
.category-bar header span:last-child { color: var(--admin-muted); }
.category-bar div { height: 6px; overflow: hidden; border-radius: 4px; background: #eceef1; }
.category-bar i { display: block; height: 100%; border-radius: inherit; background: var(--admin-red); }
.quick-actions { display: grid; gap: 9px; }
.quick-actions button { display: flex; align-items: center; justify-content: space-between; min-height: 44px; border: 1px solid var(--admin-line); border-radius: 7px; padding: 0 13px; color: var(--admin-ink); background: #fff; text-align: left; font-size: 13px; }
.quick-actions button:hover { border-color: #cfaaad; color: var(--admin-red); background: #fffafa; }

.content-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.toolbar-filters { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.search-field { position: relative; }
.search-field input { width: 260px; padding-left: 34px; }
.search-field span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9ca3af; }
.control, input.control, select.control, textarea.control {
  width: 100%;
  max-width: 100%;
  min-height: 38px;
  border: 1px solid #d9dce1;
  border-radius: 7px;
  padding: 8px 11px;
  color: var(--admin-ink);
  background: #fff;
  outline: none;
  font-size: 13px;
}
.control:focus { border-color: var(--admin-red); box-shadow: 0 0 0 3px rgb(139 23 32 / 9%); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; border: 1px solid transparent; border-radius: 7px; padding: 0 15px; font-size: 13px; font-weight: 650; }
.button.primary { color: #fff; background: var(--admin-red); }
.button.primary:hover { background: var(--admin-red-dark); }
.button.secondary { border-color: var(--admin-line); color: var(--admin-ink); background: #fff; }
.button.secondary:hover { border-color: #c7cbd1; background: #fafafa; }
.button.danger { color: #fff; background: var(--admin-danger); }
.button:disabled { opacity: .55; cursor: not-allowed; }
.logout-button { min-height: 34px; padding: 0 12px; }
.text-button { border: 0; padding: 4px 5px; color: var(--admin-red); background: transparent; font-size: 12px; }
.text-button:hover { text-decoration: underline; }
.text-button.danger { color: var(--admin-danger); }

.table-wrap { overflow-x: auto; border: 1px solid var(--admin-line); border-radius: 8px; background: #fff; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table th { height: 42px; padding: 0 14px; color: var(--admin-muted); background: #fafafa; text-align: left; font-size: 11px; font-weight: 650; }
.data-table td { height: 61px; border-top: 1px solid #eef0f2; padding: 8px 14px; font-size: 12px; vertical-align: middle; }
.data-table tr:hover td { background: #fffdfd; }
.data-table .cell-main { display: flex; align-items: center; gap: 11px; min-width: 230px; white-space: normal; }
.cell-main img { flex: 0 0 auto; width: 42px; height: 42px; border: 1px solid #eee; border-radius: 6px; object-fit: cover; background: #f3f4f6; }
.cell-main strong, .cell-main small { display: block; }
.cell-main strong { max-width: 310px; line-height: 1.4; }
.cell-main small { margin-top: 3px; color: var(--admin-muted); }
.tag { display: inline-flex; align-items: center; min-height: 23px; border-radius: 5px; padding: 0 8px; color: #654b12; background: #f8f0dc; font-size: 11px; }
.tag.red { color: var(--admin-red); background: #f7e9ea; }
.table-actions { display: flex; justify-content: flex-end; gap: 5px; }
.table-footer { display: flex; align-items: center; justify-content: space-between; padding: 13px 4px 0; color: var(--admin-muted); font-size: 12px; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.settings-grid .panel:first-child { grid-column: span 2; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field { display: grid; min-width: 0; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #4c525c; font-size: 12px; font-weight: 650; }
.field small { color: #8b919b; font-size: 11px; line-height: 1.5; }
.field textarea { min-height: 96px; resize: vertical; }
.field textarea.news-content-editor { min-height: 240px; line-height: 1.7; }
.pricing-rule { display: flex; align-items: baseline; gap: 10px; border-left: 3px solid var(--admin-red); padding: 10px 12px; color: #4c525c; background: #faf6f6; font-size: 12px; }
.pricing-rule strong { color: var(--admin-red); }
.pricing-rule span { color: var(--admin-muted); }
.admin-tier-price { display: grid; gap: 2px; white-space: nowrap; }
.admin-tier-price span { color: var(--admin-muted); font-size: 10px; }
.admin-tier-price strong { color: var(--admin-red); }
.checkbox-field { display: flex; align-items: center; gap: 8px; min-height: 38px; font-size: 13px; }
.checkbox-field input { width: 16px; height: 16px; accent-color: var(--admin-red); }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--admin-line); }
.image-preview { display: flex; align-items: center; gap: 11px; }
.image-preview img { width: 58px; height: 58px; border: 1px solid var(--admin-line); border-radius: 7px; object-fit: cover; background: #f3f4f6; }
.image-preview div { display: grid; gap: 6px; }
.upload-label { display: inline-flex; align-items: center; width: max-content; min-height: 31px; border: 1px solid var(--admin-line); border-radius: 6px; padding: 0 10px; background: #fff; font-size: 11px; cursor: pointer; }
.upload-label input { display: none; }

.module-stack { display: grid; gap: 15px; }
.repeat-list { display: grid; gap: 9px; }
.repeat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 34px; gap: 9px; align-items: end; border: 1px solid #eceef1; border-radius: 7px; padding: 11px; background: #fcfcfd; }
.repeat-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)) 34px; }
.repeat-row .icon-button { width: 34px; height: 38px; color: var(--admin-danger); }
.nav-row { display: grid; grid-template-columns: 42px 1fr 1.6fr 120px 140px 42px; gap: 9px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eef0f2; }
.nav-row:last-child { border-bottom: 0; }
.nav-order { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.nav-order button { width: 20px; height: 28px; border: 0; color: var(--admin-muted); background: transparent; }
.nav-order button:hover { color: var(--admin-red); }

.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 11px; }
.asset-card { overflow: hidden; border: 1px solid var(--admin-line); border-radius: 7px; background: #fff; }
.asset-card img { width: 100%; aspect-ratio: 1.25; object-fit: cover; background: #f3f4f6; }
.asset-card div { padding: 10px; }
.asset-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.asset-card small { display: block; margin-top: 5px; color: var(--admin-muted); font-size: 10px; }

.drawer { width: min(560px, 100vw); max-width: none; height: 100vh; max-height: none; margin: 0 0 0 auto; border: 0; padding: 0; color: var(--admin-ink); background: #fff; }
.drawer::backdrop, .confirm-dialog::backdrop { background: rgb(20 20 24 / 52%); backdrop-filter: blur(2px); }
.drawer[open] { animation: slide-in .2s ease-out; }
@keyframes slide-in { from { transform: translateX(35px); opacity: .65; } }
.drawer-shell { display: grid; grid-template-rows: auto 1fr auto; height: 100%; }
.drawer-shell > header { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 15px 20px; border-bottom: 1px solid var(--admin-line); }
.drawer-shell > header p, .drawer-shell > header h2 { margin: 0; }
.drawer-shell > header p { color: var(--admin-muted); font-size: 11px; }
.drawer-shell > header h2 { margin-top: 3px; font-size: 19px; }
.drawer-body { overflow-y: auto; padding: 21px 20px 32px; }
.drawer-shell > footer { display: flex; justify-content: flex-end; gap: 9px; min-height: 66px; padding: 13px 20px; border-top: 1px solid var(--admin-line); background: #fafafa; }
.drawer-body .form-grid { grid-template-columns: 1fr 1fr; }

.confirm-dialog { border: 0; border-radius: 8px; padding: 0; }
.confirm-card { width: min(390px, calc(100vw - 32px)); padding: 27px; text-align: center; }
.danger-mark { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 auto; border-radius: 50%; color: var(--admin-danger); background: #fdebed; font-size: 22px; font-weight: 800; }
.confirm-card h2 { margin: 14px 0 7px; font-size: 18px; }
.confirm-card p { margin: 0; color: var(--admin-muted); font-size: 13px; line-height: 1.6; }
.confirm-card > div { display: flex; justify-content: center; gap: 9px; margin-top: 21px; }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 380px; border: 1px solid #d7dae0; border-left: 4px solid var(--admin-green); border-radius: 7px; padding: 12px 14px; background: #fff; box-shadow: 0 12px 30px rgb(25 30 40 / 18%); font-size: 12px; animation: toast-in .2s ease-out; }
.toast.error { border-left-color: var(--admin-danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.error-panel { border: 1px solid #efc4c7; border-radius: 8px; padding: 20px; color: var(--admin-danger); background: #fff6f6; }
.error-panel h2 { margin: 0 0 7px; font-size: 16px; }
.error-panel p { margin: 0 0 14px; font-size: 13px; }

@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar { position: static; width: 100%; height: auto; padding: 12px; }
  .admin-brand { border: 0; padding: 0 4px 12px; }
  .admin-brand small, .store-link { display: none; }
  .admin-nav { display: flex; overflow-x: auto; margin: 0; padding-bottom: 2px; }
  .admin-nav button { flex: 0 0 auto; min-height: 38px; padding: 0 11px; }
  .admin-nav button span { display: none; }
  .workspace { margin-left: 0; }
  .topbar { top: 0; padding: 10px 18px; }
  .view { padding: 20px 18px 40px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .panel:first-child { grid-column: auto; }
}

@media (max-width: 620px) {
  .connection-status { display: none; }
  .login-card { padding: 22px; }
  .login-heading h1 { font-size: 21px; }
  .logout-button { padding: 0 10px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .summary-card { min-height: 112px; padding: 14px; }
  .summary-card strong { font-size: 25px; }
  .content-toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-filters { display: grid; grid-template-columns: 1fr; }
  .search-field input, .toolbar-filters .control { width: 100%; }
  .content-toolbar > .button { width: 100%; }
  .form-grid, .drawer-body .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .repeat-row, .repeat-row.two { grid-template-columns: 1fr; }
  .repeat-row .icon-button { width: 100%; }
  .nav-row { grid-template-columns: 38px 1fr 38px; }
  .nav-row .control { grid-column: 2 / 3; }
  .nav-row > .icon-button { grid-column: 3; grid-row: 1; }
  .drawer { width: 100vw; }
  .toast-region { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
}
