*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #fafafa;
  color: #222;
  line-height: 1.5;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  height: 3.5rem;
  background: #fff;
  color: #222;
  border-bottom: 1px solid #ddd;
  gap: 1.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
}

.topbar-nav {
  display: flex;
  gap: 0.5rem;
}


.nav-btn {
  background: #fff;
  border: 1px solid #ccc;
  color: #888;
  cursor: pointer;
  padding: 0.4rem 1rem;
  font-size: 1rem;
  border-radius: 4px;
}

.nav-btn:hover {
  color: #222;
  border-color: #888;
}

.nav-btn.active {
  color: #fff;
  background: #222;
  border-color: #222;
  font-weight: 700;
}

.nav-logout {
  color: #888;
  border-color: #ccc;
  margin-left: auto;
}

/* Main content */
.main {
  flex: 1;
  padding: 1.5rem;
  width: 100%;
}

/* Buttons */
.btn {
  background: #111;
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn:hover {
  background: #333;
}

.btn-danger {
  background: #c0392b;
}

.btn-danger:hover {
  background: #e74c3c;
}

.btn-back {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:hover {
  color: #222;
}


/* Selection bar */
.selection-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #2d4a7a;
  color: #fff;
  padding: 0 1.5rem;
  font-size: 0.85rem;
  z-index: 100;
}

.selection-count {
  margin-right: 0.5rem;
  font-weight: 600;
}

.selection-bar-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.selection-bar-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* Product grid */
.product-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.product-card {
  width: 200px;
  position: relative;
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  overflow: hidden;
  background: #f0f0f0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  transition: box-shadow 0.15s;
}

.product-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
}

.product-card.selected {
  outline: 2px solid #2d4a7a;
  outline-offset: -2px;
}

.product-card-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #2d4a7a;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-card-thumb {
  width: 100%;
  height: 160px;
  background: #f0f0f0 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23bbb' stroke-width='1.5'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6'/%3E%3C/svg%3E") center no-repeat;
  background-size: 48px;
  position: relative;
  overflow: hidden;
}

.product-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

.product-card-header {
  padding: 0.5rem 0.6rem 0.3rem;
  line-height: 1.3;
  text-align: center;
}

.product-card-name {
  font-size: 1.3rem;
  font-weight: 600;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #222;
}

.product-card-others {
  font-size: 1rem;
  color: #999;
  display: block;
}

.product-card-footer {
  padding: 0.3rem 0.6rem 0.5rem;
  line-height: 1.3;
  text-align: center;
}

.product-card-price {
  font-size: 1.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: block;
  color: #111;
}

.product-card-size {
  font-size: 1.05rem;
  color: #999;
  display: block;
}


.product-card-add {
  width: 200px;
  min-height: 200px;
  border: 2px dashed #ccc;
  border-radius: 6px;
  background: #f8f8f8 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='2'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E") center no-repeat;
  background-size: 48px;
  cursor: pointer;
}

.product-card-add:hover {
  background: #eee url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E") center no-repeat;
  background-size: 48px;
  border-color: #999;
}


/* Detail overlay */
.detail-overlay {
  position: fixed;
  inset: 0;
  top: 3.5rem;
  background: #fafafa;
  z-index: 10;
  overflow-y: auto;
}

.detail-content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

/* Fields */
.detail-fields, .settings-view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 400px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field label {
  font-size: 0.8rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input,
.field select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.95rem;
  background: #fff;
}

.field input[type="email"] {
  direction: ltr;
  text-align: left;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: #111;
}

/* Price row */
.price-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.price-row .input-price {
  width: 50%;
  flex: none;
  font-size: 1.9rem;
  font-weight: 600;
}

/* Segmented control */
.segmented-control {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-width: 50%;
}

.seg-btn {
  padding: 0.35rem 0.6rem;
  border: 1px solid #ddd;
  background: #fff;
  color: #666;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 500;
  border-radius: 4px;
}

.seg-btn:hover {
  background: #f0f0f0;
}

.seg-btn-active {
  background: #222;
  color: #fff;
  border-color: #222;
}

