@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700&family=Playfair+Display:wght@600&display=swap");

:root {
  --teal: #3fa7a3;
  --teal-dark: #2d7f7c;
  --gold: #c9a34e;
  --cream: #f8f4ed;
  --paper: #fffdf9;
  --ink: #313332;
  --muted: #76736e;
  --line: #e7ddd0;
  --danger: #ad5146;
  --shadow: 0 20px 60px rgba(46, 59, 54, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  direction: rtl;
  background: var(--cream);
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 8% 10%, rgba(63, 167, 163, 0.1), transparent 28%),
    radial-gradient(circle at 90% 30%, rgba(201, 163, 78, 0.11), transparent 25%),
    var(--cream);
  color: var(--ink);
  font-family: "Vazirmatn", Tahoma, sans-serif;
  line-height: 1.75;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.sr-only {
  width: 1px;
  height: 1px;
  position: absolute;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.admin-header {
  min-height: 82px;
  padding: 12px max(4vw, 24px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff;
  box-shadow: 0 10px 30px rgba(24, 111, 108, 0.2);
}

.admin-header > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  color: #f2d696;
  font-size: 22px;
}

.admin-header strong,
.admin-header small {
  display: block;
}

.admin-header strong {
  font: 600 25px/1.2 "Playfair Display", serif;
  letter-spacing: 1.8px;
}

.admin-header small {
  margin-top: 4px;
  color: #e4f4f3;
  font-size: 10px;
}

.header-links {
  display: flex;
  align-items: center;
  gap: 9px;
}

.header-links a,
.header-links button {
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-size: 12px;
  transition: 0.2s ease;
}

.header-links a:hover,
.header-links button:hover {
  background: #fff;
  color: var(--teal-dark);
}

.header-links button[hidden] {
  display: none;
}

.login-shell {
  min-height: calc(100vh - 82px);
  display: grid;
  place-items: center;
  padding: 36px 20px;
}

.login-shell[hidden] {
  display: none;
}

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

.login-symbol {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 13px;
  border-radius: 50%;
  background: rgba(63, 167, 163, 0.1);
  color: var(--gold);
  font-size: 22px;
}

.login-card h1 {
  margin: 0 0 4px;
  color: var(--teal-dark);
  font-size: 25px;
}

.login-card > p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 12px;
}

.login-card label {
  display: block;
  margin-bottom: 14px;
}

.login-card label span {
  display: block;
  margin-bottom: 5px;
  color: #555450;
  font-size: 11px;
  font-weight: 600;
}

.login-card input {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  direction: ltr;
  text-align: left;
}

.login-card input:focus {
  border-color: var(--teal);
  outline: none;
  box-shadow: 0 0 0 3px rgba(63, 167, 163, 0.12);
}

.login-card button {
  width: 100%;
  min-height: 47px;
  margin-top: 5px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff;
}

.login-card button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.login-card > a {
  display: block;
  margin-top: 15px;
  color: var(--teal-dark);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}

.login-card > a[hidden] {
  display: none;
}

.login-card .login-error {
  margin-top: 14px;
  margin-bottom: 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: #fff0ed;
  color: #8e443c;
}

.admin-shell[hidden] {
  display: none;
}

.admin-shell {
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 48px 0 70px;
}

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 30px;
}

.intro span,
.panel-heading > div > span,
.phase-note > span {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
}

.intro h1 {
  margin: 2px 0 4px;
  color: var(--teal-dark);
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.4;
}

.intro p {
  max-width: 700px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.primary-action {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 10px 20px;
  border: 0;
  border-radius: 9px;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 10px 25px rgba(63, 167, 163, 0.24);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.stats article {
  min-height: 100px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 249, 0.9);
  box-shadow: 0 8px 30px rgba(46, 59, 54, 0.04);
}

.stats span,
.stats strong {
  display: block;
}

.stats span {
  color: var(--muted);
  font-size: 11px;
}

.stats strong {
  margin-top: 5px;
  color: var(--teal-dark);
  font-size: 25px;
}

.storage-status strong {
  font-size: 14px;
}

.storage-status i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 7px;
  border-radius: 50%;
  background: #48a87c;
  box-shadow: 0 0 0 5px rgba(72, 168, 124, 0.12);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.85fr) minmax(520px, 1.15fr);
  gap: 22px;
  align-items: start;
}

.catalog-panel,
.editor-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.catalog-panel {
  overflow: hidden;
}

.editor-panel {
  padding: 25px;
}

