:root {
  --admin-bg: #f7f7f8;
  --admin-panel: #ffffff;
  --admin-border: #ececef;
  --admin-text: #111214;
  --admin-muted: #60646c;
  --admin-orange: #ff8a00;
  --admin-orange-weak: rgba(255, 138, 0, 0.12);
  --admin-btn-orange: var(--admin-orange);
  --admin-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  --r: 10px;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--admin-bg);
  color: var(--admin-text);
  font-family:
    Inter,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
  /* Keep scroll inside the main content area (tabs). Sidebar + topbar stay fixed. */
  overflow: hidden;
}

.btn {
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--admin-border);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn-primary {
  background: var(--admin-btn-orange);
  border-color: var(--admin-btn-orange);
  color: #fff;
}

.btn-secondary {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--admin-muted);
}

.btn-danger {
  border-color: rgba(237, 21, 21, 0.25);
  background: rgba(237, 21, 21, 0.08);
  color: #b10f0f;
}

.btn-danger:hover {
  border-color: rgba(237, 21, 21, 0.35);
}

.admin-shell {
  display: grid;
  grid-template-columns: 268px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

.admin-topbar {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--admin-panel);
  border-bottom: 1px solid var(--admin-border);
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.topbar-name {
  font-weight: 750;
}

.topbar-right {
  display: flex;
  justify-content: flex-end;
}

.sidebar {
  grid-column: 1;
  grid-row: 1 / -1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px;
  background: var(--admin-panel);
  border-right: 1px solid var(--admin-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 10px;
}

.sidebar-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.sidebar-name {
  font-weight: 750;
  font-size: 13px;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand {
  display: none;
}

.store-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--admin-muted);
}

.store-select {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--admin-border);
  background: #fff;
  font-weight: 600;
  color: var(--admin-text);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%20width%3D%2716%27%20height%3D%2716%27%20viewBox%3D%270%200%2024%2024%27%20fill%3D%27none%27%20stroke%3D%27%2360646c%27%20stroke-width%3D%272%27%20stroke-linecap%3D%27round%27%20stroke-linejoin%3D%27round%27%3E%3Cpolyline%20points%3D%276%209%2012%2015%2018%209%27/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}

