:root{
  --bg: #0b0f16;
  --panel: #101827;
  --panel2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: rgba(255,255,255,0.08);
  --accent: #3b82f6;
  --danger: #ef4444;
  --good: #10b981;
  --warn: #f59e0b;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --radius: 16px;
  --radius2: 22px;
  --safe-top: calc(
    var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) +
    var(--tg-content-safe-area-inset-top, 0px)
  );
  --safe-bottom: calc(
    var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) +
    var(--tg-content-safe-area-inset-bottom, 0px)
  );
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body{
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 30% 0%, rgba(59,130,246,0.15), transparent 55%),
              radial-gradient(1000px 700px at 70% 20%, rgba(16,185,129,0.08), transparent 55%),
              var(--bg);
  color: var(--text);
}

#app{
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.topbar{
  position: sticky;
  top: var(--safe-top);
  z-index: 10;
  padding: 14px 14px;
  background: rgba(11,15,22,0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar__right{
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__left{
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.title{
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 16px;
}

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

.content{
  padding: 14px;
  flex: 1;
}

.screen{
  display: block;
}

.h2{
  margin: 6px 2px 12px;
  font-size: 18px;
  font-weight: 700;
}

.h3{
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 10px;
  color: var(--text);
}

.state{
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(16,24,39,0.65);
  border: 1px dashed var(--border);
  color: var(--muted);
}

.state-error{
  border-style: solid;
  border-color: rgba(239,68,68,0.35);
  color: #fecaca;
}

.state-ok{
  border-style: solid;
  border-color: rgba(16,185,129,0.35);
  color: #bbf7d0;
}

.row-between{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.list-actions{
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill{
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.55);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

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

.tile{
  width: 100%;
  padding: 14px 12px;
  border-radius: var(--radius2);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(16,24,39,0.85), rgba(15,23,42,0.65));
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  transition: transform 0.08s ease, border-color 0.08s ease;
}

.tile:active{
  transform: scale(0.99);
}

.tile__title{
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}

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

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

.row{
  padding: 10px;
  border-radius: var(--radius2);
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.6);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.08s ease;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.row:active{
  transform: scale(0.995);
}

.row-title{
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

.row-media{
  width: 100%;
}

.row-thumb{
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: rgba(15,23,42,0.7);
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--muted);
}

.row-thumb--loaded{
  background: transparent;
}

.row-content{
  flex: 1 1 auto;
  min-width: 0;
}

.row-sub{
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row-sub-item{
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-actions{
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.admin-actions .btn{
  padding: 6px 10px;
  font-size: 11px;
}

.add-photo__actions{
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 8px;
}

.add-photo__actions .btn{
  padding: 10px 14px;
  font-size: 13px;
}

.add-photo__img{
  width: 100%;
  max-height: 240px;
  border-radius: 14px;
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
  background: rgba(15,23,42,0.7);
}

.add-wizard{
  padding: 12px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: visible;
}

.add-wizard__head{
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.add-wizard__body{
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: visible;
}

.add-wizard__field{
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: visible;
}

.add-wizard__hint{
  font-size: 12px;
  color: var(--muted);
}

.add-wizard__actions{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.add-wizard__summary{
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.add-wizard__summary-row{
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
}

.detail-admin-actions{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.detail-admin-actions .btn{
  padding: 6px 12px;
  font-size: 12px;
}

.admin-status{
  margin-top: 12px;
}

.stock-yes{
  color: var(--good);
}

.stock-no{
  color: var(--danger);
}

.card{
  border-radius: var(--radius2);
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.6);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card.add-wizard{
  overflow: visible;
}

.card#addPhotoCard{
  overflow: visible;
}

.filters{
  padding: 12px;
  margin: 10px 0 14px;
  overflow: visible;
}

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

.filters__field{
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  min-width: 0;
  width: 100%;
}

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

.filters__select{
  width: 100%;
  min-width: 0;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.65);
  color: var(--text);
  max-width: 100%;
  font-size: 15px;
}

.filters__select[type="date"]{
  -webkit-appearance: none;
  appearance: none;
  display: block;
}

.filters__actions{
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.suggest{
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: rgba(16, 24, 39, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 20;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}

.suggest__item{
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.suggest__item + .suggest__item{
  border-top: 1px solid var(--border);
}

.suggest__item:hover{
  background: rgba(255,255,255,0.06);
}

.card--flat{
  padding: 14px;
  box-shadow: none;
  margin-top: 12px;
}

.cover-wrap{
  position: relative;
  width: 100%;
  background: rgba(15,23,42,0.7);
  border-bottom: 1px solid var(--border);
  min-height: 220px;
}

.cover{
  width: 100%;
  height: 280px;
  object-fit: cover;
  display: none;
  opacity: 0;
  transform: scale(1.01);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cover--ready{
  opacity: 1;
  transform: scale(1);
}

.cover-placeholder{
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.meta{
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model{
  font-size: 16px;
  font-weight: 800;
}

.kv{
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  align-items: baseline;
}

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

.kv__v{
  font-size: 13px;
}

.desc{
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.gallery{
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.thumb{
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: rgba(15,23,42,0.7);
}

.pager{
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.btn{
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.6);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.25), 0 10px 20px rgba(0,0,0,0.25);
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}

.btn-primary{
  background: rgba(59,130,246,0.2);
  border-color: rgba(59,130,246,0.4);
}

.btn-small{
  padding: 6px 10px;
  font-size: 12px;
}

.btn:active{
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.22), 0 6px 16px rgba(0,0,0,0.22);
}

.btn-ghost{
  background: transparent;
  box-shadow: none;
}

.cart-btn{
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.tabs{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 6px 0 12px;
}

.tab{
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.6);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  text-align: center;
}

.tab--active{
  background: rgba(59,130,246,0.2);
  border-color: rgba(59,130,246,0.45);
}

.detail-actions{
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.qty-wrap{
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
}

.btn-qty{
  padding: 8px 0;
  font-size: 20px;
  min-width: 44px;
}

.cart-list{
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cart-item{
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius2);
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.6);
}

.cart-thumb{
  width: 72px;
  height: 90px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: rgba(15,23,42,0.7);
  flex: 0 0 auto;
}

.cart-info{
  flex: 1 1 auto;
  min-width: 0;
}

.cart-title{
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}

.cart-meta{
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.status-badge{
  font-weight: 600;
}

.status-sold{
  color: var(--good);
}

.status-canceled{
  color: var(--danger);
}

.status-active{
  color: var(--warn);
}

.status-partial{
  color: var(--warn);
}

.cart-summary{
  margin-top: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cart-summary__row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.order-card{
  padding: 12px;
  border-radius: var(--radius2);
  border: 1px solid var(--border);
  background: rgba(16,24,39,0.6);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.order-title-wrap{
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.order-date{
  font-size: 11px;
  color: var(--muted);
}

.order-total{
  font-size: 12px;
  color: var(--text);
}

.order-actions{
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.item-actions{
  margin-top: 6px;
  display: flex;
  justify-content: flex-end;
}

.order-title{
  font-weight: 700;
  color: var(--text);
}

.order-items{
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cart-controls{
  margin-top: 6px;
  display: grid;
  grid-template-columns: 36px auto 36px 1fr;
  gap: 8px;
  align-items: center;
}

.cart-qty{
  font-size: 12px;
  color: var(--text);
  text-align: center;
  min-width: 72px;
}

.cart-remove{
  justify-self: end;
  white-space: nowrap;
}

.footer{
  padding: 10px 14px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: rgba(11,15,22,0.75);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.footer__actions{
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer__actions .btn{
  padding: 14px 18px;
  font-size: 15px;
  min-height: 44px;
}

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

  .filters__select{
    font-size: 16px;
  }
}

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

.cat-tile{
  position: relative;
  width: 100%;
  height: 120px;
  border-radius: var(--radius2);
  overflow: hidden;
}

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

.cat-overlay{
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(0,0,0,0.65),
    rgba(0,0,0,0.15)
  );
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
}

.cat-overlay .tile__title{
  color: #fff;
  font-size: 15px;
}

.cat-overlay .tile__meta{
  color: rgba(255,255,255,0.8);
}

.viewer.hidden { display: none; }

.viewer{
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.viewer__backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
}

.viewer__panel{
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  grid-template-rows: 44px 1fr 44px;
  align-items: center;
  padding: 10px;
}

.viewer__img{
  grid-column: 2;
  grid-row: 2;
  max-width: 100%;
  max-height: 80vh;
  width: 100%;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.viewer__img--loading{
  opacity: 0;
  transform: scale(0.98);
}

.viewer__nav{
  grid-row: 2;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 0;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.viewer__nav:disabled{
  opacity: 0.4;
}

.viewer__nav--prev{ grid-column: 1; justify-self: center; }
.viewer__nav--next{ grid-column: 3; justify-self: center; }

.viewer__close{
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 0;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.viewer__counter{
  grid-column: 2;
  grid-row: 3;
  justify-self: center;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
}
