:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --panel-soft: #eef4f0;
  --ink: #203033;
  --muted: #6b7a7c;
  --border: #dbe5df;
  --brand: #2f5d62;
  --brand-2: #417d7a;
  --line: #06c755;
  --google: #3457d5;
  --gold: #c28f35;
  --rose: #bb5f6a;
  --blue: #426d9f;
  --shadow: 0 16px 40px rgba(40, 64, 59, .09);
  --radius: 8px;
  font-family: "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.app-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-kicker, .eyebrow, .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.brand h1 { font-size: 20px; }

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  font-weight: 750;
}

.nav-item.is-active {
  background: var(--panel-soft);
  color: var(--brand);
}

.nav-icon {
  width: 24px;
  text-align: center;
  font-size: 18px;
}

.session-panel {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

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

.login-btn, .primary-button, .ghost-button, .icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 12px;
  font-weight: 800;
}

.login-btn { color: #fff; }
.login-btn.line { background: var(--line); }
.login-btn.google { background: var(--google); }
.login-btn.admin { background: var(--brand); width: 100%; }

.current-user {
  min-height: 58px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h2 { font-size: 28px; }

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

.sync-pill {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--brand);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: #fff;
  border-color: var(--border);
  color: var(--brand);
}

.view { display: none; }
.view.is-active { display: block; }

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

.toolbar, .admin-filter {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  min-height: 44px;
}

.search input, select, input, textarea {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 44px;
  padding: 9px 11px;
  outline: none;
}

.search input {
  border: 0;
  min-height: 40px;
  width: 100%;
  padding: 0;
}

input:focus, textarea:focus, select:focus, .search:focus-within {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(65, 125, 122, .14);
}

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

.product-card, .surface, .cart-panel, .lock-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.product-card {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.product-art {
  min-height: 150px;
  display: grid;
  place-items: center;
  color: rgba(255,255,255,.96);
  font-size: 46px;
  font-weight: 850;
  position: relative;
}

.tone-preorder { background: linear-gradient(135deg, #417d7a, #d0a34d); }
.tone-ready { background: linear-gradient(135deg, #426d9f, #7ab893); }
.tone-sale { background: linear-gradient(135deg, #bb5f6a, #d9a76c); }
.tone-beauty { background: linear-gradient(135deg, #bb5f6a, #d9a76c); }
.tone-snack { background: linear-gradient(135deg, #8065a9, #4f8f86); }

.product-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-art > strong {
  font-size: 48px;
  letter-spacing: 0;
}

.product-art span {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0,0,0,.34);
  color: #fff;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.product-body {
  padding: 12px;
  display: grid;
  gap: 8px;
  flex: 1;
}

.product-body h3 {
  font-size: 16px;
  line-height: 1.3;
}

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

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

.price {
  font-size: 17px;
  font-weight: 850;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.primary-button.compact {
  min-height: 44px;
}

.ghost-button {
  background: #fff;
  color: var(--brand);
  border-color: var(--border);
}

.cart-panel {
  position: sticky;
  top: 22px;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cart-list, .history-list {
  display: grid;
  gap: 8px;
}

.cart-row, .history-row {
  border: 1px solid var(--border);
  background: #fbfcfb;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.cart-row-main, .history-row-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-controls button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--brand);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-weight: 850;
}

.total-box {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: grid;
  gap: 6px;
}

.total-box div {
  display: flex;
  justify-content: space-between;
}

.total-box .grand {
  font-size: 19px;
  color: var(--brand);
}

.profile-grid, .dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.surface { padding: 14px; }

.form-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

label.wide { grid-column: 1 / -1; }
textarea { resize: vertical; }

.admin-locked { display: none; }
.admin-locked.is-active {
  display: grid;
  min-height: 50vh;
  place-items: center;
}
.lock-box {
  padding: 24px;
  width: min(420px, 100%);
}

.admin-content { display: none; }
.admin-content.is-active { display: block; }

.segmented {
  display: inline-flex;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 800;
}

.segmented button.is-active {
  background: var(--brand);
  color: #fff;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 6px;
}

.status-bars {
  display: grid;
  gap: 10px;
}

.status-line {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr) 34px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-track {
  height: 12px;
  background: var(--panel-soft);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--brand-2);
}

.mini-chart {
  height: 250px;
  display: flex;
  align-items: end;
  gap: 8px;
  padding-top: 16px;
}

.chart-col {
  flex: 1;
  display: grid;
  align-content: end;
  gap: 6px;
  min-width: 34px;
}

.chart-bar {
  min-height: 4px;
  background: var(--blue);
  border-radius: 6px 6px 0 0;
}

.chart-label {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.sheet-surface {
  margin-top: 18px;
}

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

.table-wrap {
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.sheet-table th, .sheet-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.sheet-table th {
  background: var(--panel-soft);
  color: var(--brand);
  font-size: 13px;
}

.sheet-table input, .sheet-table select {
  min-height: 36px;
  width: 100%;
  padding: 6px 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}

.toast.is-open {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .session-panel { margin-top: 0; }
  .shop-layout { grid-template-columns: 1fr; }
  .cart-panel { position: static; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .main { padding: 14px; }
  .topbar, .toolbar, .admin-filter, .panel-head {
    align-items: stretch;
    flex-direction: column;
  }
  .product-grid, .profile-grid, .dashboard-grid, .form-grid {
    grid-template-columns: 1fr;
  }
  .metric-grid { grid-template-columns: 1fr; }
  .nav-item { justify-content: center; }
  .nav-item span:last-child { display: none; }
}
