:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --panel-soft: #fbfaf7;
  --ink: #22252a;
  --muted: #69707a;
  --line: #ded8cf;
  --sidebar: #242422;
  --sidebar-soft: #34342f;
  --gold: #d9a441;
  --teal: #24736b;
  --green: #2f7d4f;
  --orange: #b85f2d;
  --red: #b23b3b;
  --blue: #356a9a;
  --shadow: 0 16px 34px rgba(34, 37, 42, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

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

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

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 8px;
  background: var(--gold);
  color: #191817;
  font-weight: 800;
  letter-spacing: 0;
}

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

.brand h1 {
  font-size: 1.05rem;
  line-height: 1.2;
}

.brand p {
  margin-top: 3px;
  color: #d8d0c2;
  font-size: 0.86rem;
}

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

.tab-button {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #f7efe0;
  background: transparent;
  text-align: left;
  font-weight: 650;
}

.tab-button:hover,
.tab-button:focus-visible {
  border-color: rgba(255, 255, 255, 0.18);
  background: var(--sidebar-soft);
  outline: none;
}

.tab-button.is-active {
  color: #191817;
  background: #f0d48a;
}

.storage-summary {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.storage-summary span,
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.storage-summary span {
  color: #d8d0c2;
}

.storage-summary strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  color: #d8d0c2;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.sync-status::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 999px;
  background: var(--muted);
}

.sync-status.is-online::before {
  background: var(--green);
}

.sync-status.is-offline {
  color: #f0b8b8;
}

.sync-status.is-offline::before {
  background: var(--red);
}

.sync-status.is-connecting::before {
  background: var(--gold);
}

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

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

.topbar h2 {
  margin-top: 4px;
  font-size: clamp(1.45rem, 2.5vw, 2.1rem);
}

.view {
  display: none;
}

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

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  min-height: 102px;
  padding: 16px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric.sales {
  border-left-color: var(--green);
}

.metric.purchase {
  border-left-color: var(--orange);
}

.metric.payment {
  border-left-color: var(--red);
}

.metric.receipt {
  border-left-color: var(--blue);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.22rem;
  overflow-wrap: anywhere;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.split-layout,
.workspace-grid,
.backup-layout {
  display: grid;
  gap: 18px;
}

.split-layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.workspace-grid {
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  align-items: start;
}

.backup-layout {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}

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

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

.panel-header h3 {
  font-size: 1rem;
  line-height: 1.25;
}

.form-panel {
  padding-bottom: 16px;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: #33383f;
  font-size: 0.9rem;
  font-weight: 700;
}

.span-2 {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfc8bd;
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fffdf9;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(36, 115, 107, 0.15);
  outline: none;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.text-button,
.small-button {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 9px 12px;
  font-weight: 750;
  line-height: 1.1;
}

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

.primary-button:hover,
.primary-button:focus-visible {
  background: #1d625b;
  outline: none;
}

.secondary-button {
  border-color: #b9c6ce;
  color: #1d3f59;
  background: #eef6f8;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: var(--blue);
  outline: none;
}

.danger-button {
  color: #ffffff;
  background: var(--red);
}

.danger-button:hover,
.danger-button:focus-visible {
  background: #963232;
  outline: none;
}

.ghost-button,
.text-button {
  border-color: var(--line);
  color: var(--ink);
  background: var(--panel-soft);
}

.text-button {
  min-height: 32px;
  padding: 7px 10px;
}

.small-button {
  min-height: 30px;
  padding: 7px 9px;
  color: #26313a;
  background: #f3efe7;
  border-color: var(--line);
  font-size: 0.82rem;
}

.small-button.danger {
  color: #8a2929;
  background: #f8eeee;
}

.form-panel .primary-button {
  width: calc(100% - 32px);
  margin: 0 16px;
}

.table-header {
  align-items: flex-start;
}

.filters,
.button-row,
.button-grid {
  display: flex;
  gap: 10px;
}

.filters {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filters select,
.filters input,
.table-header > input {
  width: min(190px, 100%);
}

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

.table-wrap.tall {
  max-height: calc(100vh - 170px);
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #545b63;
  background: #faf8f3;
  font-size: 0.78rem;
  text-transform: uppercase;
}

td {
  font-size: 0.91rem;
}

.amount-cell,
.number-cell {
  text-align: right;
  white-space: nowrap;
}

.stock-cell {
  font-weight: 800;
}

.stock-cell.is-negative {
  color: var(--red);
}

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border-radius: 999px;
  padding: 4px 9px;
  background: #ede8df;
  color: #30333a;
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
}

.tag.purchase {
  color: #793a13;
  background: #f7e6d8;
}

.tag.sales {
  color: #1e5a35;
  background: #e1f0e5;
}

.tag.payment {
  color: #7d2525;
  background: #f5dede;
}

.tag.receipt {
  color: #214f75;
  background: #dfeefa;
}

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

.empty-cell {
  height: 110px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr;
  padding: 16px;
}

.button-row {
  padding: 0 16px 16px;
  flex-wrap: wrap;
}

.backup-stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  margin: 0;
  padding: 16px;
}

.backup-stats dt {
  color: var(--muted);
  font-weight: 700;
}

.backup-stats dd {
  margin: 0;
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #1f2a32;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .split-layout,
  .workspace-grid,
  .backup-layout {
    grid-template-columns: 1fr;
  }

  .table-wrap.tall {
    max-height: none;
  }
}

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

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

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

  .main-content {
    padding: 16px;
  }

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

  .filters,
  .filters select,
  .filters input,
  .table-header > input {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .form-grid,
  .metrics-grid,
  .nav-tabs {
    grid-template-columns: 1fr;
  }

  .brand {
    align-items: flex-start;
  }
}
