:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f4;
  --ink: #172124;
  --muted: #65757b;
  --line: #d9e2e5;
  --primary: #146c6c;
  --primary-dark: #0e5454;
  --accent: #d99736;
  --good: #18734b;
  --bad: #b43b45;
  --warn: #8a5b13;
  --shadow: 0 20px 50px rgba(20, 45, 50, 0.10);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  background: #172124;
  color: #f8fbfb;
  padding: 28px 20px;
}

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

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

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.panel p,
.dialog-header h3,
.dialog-header p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin-top: 4px;
  color: #aebcbf;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: #d8e0e2;
  text-align: left;
  padding: 12px 14px;
}

.nav-tab:hover,
.nav-tab:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.nav-tab.active {
  background: #f8fbfb;
  color: #172124;
  font-weight: 700;
}

.sidebar-footer {
  display: grid;
  gap: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  padding-top: 18px;
  color: #aebcbf;
  font-size: 13px;
}

.sidebar-footer strong {
  color: #ffffff;
  font-size: 15px;
}

.workspace {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 26px;
  min-width: 0;
}

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

.eyebrow {
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  font-size: 32px;
  line-height: 1.1;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.cloud-account {
  display: grid;
  align-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 7px 12px;
}

.sync-pill {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.sync-pill.warning {
  color: var(--warn);
}

.sync-pill.good {
  color: var(--good);
}

.sync-pill.bad {
  color: var(--bad);
}

.user-email {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button,
.file-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 14px;
  font-weight: 700;
  white-space: nowrap;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary:hover,
.file-button:hover {
  border-color: var(--primary);
}

.button.danger {
  border-color: rgba(180, 59, 69, 0.25);
  color: var(--bad);
}

.button.danger:hover {
  background: #fff0f1;
}

.file-button {
  display: inline-grid;
  place-items: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 170px 170px;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 8px 24px rgba(20, 45, 50, 0.04);
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-panel h3,
.auth-panel p {
  margin: 0;
}

.auth-panel h3 {
  margin-bottom: 6px;
  font-size: 20px;
}

.auth-panel p:not(.eyebrow) {
  color: var(--muted);
  font-weight: 600;
}

.cloud-locked .toolbar,
.cloud-locked .view,
.cloud-locked .topbar-actions label,
.cloud-locked #exportCsvBtn,
.cloud-locked #exportJsonBtn,
.cloud-locked #newSaleBtn {
  display: none;
}

.control-group,
.settings-form label,
.form-grid label,
.form-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 10px 11px;
  font-size: 14px;
  font-weight: 500;
  text-transform: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 108, 108, 0.14);
  outline: none;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

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

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 132px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(20, 45, 50, 0.04);
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 30px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
  font-weight: 700;
}

.metric-card.positive {
  border-top: 4px solid var(--good);
}

.metric-card.warning {
  border-top: 4px solid var(--accent);
}

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

.insight-card {
  display: grid;
  gap: 6px;
  align-content: center;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(20, 45, 50, 0.04);
}

.insight-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.insight-card strong {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.15;
}

.dashboard-grid,
.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
}

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

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.panel-header h3 {
  font-size: 18px;
}

.panel-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  min-height: 260px;
  padding: 12px;
}

.rank-list,
.report-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.rank-row,
.report-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.rank-row strong,
.report-row strong {
  display: block;
  margin-bottom: 4px;
}

.rank-row span,
.report-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.rank-row em,
.report-row em {
  color: var(--good);
  font-style: normal;
  font-weight: 900;
}

.rank-row.loss em,
.report-row.loss em {
  color: var(--bad);
}

.empty-list {
  color: var(--muted);
  padding: 10px;
  text-align: center;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.item-with-thumb {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.product-thumb {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

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

.item-cell strong {
  display: block;
  max-width: 320px;
  overflow-wrap: anywhere;
}

.item-cell span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-width: 74px;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.Returned,
.status-pill.Refunded {
  background: #fff0f1;
  color: var(--bad);
}

.status-pill.Pending {
  background: #fff6e5;
  color: var(--warn);
}

.status-pill.Shipped,
.status-pill.Paid,
.status-pill.Sold {
  background: #e9f7f1;
  color: var(--good);
}

.profit-positive {
  color: var(--good);
  font-weight: 900;
}

.profit-negative {
  color: var(--bad);
  font-weight: 900;
}

.action-row {
  display: flex;
  gap: 8px;
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 800;
}

.mini-button:hover {
  border-color: var(--primary);
}

.empty-state {
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

.settings-panel {
  max-width: 880px;
}

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

.settings-form button {
  align-self: end;
}

.sale-dialog {
  width: min(980px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.24);
}

.sale-dialog::backdrop {
  background: rgba(10, 20, 24, 0.48);
}

.sale-dialog form {
  margin: 0;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.dialog-header h3 {
  font-size: 24px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-weight: 900;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.photo-control {
  display: grid;
  grid-template-columns: 136px 1fr;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.photo-preview {
  display: grid;
  place-items: center;
  width: 136px;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

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

.photo-actions {
  display: grid;
  gap: 10px;
  align-content: center;
}

.photo-actions small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
}

.photo-actions .button {
  justify-self: start;
}

.live-profit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 14px;
  align-items: center;
  margin: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.live-profit span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.live-profit strong {
  font-size: 26px;
}

.live-profit small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding: 16px 18px;
}

.dialog-actions .danger {
  margin-right: auto;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }

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

  .nav-tab {
    text-align: center;
  }

  .sidebar-footer {
    display: none;
  }

  .metric-grid,
  .insight-grid,
  .dashboard-grid,
  .dashboard-grid.bottom,
  .report-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .workspace {
    padding: 16px;
  }

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

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 140px;
  }

  .cloud-account {
    flex-basis: 100%;
  }

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

  .toolbar,
  .metric-grid,
  .insight-grid,
  .dashboard-grid,
  .dashboard-grid.bottom,
  .report-grid,
  .settings-form,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .photo-control {
    grid-template-columns: 1fr;
  }

  .photo-preview {
    width: 100%;
    max-width: 220px;
  }

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

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

  .metric-card strong {
    font-size: 25px;
  }

  .dialog-actions {
    flex-wrap: wrap;
  }

  .dialog-actions .danger {
    margin-right: 0;
  }
}
