:root {
  color-scheme: dark;
  --font-ui: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-data: "Rajdhani", "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --bg: oklch(0.115 0.024 250);
  --bg-soft: oklch(0.145 0.025 250);
  --nav: oklch(0.18 0.035 249);
  --surface: oklch(0.18 0.026 250);
  --surface-2: oklch(0.205 0.028 250);
  --surface-3: oklch(0.235 0.034 248);
  --row: transparent;
  --row-alt: transparent;
  --row-hover: oklch(0.225 0.028 249);
  --row-digimium: oklch(0.285 0.058 246);
  --row-digimium-hover: oklch(0.33 0.068 246);
  --row-facebook: oklch(0.285 0.082 260);
  --row-facebook-hover: oklch(0.33 0.094 260);
  --row-telegram: oklch(0.3 0.066 226);
  --row-telegram-hover: oklch(0.345 0.076 226);
  --row-website: oklch(0.285 0.055 156);
  --row-website-hover: oklch(0.33 0.064 156);
  --ink: oklch(0.925 0.012 250);
  --ink-strong: oklch(0.985 0.004 250);
  --muted: oklch(0.72 0.035 250);
  --muted-2: oklch(0.58 0.035 250);
  --line: oklch(0.29 0.032 250);
  --line-strong: oklch(0.38 0.055 247);
  --primary: oklch(0.785 0.13 220);
  --primary-strong: oklch(0.72 0.155 224);
  --primary-ink: oklch(0.145 0.025 250);
  --accent: oklch(0.58 0.2 27.1);
  --success: oklch(0.7 0.17 150);
  --warning: oklch(0.82 0.15 82);
  --danger: oklch(0.64 0.22 28);
  --shadow: 0 18px 44px oklch(0 0 0 / 0.28);
  --radius: 8px;
  --radius-sm: 6px;
  --focus: 0 0 0 3px oklch(0.785 0.13 220 / 0.3);
}

body[data-store-theme="facebook"] {
  --primary: oklch(0.66 0.19 255);
  --primary-strong: oklch(0.6 0.21 255);
  --primary-ink: white;
  --focus: 0 0 0 3px oklch(0.66 0.19 255 / 0.32);
}

body[data-store-theme="telegram"] {
  --primary: oklch(0.74 0.14 231);
  --primary-strong: oklch(0.68 0.16 231);
  --primary-ink: oklch(0.145 0.025 250);
  --focus: 0 0 0 3px oklch(0.74 0.14 231 / 0.32);
}

body[data-store-theme="website"] {
  --primary: oklch(0.75 0.16 157);
  --primary-strong: oklch(0.68 0.18 157);
  --primary-ink: oklch(0.145 0.025 250);
  --focus: 0 0 0 3px oklch(0.75 0.16 157 / 0.3);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

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

button {
  color: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 0 78px;
  border-bottom: 1px solid oklch(0.26 0.035 248);
  background: color-mix(in oklch, var(--nav) 94%, black);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 174px;
  color: var(--ink-strong);
  font-weight: 500;
  letter-spacing: 0;
}

.brand-logo {
  display: block;
  width: 137px;
  height: auto;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 24px;
  white-space: nowrap;
}

.nav-link {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  padding: 9px 0;
}

.nav-link::after {
  position: absolute;
  right: 0;
  bottom: 3px;
  left: 0;
  height: 2px;
  border-radius: 999px;
  background: transparent;
  content: "";
}

.nav-link.active::after {
  background: var(--ink);
}

.nav-link.logout {
  color: var(--primary);
}

.sync-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 450;
  white-space: nowrap;
}

.sync-indicator .icon {
  width: 15px;
  height: 15px;
}

.sync-indicator[data-status="syncing"],
.sync-indicator[data-status="pending"],
.sync-indicator[data-status="saving"] {
  color: var(--primary);
}

.sync-indicator[data-status="offline"],
.sync-indicator[data-status="error"] {
  color: var(--warning);
}

.container {
  width: min(1850px, calc(100vw - 64px));
  margin: 0 auto;
  padding: 16px 0 44px;
}

.toolbar,
.panel,
.table-card {
  border: 1px solid oklch(0.25 0.03 249 / 0.78);
  border-radius: var(--radius);
  background: oklch(0.17 0.025 250 / 0.9);
  box-shadow: 0 14px 32px oklch(0 0 0 / 0.18);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 66px;
  padding: 14px 16px;
}

