:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #eef0f3;
  --accent: #6d4c41;
  --accent-2: #8d6e63;
  --danger: #b42318;
  --warn: #b54708;
  --success: #027a48;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", Arial, "Helvetica Neue", Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 14px;
  border-bottom: 1px solid var(--line-2);
}

.brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(109, 76, 65, 0.18), rgba(141, 110, 99, 0.06));
  border: 1px solid rgba(109, 76, 65, 0.2);
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 800;
  font-size: 20px;
}

.brand-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title strong {
  font-size: 14px;
  letter-spacing: 0.2px;
}

.brand-title span {
  font-size: 12px;
  color: var(--muted);
}

.nav {
  padding: 14px 6px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  color: #2b2f36;
}

.nav a:hover {
  background: #fafafa;
}

.nav a.active {
  background: rgba(109, 76, 65, 0.1);
  border: 1px solid rgba(109, 76, 65, 0.18);
  color: var(--accent);
}

.nav .dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #cbd5e1;
}

.nav a.active .dot {
  background: var(--accent);
}

.sidebar-footer {
  margin-top: 18px;
  padding: 14px 10px 0;
  border-top: 1px solid var(--line-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shop-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.shop-card:hover {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(109, 76, 65, 0.08);
  transform: translateY(-2px);
}

.shop-card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.shop-card .helper {
  font-size: 12px;
  color: var(--muted);
  background: #f5f5f5;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: monospace;
}

.pill {
  padding: 4px 8px;
  border-radius: 99px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.pill.ok {
  border-color: rgba(2, 122, 72, 0.25);
  background: rgba(2, 122, 72, 0.06);
  color: var(--success);
}

.pill.warn {
  border-color: rgba(181, 71, 8, 0.25);
  background: rgba(181, 71, 8, 0.06);
  color: var(--warn);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  color: #2b2f36;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
  transition: all 0.2s ease;
}

.btn:hover {
  background: #fff;
  border-color: rgba(109, 76, 65, 0.4);
  box-shadow: 0 4px 12px rgba(109, 76, 65, 0.08);
  transform: translateY(-1px);
}

.btn.primary {
  border-color: rgba(109, 76, 65, 0.35);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 10px rgba(109, 76, 65, 0.2);
}

.btn.primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(109, 76, 65, 0.3);
}

.btn.danger {
  border-color: rgba(180, 35, 24, 0.35);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.content {
  padding: 24px 24px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.topbar .meta {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

/* Reusable Mixins */
.hover-card-style {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.hover-card-style:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(109, 76, 65, 0.08);
  transform: translateY(-2px);
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.card:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(109, 76, 65, 0.08);
  transform: translateY(-2px);
}

.card-header {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-header h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.card-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.card-body {
  padding: 16px;
}

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

.kpi {
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
  transition: all 0.2s ease;
}

.kpi:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(109, 76, 65, 0.08);
  transform: translateY(-2px);
}

.kpi .label {
  color: var(--muted);
  font-size: 12px;
}

.kpi .value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.kpi .sub {
  font-size: 12px;
  color: var(--muted);
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: #fff;
}

.table th,
.table td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--line-2);
  font-size: 13px;
  text-align: left;
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  background: #fafafa;
}

.table tr:last-child td {
  border-bottom: none;
}

.form {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  gap: 8px;
}

.form-row label {
  font-size: 13px;
  color: #2b2f36;
}

.input,
.select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  outline: none;
}

.input:focus,
.select:focus {
  border-color: rgba(109, 76, 65, 0.35);
  box-shadow: 0 0 0 4px rgba(109, 76, 65, 0.12);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.helper {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.divider {
  height: 1px;
  background: var(--line-2);
  margin: 14px 0;
}

.poster-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.poster {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  min-height: 120px;
  display: grid;
  gap: 12px;
  padding: 16px;
  position: relative;
  /* FLIP Animation */
  transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.3s ease, border-color 0.3s ease;
  transform-origin: center center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  cursor: grab;
}

.poster:hover {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(109, 76, 65, 0.08);
  transform: translateY(-2px);
}

.poster:active {
  cursor: grabbing;
}

.poster.dragging {
  opacity: 0.5;
  transform: scale(0.95);
  border: 2px dashed var(--accent);
}

.poster.moving {
  z-index: 2;
  box-shadow: 0 12px 30px rgba(0,0,0,0.12);
}

.index-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  z-index: 5;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

.poster .preview {
  height: 140px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(109, 76, 65, 0.12), rgba(141, 110, 99, 0.06));
  border: 1px solid rgba(109, 76, 65, 0.1);
  display: grid;
  place-items: center;
  overflow: hidden;
  margin-bottom: 4px;
}

.poster .preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.poster .title {
  font-size: 13px;
  color: #2b2f36;
  font-weight: 600;
}

.poster .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Tooltips */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  margin-bottom: 8px;
  z-index: 10;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #333;
  margin-bottom: -4px;
  z-index: 10;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
}

.seg button {
  border: none;
  background: transparent;
  padding: 10px 12px;
  cursor: pointer;
  color: #2b2f36;
}

.seg button.active {
  background: rgba(109, 76, 65, 0.12);
  color: var(--accent);
  font-weight: 700;
}

.chart {
  height: 220px;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: #fff;
  position: relative;
  overflow: hidden;
}

.chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.login-head {
  display: grid;
  gap: 8px;
  padding: 8px 6px 14px;
  border-bottom: 1px solid var(--line-2);
}

.login-head h1 {
  margin: 0;
  font-size: 18px;
}

.login-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: rgba(31, 35, 40, 0.92);
  color: #fff;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  display: none;
  max-width: 360px;
  z-index: 9999;
}

.toast.show {
  display: block;
}

.toast .title {
  font-weight: 700;
  margin-bottom: 4px;
  font-size: 13px;
}

.toast .desc {
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.5;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  /* Ensure visibility delay matches the modal's longest transition */
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.5s step-end;
  backdrop-filter: blur(4px);
  perspective: 1000px;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s;
}

.modal {
  background: #fff;
  border-radius: 16px;
  width: 92%;
  max-width: 860px; /* Increased width for two-column layout */
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  /* Pure Hero Animation: Match source card scale (~0.3) and position */
  transform: translate3d(var(--tx, 0), var(--ty, 0), 0) scale(var(--ts, 0.3));
  opacity: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  will-change: transform, opacity;
  backface-visibility: hidden;
  contain: content;
  /* Remove transition from base state to prevent animation during initial positioning */
  transition: none;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.modal-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-column.right {
  height: 100%;
  justify-content: space-between;
}

@media (max-width: 768px) {
  .modal-grid {
    grid-template-columns: 1fr;
  }
}

.modal-overlay.open .modal {
  transform: translate3d(0, 0, 0) scale(1);
  opacity: 1;
  /* Apply transition only when opening */
  transition: 
    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
    opacity 0.3s ease-out;
}

/* Specific class for closing animation */
.modal-overlay.closing .modal {
  transform: translate3d(var(--tx, 0), var(--ty, 0), 0) scale(var(--ts, 0.3));
  opacity: 0;
  transition: 
    transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), 
    opacity 0.2s ease-in-out;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  display: grid;
  gap: 16px;
}

.image-preview-area {
  width: 100%;
  height: 160px;
  border-radius: 12px;
  border: 2px dashed var(--line);
  background: #fafafa;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color 0.2s;
}

.image-preview-area:hover {
  border-color: var(--accent);
  background: rgba(109, 76, 65, 0.04);
}

.image-preview-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.image-preview-area.has-image img {
  display: block;
}

.image-preview-area .placeholder {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.image-preview-area.has-image .placeholder {
  display: none;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .poster-grid {
    grid-template-columns: 1fr;
  }
}
