:root {
  --bg: #f2f4f3;
  --card-bg: #ffffff;
  --border: #e0e3e0;
  --border-strong: #c9cec9;
  --text: #1c231e;
  --muted: #6c7570;
  --brand: #1f7a52;
  --brand-dark: #145c3d;
  --brand-soft: #eaf5ef;
  --danger: #c0392b;
  --error-bg: #fdecea;
  --success-bg: #e8f5e9;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 24, 0.04), 0 8px 24px -12px rgba(20, 30, 24, 0.12);
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.topbar {
  background: var(--brand-dark);
  color: #fff;
}

.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.brand {
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
}

.topbar nav a {
  color: #dcefe4;
  text-decoration: none;
  font-size: 0.9rem;
  transition: color var(--transition);
}

.topbar nav a:hover { color: #fff; }

.topbar .user {
  color: #a9d3bd;
  font-size: 0.8rem;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3.5rem;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 1.25rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 1.25rem;
  color: var(--text);
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 380px;
  margin: 3rem auto;
}

form label {
  display: block;
  margin-bottom: 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #3c463f;
}

form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="number"],
form input[type="url"],
form textarea,
form select {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 400;
  color: var(--text);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
}

form input:focus,
form textarea:focus,
form select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

form textarea { resize: vertical; }

.price-field { max-width: 220px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0 1.25rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  background: var(--brand);
  color: #fff;
  transition: background var(--transition), transform 100ms ease, box-shadow var(--transition);
}

button:hover { background: var(--brand-dark); }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

button.secondary {
  background: #fff;
  color: var(--brand-dark);
  border: 1px solid var(--border-strong);
}

button.secondary:hover { background: var(--brand-soft); border-color: var(--brand); }

button.loading { position: relative; color: transparent; }
button.loading::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.link-button {
  background: none;
  color: var(--brand-dark);
  padding: 0;
  font-weight: 500;
  text-decoration: underline;
}

.link-button:hover { background: none; color: var(--brand); }
.link-button.danger { color: var(--danger); }

form.inline { display: inline; margin: 0; }

.ai-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

.alert {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.alert-error { background: var(--error-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: #256029; }
.alert-success a { color: var(--brand-dark); font-weight: 600; display: inline-block; margin-top: 0.3rem; }

.field-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 1.1em;
  margin: -0.7rem 0 0.9rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table th, .table td {
  text-align: left;
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

.table th { background: #f6f8f6; font-weight: 600; }
.table .actions { display: flex; gap: 0.75rem; }

/* --- Wizard / stepper --- */

.wizard { padding: 1.5rem 1.5rem 1.75rem; }

.stepper {
  list-style: none;
  display: flex;
  padding: 0;
  margin: 0 0 2rem;
}

.stepper-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  position: relative;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: default;
}

.stepper-item:not(:first-child)::before {
  content: "";
  position: absolute;
  top: 15px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.stepper-item.done:not(:first-child)::before,
.stepper-item.active:not(:first-child)::before {
  background: var(--brand);
}

.stepper-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  position: relative;
  z-index: 1;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.stepper-item.active .stepper-circle {
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.stepper-item.done { cursor: pointer; }
.stepper-item.done .stepper-circle {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-size: 0;
}

.stepper-item.done .stepper-circle::after {
  content: "\2713";
  font-size: 0.9rem;
}

.stepper-item.active .stepper-label { color: var(--text); font-weight: 600; }

.step { min-height: 220px; }

.step-enter { animation: stepFade 220ms ease; }

@keyframes stepFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.wizard-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.wizard-nav #nextBtn { margin-left: auto; }

.submit-row {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  margin-left: auto;
}

.status-select {
  margin-bottom: 0;
  font-size: 0.78rem;
}

.status-select select { min-width: 140px; padding: 0.55rem 0.6rem; }

/* --- Image previews --- */

.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.preview-thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f6f8f6;
}

.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  background: rgba(20, 30, 24, 0.65);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-remove:hover { background: var(--danger); }

/* --- Category multiselect --- */

.multiselect { position: relative; margin-bottom: 1.1rem; }

.multiselect-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 400;
  font-size: 0.95rem;
  text-align: left;
}

.multiselect-toggle:hover { background: #fff; border-color: var(--brand); }

.multiselect.open .multiselect-toggle {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.chevron { color: var(--muted); margin-left: 0.5rem; transition: transform var(--transition); }
.multiselect.open .chevron { transform: rotate(180deg); }

.multiselect-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.5rem;
}

.multiselect-search {
  margin: 0 0 0.4rem !important;
  width: 100%;
}

.multiselect-options {
  max-height: 220px;
  overflow-y: auto;
}

.multiselect-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 400;
  margin: 0;
  cursor: pointer;
}

.multiselect-option:hover { background: var(--brand-soft); }
.multiselect-option input { width: auto; margin: 0; }
.multiselect-empty { padding: 0.5rem; margin: 0; }

/* --- Vari combobox --- */

.combobox { position: relative; margin-top: 0.4rem; }

.combobox input[type="text"] { margin-top: 0; }

.combobox-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.4rem;
}

.combobox-options {
  max-height: 200px;
  overflow-y: auto;
}

.combobox-option {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 400;
  cursor: pointer;
}

.combobox-option:hover { background: var(--brand-soft); }

.combobox-create {
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--brand-dark);
  border-top: 1px dashed var(--border);
  margin-top: 0.3rem;
  padding-top: 0.6rem;
  cursor: pointer;
}

.combobox-create:hover { background: var(--brand-soft); }

#colorAutoHint { margin-top: 0.4rem; }

/* --- Profiilipiirros --- */

.profile-tool {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.profile-tool h3 {
  font-size: 0.95rem;
  margin: 0 0 0.3rem;
}

#profileCanvas {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  aspect-ratio: 640 / 360;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0.75rem 0;
  background: #e7e7e4;
  touch-action: none;
  cursor: grab;
}

.profile-segments {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.profile-segment {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.6rem 0.75rem;
  background: #f6f8f6;
  border-radius: var(--radius-sm);
}

.profile-segment-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  min-width: 55px;
}

.profile-segment label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
}

.profile-segment input {
  width: 90px;
  margin-top: 0.3rem !important;
}

.profile-segment select {
  width: 190px;
  margin-top: 0.3rem !important;
  padding: 0.5rem 0.6rem;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
}

@media (max-width: 480px) {
  .stepper-label { display: none; }
  .wizard-nav { flex-wrap: wrap; gap: 0.75rem; }
  .submit-row { width: 100%; justify-content: space-between; }
}