.toolbar + .panel,
.toolbar + .table-card,
.panel + .table-card {
  margin-top: 14px;
}

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

.toolbar-title {
  margin: 0;
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 650;
}

.single-tab {
  display: inline-flex;
  align-items: stretch;
  min-width: 78px;
  border-bottom: 2px solid var(--primary);
  color: var(--ink-strong);
  background: color-mix(in oklch, var(--surface-2) 58%, transparent);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px 11px;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 13px;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
}

.icon-button {
  width: 40px;
  background: transparent;
  color: var(--ink-strong);
}

.icon-button:hover {
  background: oklch(0.26 0.035 250);
}

.primary-button {
  min-width: 118px;
  padding: 0 18px;
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 12px 28px oklch(0.785 0.13 220 / 0.18);
}

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

.secondary-button {
  min-width: 118px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--ink);
}

.danger-button {
  min-width: 118px;
  padding: 0 16px;
  background: oklch(0.23 0.055 28);
  color: oklch(0.95 0.025 28);
}

.icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.store-filter select,
.search-control {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: oklch(0.14 0.018 250);
}

.store-filter select {
  min-width: 132px;
  padding: 0 30px 0 11px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 450;
}

.search-control {
  display: flex;
  align-items: center;
  width: min(360px, 30vw);
  padding: 0 8px 0 11px;
  color: var(--muted);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.search-control:focus-within {
  border-color: var(--primary);
  box-shadow: var(--focus);
}

.search-control > .icon {
  width: 17px;
  height: 17px;
}

.search-control input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 9px;
  font-size: 13px;
  font-weight: 400;
}

.search-clear {
  display: inline-grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
}

.search-clear:hover {
  background: var(--surface-3);
  color: var(--ink-strong);
}

.search-clear .icon {
  width: 15px;
  height: 15px;
}

.panel {
  padding: 0;
  overflow: clip;
}

.panel-title {
  display: flex;
  align-items: center;
  min-height: 52px;
  margin: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-strong);
  font-size: 18px;
  font-weight: 650;
}

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

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  grid-column: 1 / -1;
  padding-top: 18px;
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.field.accent-label span {
  color: var(--primary);
}

.field input,
.field select,
.field textarea,
.summary-form input,
.summary-form select {
  width: 100%;
  min-height: 34px;
  border: 1px solid oklch(0.34 0.035 250);
  border-radius: var(--radius-sm);
  background: oklch(0.225 0.018 250);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  padding: 0 10px;
}

.field textarea {
  min-height: 74px;
  padding: 10px 14px;
  resize: vertical;
}

::placeholder {
  color: oklch(0.67 0.025 250);
  opacity: 1;
}

.table-card {
  padding: 14px 16px 8px;
}

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

table {
  width: 100%;
  min-width: 1260px;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: var(--font-data);
}

.sales-table {
  min-width: 1660px;
}

.product-table {
  min-width: 1570px;
}

.expiry-table {
  min-width: 1436px;
}

thead th {
  height: 36px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

tbody td {
  height: 40px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}

th,
td {
  overflow: hidden;
  padding: 0 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tbody tr {
  background: var(--row);
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: var(--row-hover);
}

.sales-table tbody tr.store-row[data-store="digimium"] {
  background: var(--row-digimium);
}

.sales-table tbody tr.store-row[data-store="facebook"] {
  background: var(--row-facebook);
}

.sales-table tbody tr.store-row[data-store="telegram"] {
  background: var(--row-telegram);
}

.sales-table tbody tr.store-row[data-store="website"] {
  background: var(--row-website);
}

.sales-table tbody tr.store-row[data-store="digimium"]:hover {
  background: var(--row-digimium-hover);
}

.sales-table tbody tr.store-row[data-store="facebook"]:hover {
  background: var(--row-facebook-hover);
}

.sales-table tbody tr.store-row[data-store="telegram"]:hover {
  background: var(--row-telegram-hover);
}

.sales-table tbody tr.store-row[data-store="website"]:hover {
  background: var(--row-website-hover);
}

.sales-table tbody tr:first-child td {
  border-top-color: var(--line-strong);
}

.sales-table .total-row,
.sales-table .total-row:hover {
  background: transparent !important;
}

.sales-table .total-row td {
  height: 34px;
  border-top: 1px solid var(--line-strong);
  color: var(--ink);
  font-weight: 600;
}

.total-label {
  text-align: right;
}

.compact-table tbody tr {
  background: transparent;
}

.compact-table tbody tr:nth-child(even) {
  background: transparent;
}

.compact-table tbody td {
  border-top: 1px solid var(--line);
  height: 42px;
}

.number-cell {
  color: var(--ink);
  text-align: center;
}

.money-cell,
.date-cell {
  text-align: right;
}

.table-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}

.row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
}

