:root {
  color-scheme: light;
  --ink: #231f20;
  --muted: #676266;
  --line: #e3ded8;
  --paper: #fff9f0;
  --panel: #ffffff;
  --field: #fffdf8;
  --brand: #21b8c8;
  --brand-dark: #087987;
  --brand-soft: #e8f8fa;
  --accent: #ef1453;
  --accent-soft: #ffe7ef;
  --gold: #ffca09;
  --gold-soft: #fff4c8;
  --lime: #a8d638;
  --orange: #f4661b;
  --warn: #ef1453;
  --shadow: 0 14px 36px rgba(35, 31, 32, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
  gap: 32px;
  align-items: center;
  padding: clamp(20px, 4vw, 56px);
  background:
    linear-gradient(90deg, rgba(255, 202, 9, 0.16), transparent 28%),
    linear-gradient(180deg, #fff, var(--paper));
}

.brand-logo {
  display: block;
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

.auth-logo {
  width: min(420px, 92vw);
  margin-bottom: 22px;
}

.auth-brand h1,
.topbar h1,
.panel h2,
.section-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.auth-brand h1 {
  max-width: 760px;
  font-size: clamp(36px, 6vw, 74px);
  line-height: 0.96;
}

.auth-brand p:not(.eyebrow) {
  max-width: 540px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.5;
}

.auth-panels {
  display: grid;
  grid-template-columns: minmax(260px, 460px);
  gap: 18px;
  justify-content: end;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 22px;
  align-items: center;
  padding: 16px clamp(18px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 249, 240, 0.94);
  backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
}

.topbar-logo {
  width: 126px;
  flex: 0 0 auto;
}

.topbar h1 {
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff2bd;
}

.tab-btn,
.ghost-btn {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
}

.tab-btn {
  padding: 9px 14px;
  font-weight: 700;
}

.tab-btn.active {
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(35, 31, 32, 0.12);
}

.user-box {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

main {
  padding: 24px clamp(18px, 3vw, 34px) 44px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(360px, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

form.panel,
.preview-panel,
.colors-panel,
.account-designs {
  padding: 18px;
}

.panel-title-row,
.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.panel h2,
.section-heading h2 {
  font-size: 22px;
}

label {
  display: grid;
  gap: 7px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(33, 184, 200, 0.18);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--brand);
}

.measure-grid,
.crop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 12px;
  align-items: end;
}

.range-row strong {
  padding-bottom: 11px;
  color: var(--brand-dark);
  text-align: right;
}

.crop-box,
.text-box {
  margin: 18px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.crop-box legend,
.text-box legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.source-preview {
  width: 100%;
  height: auto;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #efede5;
}

.render-frame {
  display: grid;
  place-items: center;
  min-height: 420px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #efe9df 25%, transparent 25%),
    linear-gradient(-45deg, #efe9df 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #efe9df 75%),
    linear-gradient(-45deg, transparent 75%, #efe9df 75%);
  background-color: #fffaf2;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  overflow: hidden;
}

#renderCanvas {
  max-width: 100%;
  max-height: 68vh;
  width: auto;
  height: auto;
  box-shadow: 0 18px 32px rgba(23, 32, 27, 0.22);
  touch-action: none;
  cursor: crosshair;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.compact-actions {
  margin-top: 10px;
}

.selection-buttons {
  display: none;
}

.layer-tools {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf8;
}

.result-head-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.render-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tool-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.tool-btn:hover:not(:disabled),
.tool-btn:focus-visible {
  border-color: var(--brand);
  background: var(--brand-soft);
  outline: none;
}

.text-tool {
  font-size: 15px;
}

.layer-tools h3 {
  margin: 0;
  font-size: 17px;
}

.empty-layer {
  opacity: 0.78;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 7px;
  font-weight: 800;
}

.full-btn {
  width: 100%;
  margin-top: 10px;
}

.primary-btn {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
}

.primary-btn:hover {
  background: #3a3235;
}

.secondary-btn {
  border: 1px solid var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.id-pill {
  max-width: 180px;
  overflow: hidden;
  border: 1px solid #f0d166;
  border-radius: 999px;
  padding: 6px 10px;
  color: #5d4200;
  background: var(--gold-soft);
  font-size: 12px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.used-colors {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.empty-state {
  min-height: 140px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.color-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: default;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.color-row.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(33, 184, 200, 0.14);
}

.color-row.is-deleted {
  opacity: 0.55;
}

.texture-chip {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 7px;
  background-size: cover;
}

.color-row strong {
  display: block;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

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

.section-heading {
  margin-bottom: 18px;
  align-items: center;
}

.search-input {
  max-width: 360px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
}

.filter-row label {
  min-width: 150px;
  margin-top: 0;
}

.pagination-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
}

.designs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.design-card {
  overflow: hidden;
}

.design-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #ece9df;
  border-bottom: 1px solid var(--line);
}

.design-body {
  padding: 14px;
}

.design-body h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.design-meta {
  display: grid;
  gap: 4px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

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

.danger-btn {
  border-color: var(--accent);
  color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card,
.stat-panel,
.admin-users {
  padding: 18px;
}

.stat-card span,
.stat-row span,
.user-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.stats-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
}

.stat-panel h3 {
  margin: 0 0 12px;
}

.stat-list {
  display: grid;
  gap: 12px;
}

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

.stat-row div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stat-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--gold-soft);
}

.stat-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(280px, 360px) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.admin-users {
  margin-top: 18px;
}

.user-create-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
}

.user-create-grid label {
  margin-top: 0;
}

.users-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.user-card {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(140px, 0.7fr) minmax(160px, 0.8fr) auto;
  gap: 12px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.user-card label {
  margin-top: 0;
}

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

.compact-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.compact-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.compact-item:last-child {
  border-bottom: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid rgba(33, 184, 200, 0.28);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 750;
}

@media (max-width: 1180px) {
  .workspace-grid,
  .account-grid,
  .stats-columns {
    grid-template-columns: 1fr;
  }

  .stats-grid,
  .user-create-grid,
  .user-card {
    grid-template-columns: 1fr;
  }

  .colors-panel {
    order: 3;
  }
}

@media (max-width: 820px) {
  .auth-shell,
  .auth-panels {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
  }

  .tabs {
    width: 100%;
    overflow-x: auto;
  }

  .user-box,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-row {
    justify-content: stretch;
  }

  .filter-row label,
  .filter-row .search-input {
    max-width: none;
    width: 100%;
  }

  .result-head-actions {
    justify-items: start;
  }

  .topbar-logo {
    width: 112px;
  }

  .search-input {
    max-width: none;
  }
}

@media (max-width: 520px) {
  .measure-grid,
  .crop-grid {
    grid-template-columns: 1fr;
  }

  main {
    padding-inline: 12px;
  }

  .auth-shell {
    padding: 16px;
  }

  .auth-logo {
    width: 100%;
  }

  .render-toolbar {
    flex-wrap: wrap;
  }
}
