:root {
  --background: #f8fafc;
  --foreground: #0f172a;
  --card: #ffffff;
  --muted: #64748b;
  --muted-bg: #f1f5f9;
  --border: #e2e8f0;
  --primary: #111827;
  --primary-foreground: #ffffff;
  --accent: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
}

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

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

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

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

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

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

.brand span,
.label,
.muted,
.panel-head p,
.metric-card span,
.metric-card small {
  color: var(--muted);
}

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

.nav-item,
.button,
.icon-button,
.segmented button {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.18s ease;
}

.nav-item {
  text-align: left;
  padding: 10px 12px;
  color: #334155;
  background: transparent;
}

.nav-item:hover,
.nav-item.active {
  color: var(--foreground);
  background: var(--muted-bg);
}

.tenant-card {
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
}

.tenant-card select,
.tenant-card p {
  width: 100%;
  margin: 8px 0 0;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--foreground);
  padding: 9px 11px;
  outline: none;
}

textarea {
  min-height: 190px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, monospace;
  line-height: 1.55;
}

select:focus,
input:focus,
textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 16px;
  letter-spacing: 0;
}

.top-actions,
.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.button {
  min-height: 38px;
  padding: 8px 13px;
  font-weight: 600;
}

.button.primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.button.secondary,
.icon-button {
  background: white;
  color: var(--foreground);
  border-color: var(--border);
}

.button:hover,
.icon-button:hover,
.segmented button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

.icon-button {
  width: 38px;
  height: 38px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric-card,
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric-card {
  padding: 15px;
}

.metric-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 26px;
  letter-spacing: 0;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.7fr);
  gap: 14px;
}

.split,
.store-layout,
.tenant-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  gap: 14px;
}

.tenant-layout {
  grid-template-columns: minmax(320px, 0.72fr) minmax(0, 1.28fr);
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--muted-bg);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.status.success {
  background: #dcfce7;
  color: #166534;
}

.status.warn {
  background: #fef3c7;
  color: #92400e;
}

.status.danger {
  background: #fee2e2;
  color: #991b1b;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item,
.channel-item,
.product-item,
.tenant-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.timeline-item {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 12px;
  align-items: center;
}

.timeline-item strong,
.product-item strong,
.channel-item strong,
.tenant-item strong {
  display: block;
  margin-bottom: 3px;
}

.channel-list,
.product-list,
.tenant-grid {
  display: grid;
  gap: 10px;
}

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

.tenant-form .full {
  grid-column: 1 / -1;
}

.tenant-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.tenant-edit {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.tenant-actions {
  margin-top: 12px;
}

.danger-button {
  color: #991b1b;
  border-color: #fecaca;
}

.channel-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.product-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.stock-bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--muted-bg);
  margin-top: 10px;
}

.stock-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #2563eb);
}

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

label {
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

label input,
label select {
  margin-top: 6px;
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
}

.switch input {
  display: none;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #cbd5e1;
  cursor: pointer;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: white;
  transition: 0.18s ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--muted-bg);
  border-radius: 9px;
}

.segmented button {
  padding: 6px 10px;
  background: transparent;
}

.segmented button.active {
  background: white;
  border-color: var(--border);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 11px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

pre {
  min-height: 156px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  line-height: 1.55;
}

.phone {
  display: flex;
  justify-content: center;
}

.phone-screen {
  width: min(100%, 390px);
  min-height: 720px;
  border: 10px solid #111827;
  border-radius: 30px;
  background: #f8fafc;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
}

.store-hero {
  padding: 22px;
  color: white;
  background: linear-gradient(135deg, #111827, #2563eb);
}

.store-hero span {
  display: inline-block;
  margin-bottom: 12px;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  font-size: 12px;
}

.store-hero h2 {
  font-size: 24px;
}

.store-products {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.store-product {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
}

.store-product.active {
  outline: 2px solid var(--primary);
}

.checkout {
  display: grid;
  gap: 10px;
  padding: 0 14px 16px;
}

.guard-card,
.delivery-card {
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.delivery-card {
  margin-top: 14px;
  border-style: solid;
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.hidden {
  display: none;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.16);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

body.public-store {
  background: #f8fafc;
}

body.public-store #app {
  display: block;
  min-height: 100vh;
}

body.public-store .sidebar,
body.public-store .topbar {
  display: none;
}

body.public-store .shell {
  padding: 0;
}

body.public-store .view {
  display: none;
}

body.public-store #store.view.active {
  display: block;
}

body.public-store .store-layout {
  display: block;
}

body.public-store .phone {
  min-height: 100vh;
  align-items: stretch;
}

body.public-store .phone-screen {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.public-store .store-layout > .panel {
  display: none;
}

@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid,
  .content-grid,
  .split,
  .store-layout,
  .tenant-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 14px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .form-grid,
  .tenant-form,
  .tenant-edit {
    grid-template-columns: 1fr;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .timeline-item,
  .product-item {
    grid-template-columns: 1fr;
  }

  .phone-screen {
    min-height: 660px;
  }
}