.row-action:hover {
  background: var(--surface-3);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  padding: 8px 4px 0;
}

.table-pagination > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.table-pagination .secondary-button {
  min-width: 78px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: oklch(0.22 0.024 250);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  height: 28px;
  border: 1px solid oklch(0.55 0.15 150 / 0.7);
  border-radius: 8px;
  background: oklch(0.29 0.09 150 / 0.48);
  color: oklch(0.78 0.18 150);
  font-size: 13px;
  font-weight: 700;
}

.summary-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.summary-form label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.summary-form input,
.summary-form select {
  width: 124px;
  min-height: 32px;
}

.check-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

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

.metric {
  min-height: 94px;
  border: 1px solid oklch(0.255 0.028 250);
  border-radius: var(--radius);
  background: oklch(0.12 0.008 250);
  padding: 16px;
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
}

.metric-value {
  margin: 4px 0 0;
  color: var(--ink-strong);
  font-size: 26px;
  font-weight: 700;
  text-align: right;
}

.metric-delta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  text-align: right;
}

.settings-panel {
  margin-top: 20px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 20px;
  padding: 22px;
}

.settings-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: oklch(0.145 0.018 250);
  padding: 18px;
}

.settings-card h3 {
  margin: 0 0 16px;
  color: var(--ink-strong);
  font-size: 20px;
}

.stack {
  display: grid;
  gap: 14px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 800;
}

.app-loading,
.login-shell {
  min-height: 100vh;
  background: var(--bg);
}

.app-loading {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.login-shell {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(404px, 100%);
  border: 1px solid var(--line-strong);
  border-top-color: var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 38px 36px 36px;
}

.login-kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  text-transform: uppercase;
}

.login-logo {
  display: block;
  width: 128px;
  height: auto;
  margin: 0 auto 28px;
}

.setup-copy {
  margin: -10px 0 22px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
}

.login-panel .field + .field {
  margin-top: 14px;
}

.password-field {
  display: flex;
  gap: 8px;
}

.password-field input {
  min-width: 0;
  flex: 1;
}

.password-toggle {
  display: inline-grid;
  width: 40px;
  min-width: 40px;
  height: 34px;
  place-items: center;
  border: 1px solid oklch(0.34 0.035 250);
  border-radius: var(--radius-sm);
  background: oklch(0.225 0.018 250);
  color: var(--muted);
}

.password-toggle:hover {
  color: var(--ink-strong);
}

.login-error {
  min-height: 20px;
  margin: 8px 0 5px;
  color: oklch(0.78 0.16 28);
  font-size: 12px;
}

.success-message {
  color: var(--success);
}

.login-button {
  width: 100%;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 48px));
  transform: translateY(18px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: oklch(0.16 0.024 250);
  color: var(--ink-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  padding: 14px 16px;
  font-weight: 800;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 1080px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding: 18px 24px;
  }

  .brand {
    min-width: 0;
  }

  .nav {
    width: 100%;
    justify-content: flex-start;
    gap: 22px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

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

  .toolbar-group,
  .action-row,
  .summary-form {
    justify-content: flex-start;
  }

  .search-control {
    width: 100%;
  }

  .store-filter,
  .store-filter select {
    width: 100%;
  }

  .sync-indicator {
    margin-left: auto;
  }

  .settings-grid,
  .metrics,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  .container {
    width: min(100% - 24px, 1550px);
    padding-top: 14px;
  }

  .topbar {
    padding: 16px;
  }

  .nav-link {
    font-size: 17px;
  }

  .single-tab {
    min-width: 82px;
    padding-inline: 16px;
    font-size: 16px;
  }

  .primary-button,
  .secondary-button,
  .danger-button {
    min-width: auto;
    padding-inline: 18px;
  }

  .action-row {
    flex-wrap: wrap;
  }

  .action-row .search-control {
    order: -1;
    flex-basis: 100%;
  }

  .table-pagination {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .table-pagination > div {
    width: 100%;
    justify-content: space-between;
  }

  .login-panel {
    padding: 32px 22px 26px;
  }

  .summary-form input,
  .summary-form select {
    width: 100%;
  }

  .summary-form label {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