.panel-heading {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.editor-panel > .panel-heading {
  min-height: 62px;
  padding: 0 0 18px;
}

.panel-heading h2 {
  margin: 0;
  color: var(--teal-dark);
  font-size: 18px;
}

.admin-search input {
  width: min(210px, 24vw);
  height: 42px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}

.admin-search input:focus {
  border-color: var(--teal);
  outline: none;
  box-shadow: 0 0 0 3px rgba(63, 167, 163, 0.12);
}

.product-list {
  max-height: 740px;
  padding: 12px;
  overflow: auto;
}

.loading-state,
.empty-state {
  padding: 45px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.admin-product {
  width: 100%;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: right;
  transition: 0.2s ease;
}

.admin-product:hover {
  background: #f7f2ea;
}

.admin-product.active {
  border-color: rgba(63, 167, 163, 0.35);
  background: rgba(63, 167, 163, 0.08);
}

.admin-product img {
  width: 72px;
  height: 72px;
  border-radius: 9px;
  background: #eee5da;
  object-fit: cover;
}

.admin-product b,
.admin-product small {
  display: block;
}

.admin-product b {
  overflow: hidden;
  color: var(--teal-dark);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-product small {
  color: var(--muted);
  font-size: 10px;
}

.product-price {
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.stock-dot {
  display: block;
  width: 8px;
  height: 8px;
  margin: 8px auto 0;
  border-radius: 50%;
  background: #4ca77d;
}

.stock-dot.off {
  background: #c47a6a;
}

.unsaved-indicator {
  padding: 4px 9px;
  border-radius: 999px;
  background: #fff3d7;
  color: #8f6722;
  font-size: 10px;
}

#productForm {
  padding-top: 22px;
}

.image-editor {
  display: flex;
  align-items: center;
  gap: 17px;
  margin-bottom: 22px;
  padding: 15px;
  border: 1px dashed #d7c5ab;
  border-radius: 13px;
  background: #fcf8f2;
}

.image-preview {
  flex: 0 0 112px;
  height: 112px;
  overflow: hidden;
  border-radius: 11px;
  background: #eee6db;
}

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

#productImageFile {
  width: 1px;
  height: 1px;
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.upload-button {
  display: inline-flex;
  padding: 8px 13px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.image-editor small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
}

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

.field {
  display: block;
  margin-bottom: 15px;
}

.field > span {
  display: block;
  margin-bottom: 6px;
  color: #555450;
  font-size: 11px;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 45px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}

.field textarea {
  resize: vertical;
}

.field-help {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.7;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--teal);
  outline: none;
  box-shadow: 0 0 0 3px rgba(63, 167, 163, 0.12);
}

.stock-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 3px 0 22px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}

.stock-field input {
  width: 19px;
  height: 19px;
  accent-color: var(--teal);
}

.stock-field strong,
.stock-field small {
  display: block;
}

.stock-field strong {
  color: var(--teal-dark);
  font-size: 12px;
}

.stock-field small {
  color: var(--muted);
  font-size: 9px;
}

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

.save-button,
.delete-button {
  min-height: 46px;
  padding: 9px 18px;
  border-radius: 9px;
}

.save-button {
  flex: 1;
  border: 0;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff;
  box-shadow: 0 8px 22px rgba(63, 167, 163, 0.2);
}

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

.delete-button {
  border: 1px solid rgba(173, 81, 70, 0.45);
  background: #fff;
  color: var(--danger);
}

.delete-button[hidden] {
  display: none;
}

.phase-note {
  margin-top: 22px;
  padding: 18px 22px;
  border: 1px solid rgba(201, 163, 78, 0.3);
  border-radius: 13px;
  background: rgba(255, 250, 238, 0.85);
}

.phase-note p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.admin-toast {
  min-width: 250px;
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 9px;
  background: #303634;
  color: #fff;
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 12px;
}

.admin-toast.error {
  background: #8e443c;
}

@media (max-width: 1000px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .product-list {
    max-height: 480px;
  }
}

@media (max-width: 640px) {
  .admin-header {
    min-height: 70px;
    padding: 10px 15px;
  }

  .header-links a,
  .header-links button {
    padding: 7px 10px;
    font-size: 10px;
  }

  .login-card {
    padding: 28px 20px;
  }

  .admin-shell {
    width: min(100% - 24px, 1480px);
    padding-top: 30px;
  }

  .intro {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }

  .primary-action {
    width: 100%;
  }

  .stats {
    gap: 8px;
  }

  .stats article {
    min-height: 84px;
    padding: 14px;
  }

  .stats strong {
    font-size: 20px;
  }

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

  .admin-search input {
    width: 100%;
  }

  .editor-panel {
    padding: 17px;
  }

  .editor-panel > .panel-heading {
    align-items: center;
    flex-direction: row;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .image-editor {
    align-items: flex-start;
  }

  .image-preview {
    flex-basis: 94px;
    height: 94px;
  }

  .form-actions {
    flex-direction: column;
  }
}