.nav-item {
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: transparent;
  font-weight: 650;
  color: var(--admin-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.nav-badge {
  display: inline-flex;
  min-width: 16px;
  height: 16px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--admin-btn-orange);
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.nav-badge[hidden] {
  display: none !important;
}

.nav-item:hover {
  background: #f3f3f6;
}

.nav-item.is-active {
  background: var(--admin-orange-weak);
  border-color: rgba(255, 138, 0, 0.25);
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 0;
  border-top: none;
}

.logout-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  font-weight: 650;
  color: var(--admin-muted);
  text-align: left;
}

.logout-btn:hover {
  color: var(--admin-text);
  background: #f3f3f6;
}

.logout-btn-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.content {
  grid-column: 2;
  grid-row: 2;
  padding: 18px 18px 28px;
  height: calc(100vh - 56px);
  overflow: auto;
  /* Keep layout aligned across tabs (reserve scrollbar space even when not needed). */
  scrollbar-gutter: stable;
}

/* Login: hide shell chrome and center auth card */

body.is-login .admin-shell {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

body.is-login .admin-topbar,
body.is-login .sidebar {
  display: none;
}

body.is-login .content {
  grid-column: 1;
  grid-row: 1;
  height: 100vh;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.page-title {
  display: none;
}

.content-header {
  justify-content: flex-end;
}

.content-header.is-compact {
  margin-bottom: 12px;
}

.content-header.is-compact .page-actions {
  display: none;
}

.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 32px;
}

.page-actions [data-page-actions] {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-actions .switch {
  align-self: center;
}

.page-actions .btn {
  align-self: center;
}

/* Ensure header action slots never align to the top due to default block layout */
[data-page-actions] {
  display: flex;
  align-items: center;
  gap: 10px;
}

[data-page-actions][hidden] {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 750;
}

.page-title:empty {
  display: none;
}

.page-sub {
  display: none;
}

.view {
  display: none;
  gap: 14px;
}

.view.is-active {
  display: grid;
  gap: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.panel {
  background: var(--admin-panel);
  border: 1px solid var(--admin-border);
  border-radius: var(--r);
  box-shadow: var(--admin-shadow);
  padding: 14px;
  overflow: hidden;
}

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

.panel-title {
  margin: 0;
  font-size: 14px;
  font-weight: 750;
  text-transform: none;
}

.panel-meta {
  font-size: 12px;
  color: var(--admin-muted);
  font-weight: 650;
}

.panel-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.admin-tab-header .panel-h {
  margin-bottom: 0;
}

.admin-tab-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.empty {
  color: var(--admin-muted);
  font-weight: 600;
  padding: 12px 0 2px;
}

.panel-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.link {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-weight: 700;
  color: var(--admin-muted);
}

.link:hover {
  color: var(--admin-text);
}

.input {
  padding: 10px 12px;
  border-radius: var(--r);
  border: 1px solid var(--admin-border);
  background: #fff;
  min-width: 240px;
  font-weight: 500;
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: rgba(17, 18, 20, 0.86);
  color: #fff;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 13px;
  box-shadow: var(--admin-shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.toast.is-open {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.admin-popup-x {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--admin-border);
  background: #fff;
  cursor: pointer;
  color: var(--admin-muted);
  font-weight: 800;
  line-height: 1;
  font-size: 18px;
  padding: 0;
}

.admin-popup-x::before {
  content: "×";
}

.admin-popup-x:hover {
  filter: brightness(0.98);
  color: var(--admin-text);
}

.admin-popup-x:focus-visible {
  outline: 2px solid rgba(255, 138, 0, 0.55);
  outline-offset: 2px;
}

.table {
  border: 1px solid var(--admin-border);
  border-radius: var(--r);
  overflow: hidden;
  background: #fff;
}

.t-head,
.t-row {
  display: grid;
  grid-template-columns: 1.6fr 0.8fr 0.9fr 0.7fr;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
}

.t-head {
  background: #f5f5f7;
  border-bottom: 1px solid var(--admin-border);
  color: var(--admin-muted);
  font-weight: 700;
  font-size: 12px;
}

.t-row {
  border-bottom: 1px solid var(--admin-border);
}

.t-row:last-child {
  border-bottom: none;
}

.t-main {
  display: grid;
  gap: 2px;
}

.t-title {
  font-weight: 750;
}

.t-sub {
  font-size: 12px;
  color: var(--admin-muted);
  font-weight: 600;
}

.t-right {
  justify-self: end;
  text-align: right;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  border: 1px solid var(--admin-border);
  background: #fff;
}

.tag-ok {
  border-color: rgba(15, 186, 49, 0.2);
  background: rgba(15, 186, 49, 0.1);
  color: #0b7d22;
}

.tag-muted {
  border-color: rgba(96, 100, 108, 0.22);
  background: rgba(96, 100, 108, 0.08);
  color: #4b4f58;
}

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

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .admin-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
  }

  .admin-topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .topbar-right {
    justify-content: flex-start;
  }

  .sidebar {
    position: relative;
    top: 0;
    height: auto;
    grid-row: auto;
    border-right: none;
    border-bottom: 1px solid var(--admin-border);
  }

  .content {
    padding: 14px;
    height: auto;
    overflow: visible;
  }

  .input {
    min-width: 0;
    width: 100%;
  }

  .t-head,
  .t-row {
    grid-template-columns: 1.6fr 0.9fr 0.7fr;
  }

  .t-head > :nth-child(3),
  .t-row > :nth-child(3) {
    display: none;
  }
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-text {
  flex: 1;
  text-align: left;
}

/* Ensure the close icon renders even if file encoding glitches. */
.admin-popup-x::before {
  content: "\00D7";
}