.seg-btn-active:hover {
  background: #333;
}

.detail-divider {
  border: none;
  border-top: 1px solid #ddd;
}

.checkout-link-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.checkout-link-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-copy {
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  color: #666;
  cursor: pointer;
  padding: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-copy:hover {
  color: #222;
  border-color: #888;
}

.btn-copy.copied {
  color: #27ae60;
  border-color: #27ae60;
}

.readonly-field {
  padding: 0.5rem 0.75rem;
  background: #f0f0f0;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  color: #666;
}

/* File grid */
.file-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.file-tile {
  width: 160px;
  background: #f0f0f0;
  border-radius: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.file-tile:hover {
  background-color: #e8e8e8;
}

.file-tile.selected {
  outline: 2px solid #2d4a7a;
  outline-offset: -2px;
}

.file-tile-header {
  padding: 0.4rem 0.4rem 0.25rem;
  text-align: center;
  line-height: 1.2;
}

.file-tile-name {
  font-size: 1.1rem;
  font-weight: 600;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #222;
}

.file-tile-thumb-wrap {
  position: relative;
  overflow: hidden;
}

.file-tile-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #2d4a7a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.file-tile-thumb {
  width: 100%;
  height: 128px;
  object-fit: cover;
  display: block;
  -webkit-user-drag: none;
  user-drag: none;
}

.file-tile-footer {
  padding: 0.25rem 0.4rem 0.4rem;
  text-align: center;
  line-height: 1.2;
}

.file-tile-size {
  font-size: 1.05rem;
  color: #999;
  display: block;
}

.file-tile-add {
  min-height: 152px;
  border: 2px dashed #ccc;
  background: #f8f8f8 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='2'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E") center no-repeat;
  background-size: 32px;
  cursor: pointer;
  position: relative;
}

.file-tile-add:hover {
  background-color: #eee;
  border-color: #999;
}

.file-input-hidden {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Archive section */
.archive-section {
  margin-top: 2rem;
}

.archive-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.5rem 0;
  user-select: none;
  color: #666;
  font-size: 0.9rem;
  font-weight: 600;
}

.archive-header:hover {
  color: #333;
}

.archive-header-title {
  flex: 1;
}

.archive-toggle {
  font-size: 1.2rem;
  font-weight: 700;
  width: 1.5rem;
  text-align: center;
  line-height: 1;
}

.archive-grid {
  margin-top: 0.75rem;
  opacity: 0.7;
}

/* Settings */
.settings-view h2 {
  margin-bottom: 1.5rem;
}

.badge-tier {
  display: inline-block;
  background: #e8f0fe;
  color: #2d4a7a;
  padding: 0.2rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
}

.placeholder {
  color: #999;
  font-style: italic;
}

/* Stripe Connect */
.btn-stripe {
  background: #635bff;
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
}

.btn-stripe:hover {
  background: #7a73ff;
}

.badge-stripe-connected {
  display: inline-block;
  background: #d4edda;
  color: #155724;
  padding: 0.2rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Sales list */
.sales-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 480px;
}

.sale-item {
  padding: 0.75rem 1rem;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.sale-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.sale-product {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sale-price {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.sale-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: #999;
  margin-top: 0.25rem;
}

.sale-email {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Loading */
.loading {
  text-align: center;
  padding: 3rem;
  color: #999;
}

/* Toast */
.link-subtle {
  font-size: 0.8rem;
  color: #999;
  cursor: pointer;
  text-decoration: none;
}

.link-subtle:hover {
  color: #c0392b;
}

/* Email confirm row */
.email-confirm-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  max-width: 400px;
}

.email-confirm-row input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.95rem;
}

.email-confirm-row input:focus {
  outline: none;
  border-color: #111;
}

/* Login page */
.login-view {
  max-width: 360px;
  margin: 4rem auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.login-view h2 {
  text-align: center;
}

.login-demo-link {
  text-align: center;
  font-size: 0.9rem;
}

.login-demo-link a {
  color: #666;
}

.login-demo-link a:hover {
  color: #222;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #c0392b;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 6px;
  font-size: 0.85rem;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
