:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #2563eb;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; }

.topbar nav a {
  margin-left: 1rem;
  color: var(--accent);
  text-decoration: none;
}

.user { margin-left: 1rem; color: var(--muted); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.muted { color: var(--muted); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
}

th, td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.messages { list-style: none; padding: 0; }
.messages .warning { color: #b45309; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
}

.logout-form {
  display: inline;
  margin: 0;
}

.logout-form button {
  background: none;
  color: var(--accent);
  padding: 0;
  margin-left: 1rem;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-form input[type="search"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.card {
  background: var(--card);
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.metric {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.warning { color: #b45309; }
tr.warning-row { background: #fffbeb; }

.prices-table .col-kit {
  width: 200px;
  max-width: 200px;
}

.prices-table .col-kit a {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prices-table td[title] {
  cursor: help;
}

.prices-table tbody tr:hover {
  background: #eff6ff;
}

.prices-table tbody tr.warning-row:hover {
  background: #fef3c7;
}

.pagination {
  margin-top: 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
}

section { margin-bottom: 1.5rem; }

.form-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.form-row input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 8rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.form-grid input,
.form-grid select {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.form-hint { font-size: 0.9rem; line-height: 1.5; }

.btn-secondary {
  background: #6b7280;
}

.btn-danger {
  background: #dc2626;
}

.inline-form {
  display: inline;
  margin-right: 0.25rem;
}

.inline-form button {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.actions { white-space: nowrap; }

.breakdown-table {
  margin-top: 0.75rem;
  max-width: 360px;
}

.recalc-form { margin-top: 1rem; }

.expense-form { margin-top: 1rem; }

.summary-cards {
  background: var(--card);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem;
}

.summary-cards h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-card strong {
  font-size: 1.25rem;
}

.summary-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-hint {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.5rem 1rem;
  background: var(--card);
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
}

.hidden { display: none !important; }

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border-radius: 6px;
}

.sync-banner {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.sync-banner-hint {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
}

.sync-spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #fcd34d;
  border-top-color: #b45309;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
  margin-top: 0.15rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.columns-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.columns-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.channel-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.status-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-badge.status-completed {
  background: #dcfce7;
  color: #166534;
}

.status-badge.status-cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.status-badge.status-returned {
  background: #ffedd5;
  color: #9a3412;
}

.sale-row.status-cancelled td {
  opacity: 0.75;
}

.sale-row.status-returned td {
  opacity: 0.85;
}

.row-unlinked td {
  background: #fffbeb;
}

.amount-negative {
  color: #dc2626;
  font-weight: 600;
}

.status-badge.status-has-reason {
  cursor: help;
  border-bottom: 1px dotted currentColor;
}

#sales-table [data-col="seller_price"],
#sales-table [data-col="customer_price"],
#sales-table [data-col="payout"],
#sales-table [data-col="profit"] {
  width: 6.25rem;
  min-width: 6.25rem;
  max-width: 6.25rem;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#sales-table th a {
  color: inherit;
  text-decoration: none;
}

#sales-table th a:hover {
  color: var(--accent);
}
