:root {
  --black: #111111;
  --ink: #242424;
  --muted: #707070;
  --soft: #f5f4f1;
  --line: #ded9cf;
  --white: #ffffff;
  --gold: #c9a24a;
  --danger: #9d2d2d;
  --success: #16724b;
  font-family: "Noto Sans Thai", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--soft);
  color: var(--ink);
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-screen {
  align-items: center;
  background: linear-gradient(135deg, #111111, #2d2d2d);
  display: flex;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  background: var(--white);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  margin: 0 auto;
  max-width: 440px;
  padding: 34px;
  width: 100%;
}

.login-brand,
.admin-logo {
  align-items: center;
  display: flex;
  gap: 12px;
}

.login-brand span,
.admin-logo span {
  align-items: center;
  background: var(--black);
  color: var(--gold);
  display: inline-flex;
  font-weight: 800;
  height: 46px;
  justify-content: center;
  width: 46px;
}

.login-brand strong {
  display: block;
  font-size: 1.35rem;
}

.login-brand p {
  color: var(--muted);
  margin: 0;
}

.login-form,
.grid-form,
.upload-form {
  display: grid;
  gap: 16px;
}

.login-form {
  margin-top: 30px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.9rem;
  font-weight: 700;
  gap: 7px;
}

input,
select,
textarea {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  min-height: 44px;
  padding: 10px 12px;
  width: 100%;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  outline: 2px solid rgba(201, 162, 74, 0.18);
}

.login-form button,
.form-actions button,
.upload-form button,
.topbar-actions button,
.topbar-actions a,
.secondary-button,
.table-action {
  align-items: center;
  border: 1px solid transparent;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
}

.login-form button,
.form-actions button,
.upload-form button {
  background: var(--black);
  color: var(--gold);
}

.form-message,
.notice {
  margin: 0;
  min-height: 24px;
}

.notice {
  border: 1px solid var(--line);
  margin-bottom: 18px;
  padding: 12px 14px;
}

.notice.success {
  border-color: rgba(22, 114, 75, 0.35);
  color: var(--success);
}

.notice.error,
.form-message.error {
  color: var(--danger);
}

.admin-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--black);
  color: var(--white);
  padding: 24px 18px;
}

.admin-logo {
  color: var(--white);
  margin-bottom: 28px;
}

.admin-logo span {
  background: var(--gold);
  color: var(--black);
}

.admin-nav {
  display: grid;
  gap: 8px;
}

.admin-nav button {
  background: transparent;
  border: 1px solid transparent;
  color: rgba(255, 255, 255, 0.72);
  min-height: 44px;
  padding: 10px 12px;
  text-align: left;
}

.admin-nav button.active,
.admin-nav button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(201, 162, 74, 0.35);
  color: var(--gold);
}

.admin-main {
  min-width: 0;
  padding: 24px;
}

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

.eyebrow {
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  margin: 0 0 4px;
  text-transform: uppercase;
}

.topbar h1 {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.2;
  margin: 0;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.topbar-actions a,
.topbar-actions button,
.secondary-button {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
}

.admin-view {
  display: none;
}

.admin-view.active {
  display: grid;
  gap: 18px;
}

.stats-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-grid article,
.panel {
  background: var(--white);
  border: 1px solid var(--line);
}

.stats-grid article {
  padding: 22px;
}

.stats-grid span {
  color: var(--muted);
  display: block;
  font-weight: 700;
}

.stats-grid strong {
  display: block;
  font-size: 2.4rem;
  line-height: 1.1;
  margin-top: 10px;
}

.panel {
  padding: 20px;
}

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

.panel-heading h2 {
  font-size: 1.25rem;
  margin: 0;
}

.panel-note {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

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

.grid-form.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.span-2 {
  grid-column: span 2;
}

.check-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}

.check-row label,
.inline-check {
  align-items: center;
  color: var(--ink);
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.check-row input,
.inline-check input {
  min-height: 0;
  width: auto;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.product-image-tools {
  background: var(--soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding: 14px;
}

.mini-heading {
  align-items: start;
  margin-bottom: 0;
}

.mini-heading h3 {
  font-size: 1rem;
  margin: 0;
}

.mini-heading span {
  color: var(--muted);
  font-size: 0.86rem;
}

.inline-upload {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) auto;
}

.product-image-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.inline-upload button {
  background: var(--black);
  border: 0;
  color: var(--gold);
  font-weight: 800;
  min-height: 44px;
  padding: 10px 14px;
}

.inline-upload button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.inline-upload .secondary-button {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
}

.field-hint {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
  margin: 0;
}

.product-image-preview {
  margin-top: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.86rem;
}

td {
  font-size: 0.94rem;
}

.table-search {
  max-width: 300px;
}

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

.table-action {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
  min-height: 34px;
  padding: 6px 10px;
}

.table-action.danger {
  border-color: rgba(157, 45, 45, 0.28);
  color: var(--danger);
}

.badge {
  background: var(--soft);
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 4px 8px;
}

.badge.on {
  background: rgba(22, 114, 75, 0.1);
  color: var(--success);
}

.badge.off {
  background: rgba(157, 45, 45, 0.1);
  color: var(--danger);
}

.upload-form {
  align-items: end;
  grid-template-columns: minmax(220px, 1fr) auto;
}

.image-preview {
  margin-top: 16px;
  max-width: 360px;
}

.image-preview img {
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  display: block;
  object-fit: cover;
  width: 100%;
}

.image-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.image-card {
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding: 10px;
}

.image-card img {
  aspect-ratio: 1 / 1;
  background: var(--soft);
  object-fit: cover;
  width: 100%;
}

.image-card strong {
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.image-card .table-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.theme-preview {
  --preview-primary: #111111;
  --preview-accent: #c9a24a;
  --preview-bg: #ffffff;
  background: linear-gradient(135deg, var(--preview-bg), #f4f4f2);
}

.theme-preview-card {
  background: var(--preview-bg);
  border: 1px solid var(--line);
  color: var(--preview-primary);
  display: grid;
  gap: 10px;
  max-width: 420px;
  padding: 22px;
}

.theme-preview[data-radius-style="soft"] .theme-preview-card {
  border-radius: 8px;
}

.theme-preview[data-radius-style="rounded"] .theme-preview-card {
  border-radius: 16px;
}

.theme-preview-card h3,
.theme-preview-card p {
  margin: 0;
}

.theme-preview-card button {
  background: var(--preview-primary);
  border: 1px solid var(--preview-primary);
  color: var(--preview-accent);
  font-weight: 800;
  min-height: 42px;
  padding: 9px 14px;
  width: fit-content;
}

.theme-preview[data-button-style="outline"] .theme-preview-card button {
  background: transparent;
  color: var(--preview-primary);
}

.theme-preview[data-button-style="soft"] .theme-preview-card button {
  background: color-mix(in srgb, var(--preview-accent) 20%, #ffffff);
  color: var(--preview-primary);
}

@media (max-width: 1080px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .admin-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-grid,
  .image-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .admin-main,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .admin-nav,
  .stats-grid,
  .grid-form,
  .grid-form.compact,
  .inline-upload,
  .upload-form,
  .image-grid {
    grid-template-columns: 1fr;
  }

  .product-image-buttons {
    justify-content: stretch;
  }

  .product-image-buttons button {
    flex: 1 1 160px;
  }

  .span-2 {
    grid-column: auto;
  }
}
