:root {
  color: #172033;
  background: #f5f7fb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Microsoft YaHei', sans-serif;
  font-synthesis: none;
  --primary: #4f46e5;
  --primary-deep: #3730a3;
  --primary-soft: #eef2ff;
  --success: #0f9f6e;
  --danger: #d92d4a;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-muted: #f7f8fc;
  --border: #e1e5ee;
  --muted: #6c758b;
  --shadow: 0 18px 50px rgba(31, 42, 68, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at 10% 0%, rgba(79, 70, 229, 0.1), transparent 28rem),
    radial-gradient(circle at 90% 10%, rgba(14, 165, 233, 0.09), transparent 24rem), #f5f7fb;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(1600px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  overflow: hidden;
  border: 1px solid rgba(216, 221, 232, 0.86);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 92px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(18px);
}

.brand,
.brand > div:last-child,
.header-actions,
.inline-actions,
.title-line,
.pack-admin-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
}

.brand > div:last-child {
  align-items: flex-start;
  flex-direction: column;
  gap: 2px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(145deg, #5e5af0, #3932b5);
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.27);
  font-size: 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(20px, 2vw, 27px);
  letter-spacing: -0.03em;
}

h2 {
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: -0.035em;
}

.eyebrow {
  color: var(--primary);
  font-size: 10px;
  line-height: 1.3;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.header-actions {
  gap: 10px;
}

.stat {
  min-width: 84px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  color: var(--primary-deep);
  font-size: 21px;
}

.button,
.icon-button {
  border: 0;
  border-radius: 11px;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button {
  min-height: 40px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  font-weight: 700;
  font-size: 13px;
}

.button-primary {
  color: white;
  background: linear-gradient(135deg, #5b55ec, #4338ca);
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.2);
}

.button-secondary {
  color: #3d4660;
  border: 1px solid var(--border);
  background: white;
}

.button-success {
  color: white;
  background: var(--success);
}

.button-danger-soft {
  color: var(--danger);
  background: #fff0f3;
}

.button-light {
  color: var(--primary-deep);
  background: white;
}

.button-ghost-light {
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.09);
}

.button-block {
  width: 100%;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #4e5870;
  border: 1px solid var(--border);
  background: white;
  font-size: 20px;
}

.admin-banner {
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: white;
  background: linear-gradient(110deg, #312e81, #4f46e5 55%, #6366f1);
}

.admin-banner > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.admin-banner span {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
}

.inline-actions {
  gap: 8px;
}

.workspace {
  min-height: calc(100vh - 125px);
  display: grid;
  grid-template-columns: 265px minmax(0, 1fr);
}

.sidebar {
  padding: 20px 14px;
  border-right: 1px solid var(--border);
  background: rgba(247, 248, 252, 0.78);
}

.search-box {
  height: 44px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #7b8498;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  transition: border 120ms ease, box-shadow 120ms ease;
}

.search-box:focus-within {
  border-color: rgba(79, 70, 229, 0.55);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: #20283a;
  background: transparent;
}

.sidebar-heading {
  margin: 22px 10px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #9299a9;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.badge,
.count-pill {
  border-radius: 999px;
  color: var(--primary-deep);
  background: var(--primary-soft);
  font-weight: 800;
}

.badge {
  padding: 2px 7px;
  font-size: 10px;
}

.pack-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.pack-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  border-radius: 11px;
}

.pack-row-admin {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.pack-drag-handle {
  width: 24px;
  height: 36px;
  display: grid;
  place-items: center;
  align-self: center;
  color: #a2a9bb;
  border-radius: 7px;
  cursor: grab;
  font-size: 17px;
  user-select: none;
  touch-action: none;
}

.pack-drag-handle:hover,
.pack-drag-handle:focus-visible {
  color: var(--primary);
  outline: 0;
  background: rgba(79, 70, 229, 0.09);
}

.pack-drag-handle:active {
  cursor: grabbing;
}

.pack-row.pack-dragging {
  opacity: 0.42;
}

.pack-row.pack-drop-before::before,
.pack-row.pack-drop-after::after {
  content: '';
  position: absolute;
  z-index: 3;
  right: 5px;
  left: 5px;
  height: 3px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.pack-row.pack-drop-before::before {
  top: -4px;
}

.pack-row.pack-drop-after::after {
  bottom: -4px;
}

.pack-row.active {
  background: #e9eafe;
}

.pack-select {
  min-width: 0;
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: #4c556b;
  border: 0;
  border-radius: 11px;
  background: transparent;
  text-align: left;
}

.pack-select:hover {
  background: rgba(232, 234, 243, 0.75);
}

.pack-row.active .pack-select {
  color: var(--primary-deep);
  font-weight: 750;
}

.pack-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #a8afc0;
}

.pack-row.active .pack-dot {
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
}

.pack-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pack-item-count {
  color: #9198a8;
  font-size: 11px;
}

.pack-order-controls {
  padding-right: 5px;
  display: flex;
  gap: 2px;
}

.mini-button {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: #626c82;
  background: rgba(255, 255, 255, 0.76);
  font-size: 10px;
}

.content {
  min-width: 0;
  padding: 28px;
}

.content-header {
  min-height: 64px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.content-header > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.title-line,
.pack-admin-actions {
  gap: 10px;
}

.count-pill {
  padding: 5px 10px;
  font-size: 11px;
}

.pack-editor,
.upload-options {
  margin-top: 18px;
  padding: 14px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid #dfe1fa;
  border-radius: 14px;
  background: linear-gradient(135deg, #f7f7ff, #f2f6ff);
}

.upload-options {
  align-items: center;
}

.upload-options p {
  max-width: 370px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.upload-button input {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field.grow,
.grow {
  flex: 1;
}

.field label {
  color: #545d73;
  font-size: 12px;
  font-weight: 700;
}

.field input,
.pack-editor input,
.upload-options input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #d7dce8;
  border-radius: 10px;
  outline: 0;
  color: #20283a;
  background: white;
}

.field input:focus,
.pack-editor input:focus,
.upload-options input:focus {
  border-color: rgba(79, 70, 229, 0.65);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.field-error {
  color: var(--danger);
  font-size: 12px;
}

.emoji-grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 12px;
}

.emoji-card {
  position: relative;
  min-width: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: white;
  box-shadow: 0 3px 10px rgba(31, 42, 68, 0.025);
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
}

.emoji-card:hover {
  z-index: 1;
  transform: translateY(-3px);
  border-color: #cdd1fa;
  box-shadow: 0 12px 26px rgba(31, 42, 68, 0.1);
}

.emoji-image-wrap {
  height: 102px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 11px;
  background: linear-gradient(45deg, #f3f4f8 25%, transparent 25%),
    linear-gradient(-45deg, #f3f4f8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f3f4f8 75%),
    linear-gradient(-45deg, transparent 75%, #f3f4f8 75%), #fafbfc;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-size: 12px 12px;
}

.emoji-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.emoji-name {
  overflow: hidden;
  color: #3e475d;
  font-size: 12px;
  font-weight: 650;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emoji-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.emoji-actions button {
  min-width: 0;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: #616b81;
  background: #f8f9fc;
  font-size: 11px;
}

.emoji-actions button[data-action='delete-item'] {
  color: var(--danger);
  background: #fff4f6;
}

.state-panel {
  min-height: 390px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 9px;
  color: var(--muted);
  text-align: center;
}

.state-panel strong {
  color: #414a60;
  font-size: 16px;
}

.state-panel span {
  max-width: 560px;
  font-size: 12px;
  line-height: 1.6;
}

.state-error strong {
  color: var(--danger);
}

.empty-icon {
  color: #b6bdcc;
  font-size: 50px;
}

.spinner {
  width: 25px;
  height: 25px;
  border: 3px solid rgba(79, 70, 229, 0.14);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.dialog {
  width: min(430px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: inherit;
  background: transparent;
  box-shadow: 0 30px 80px rgba(20, 26, 45, 0.24);
}

.dialog::backdrop {
  background: rgba(24, 29, 45, 0.48);
  backdrop-filter: blur(6px);
}

.dialog-card {
  position: relative;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  border-radius: 20px;
  background: white;
}

.dialog-card h2 {
  font-size: 25px;
}

.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  color: #717a8e;
  background: #f1f3f7;
  font-size: 20px;
}

.dialog-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--primary-soft);
  font-size: 23px;
}

.dialog-description {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.edit-preview {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border-radius: 14px;
  background: #f5f6fa;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(245, 247, 251, 0.66);
  backdrop-filter: blur(5px);
}

.busy-card {
  width: min(390px, 100%);
  padding: 24px;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: white;
  box-shadow: var(--shadow);
  text-align: center;
}

.busy-card span {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 120;
  max-width: min(440px, calc(100% - 44px));
  padding: 13px 16px;
  border-radius: 12px;
  color: white;
  background: #26304a;
  box-shadow: 0 15px 40px rgba(31, 42, 68, 0.22);
  font-size: 13px;
  font-weight: 650;
}

.toast.error {
  background: #b4233d;
}

@media (max-width: 800px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .topbar {
    padding: 14px 16px;
  }

  .brand-mark,
  .stat {
    display: none;
  }

  .admin-banner,
  .admin-banner > div:first-child {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-banner {
    padding: 14px 16px;
  }

  .admin-banner > div:first-child {
    gap: 3px;
  }

  .workspace {
    display: block;
  }

  .sidebar {
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-heading {
    margin-top: 14px;
  }

  .pack-list {
    padding-bottom: 2px;
    overflow-x: auto;
    flex-direction: row;
  }

  .pack-row {
    flex: 0 0 auto;
    display: flex;
  }

  .pack-drag-handle {
    display: none;
  }

  .pack-select {
    min-width: 118px;
  }

  .content {
    padding: 20px 16px;
  }

  .content-header,
  .pack-editor,
  .upload-options {
    align-items: stretch;
    flex-direction: column;
  }

  .content-header {
    gap: 13px;
  }

  .pack-admin-actions {
    flex-wrap: wrap;
  }

  .pack-admin-actions .button {
    flex: 1;
  }

  .emoji-grid {
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
    gap: 9px;
  }

  .emoji-card {
    padding: 9px;
  }

  .emoji-image-wrap {
    height: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
