:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #fbfcfd;
  --text: #172033;
  --muted: #6e7787;
  --border: #e6e9ef;
  --green: #189a42;
  --orange: #ff6a00;
  --red: #ef3b35;
  --blue: #3f6ee8;
  --amber: #e99a13;
  --shadow: 0 12px 28px rgba(20, 31, 48, 0.06);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 224px;
  padding: 24px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 28px;
  z-index: 5;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  padding: 0 8px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 2px solid var(--orange);
  color: var(--orange);
  border-radius: var(--radius);
  font-weight: 800;
}

.brand strong,
.profile-button strong {
  display: block;
  font-size: 16px;
  line-height: 1.2;
}

.brand small,
.profile-button small {
  color: var(--muted);
  font-size: 12px;
}

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

.nav-list a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  color: #2c3446;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 14px;
  outline: 0;
}

.nav-list a span {
  width: 22px;
  font-size: 11px;
  font-weight: 800;
  color: #536075;
}

.nav-list a.active,
.nav-list a:hover {
  color: var(--orange);
  background: #fff3e8;
}

.nav-list a:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(255, 106, 0, 0.35);
}

.branch-card {
  margin-top: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-soft);
}

.branch-card span,
.branch-card strong {
  display: block;
  padding: 10px 12px 0;
  font-size: 12px;
}

.branch-card strong {
  padding-top: 4px;
  padding-bottom: 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.branch-card strong:last-child {
  border-bottom: 0;
}

.app-shell {
  margin-left: 224px;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 68px;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: #344055;
  cursor: pointer;
}

.menu-button span {
  width: 16px;
  height: 2px;
  background: currentColor;
  display: block;
}

.search-box {
  position: relative;
  min-width: 260px;
  max-width: 560px;
  flex: 1;
  height: 42px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 18;
  max-height: 360px;
  overflow-y: auto;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.14);
}

.search-result {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 6px;
  min-height: 52px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  text-align: left;
  cursor: pointer;
}

.search-result:hover,
.search-result.active {
  background: #fff3e8;
}

.search-result strong,
.search-result small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result small {
  color: var(--muted);
}

.search-result b {
  grid-row: span 2;
  align-self: center;
  color: var(--orange);
  font-size: 12px;
}

.search-box input {
  border: 0;
  outline: 0;
  flex: 1;
  min-width: 0;
  color: var(--text);
}

kbd {
  border: 1px solid var(--border);
  background: #f7f8fb;
  color: #6b7280;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
}

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

.select-shell {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0 12px;
}

select {
  border: 0;
  outline: 0;
  background: transparent;
}

.has-dot {
  position: relative;
}

.has-dot::after {
  content: "8";
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: white;
  border-radius: 999px;
  font-size: 10px;
  line-height: 16px;
  width: 16px;
  height: 16px;
}

.profile-button {
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #1f2937;
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.content {
  padding: 22px;
}

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

.page-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.page-header p,
.muted-text {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.kpi-grid,
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card,
.panel,
.action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi-card {
  min-height: 152px;
  padding: 22px 18px 12px;
  overflow: hidden;
}

.kpi-head {
  display: flex;
  gap: 18px;
  align-items: center;
}

.kpi-head span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.kpi-head strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  flex: none;
}

.metric-icon.green { background: var(--green); }
.metric-icon.orange { background: var(--orange); }
.metric-icon.red { background: var(--red); }

svg {
  width: 22px;
  height: 22px;
}

svg path {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.kpi-card p {
  margin: 12px 0 0 68px;
  font-size: 13px;
}

.positive { color: var(--green); }
.negative { color: var(--red); }

.sparkline {
  width: 100%;
  height: 48px;
  margin-top: 2px;
}

.sparkline polyline {
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sparkline .green { stroke: var(--green); }
.sparkline .orange { stroke: var(--orange); }
.sparkline .red { stroke: var(--red); }

.dashboard-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.95fr);
  gap: 16px;
}

.dashboard-grid > * {
  min-width: 0;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-header {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.segmented button {
  border: 0;
  background: var(--surface);
  padding: 8px 13px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
}

.segmented button.active {
  color: var(--orange);
  background: #fff3e8;
}

.chart-wrap {
  height: 284px;
}

#salesChart {
  width: 100%;
  height: 100%;
}

.chart-grid line {
  stroke: #e7eaf0;
  stroke-dasharray: 3 4;
}

.chart-grid text,
.chart-labels text {
  fill: #5f6878;
  font-size: 11px;
}

.chart-labels text {
  text-anchor: middle;
}

.x-date {
  font-size: 12px;
  fill: #7d8592;
}

.chart-area {
  fill: rgba(255, 106, 0, 0.12);
}

.chart-line {
  fill: none;
  stroke: var(--orange);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dots circle {
  fill: var(--orange);
  stroke: white;
  stroke-width: 4;
}

.product-list,
.stock-list {
  display: grid;
}

.product-row,
.stock-row {
  min-height: 52px;
  display: grid;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.product-row {
  grid-template-columns: 38px minmax(0, 1fr) 58px 86px;
}

.product-row:last-child,
.stock-row:last-child {
  border-bottom: 0;
}

.sku,
.mini-box {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
}

.product-row strong,
.stock-row strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.product-row b {
  text-align: right;
}

.transactions-panel {
  min-height: 320px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  font-size: 13px;
}

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

th {
  color: #556071;
  font-weight: 700;
  font-size: 12px;
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: #e7f6eb;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.badge.return {
  background: #ffe8e6;
  color: var(--red);
}

.stock-row {
  grid-template-columns: 38px minmax(0, 1fr) 70px 88px;
}

.mini-box {
  background: #f1f5f9;
  color: #516072;
}

.stock-count {
  color: var(--red);
  font-weight: 800;
}

.quick-actions {
  margin-top: 16px;
}

.action-card {
  min-height: 84px;
  border: 1px solid var(--border);
  padding: 16px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 24px;
  grid-template-rows: auto auto;
  align-items: center;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.action-card span {
  grid-row: span 2;
  grid-column: 1;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
}

.action-card strong,
.action-card small {
  grid-column: 2;
}

.action-card small {
  color: var(--muted);
}

.action-card b {
  grid-column: 3;
  grid-row: span 2;
  font-size: 22px;
  font-weight: 400;
}

.action-card.orange { background: #fff7f0; }
.action-card.green { background: #f1fbf4; }
.action-card.blue { background: #f4f7ff; }
.action-card.amber { background: #fffaf0; }
.action-card.orange span { color: var(--orange); }
.action-card.green span { color: var(--green); }
.action-card.blue span { color: var(--blue); }
.action-card.amber span { color: var(--amber); }

.empty-state,
.empty-cell {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
}

.modal {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
  padding: 18px;
}

.action-form {
  display: grid;
  gap: 14px;
}

.action-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.action-form input {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--text);
}

.primary-button {
  height: 44px;
  border: 0;
  border-radius: var(--radius);
  color: white;
  background: var(--orange);
  font-weight: 800;
  cursor: pointer;
}

.primary-button.small {
  width: auto;
  padding: 0 16px;
}

.pos-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
  gap: 16px;
}

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

.pos-product {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: var(--radius);
  min-height: 82px;
  padding: 12px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 10px;
  text-align: left;
  cursor: pointer;
}

.pos-product strong,
.cart-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pos-product .sku {
  grid-row: span 2;
}

.pos-product small {
  color: var(--muted);
}

.cart-panel {
  align-self: start;
}

.cart-list {
  display: grid;
  gap: 8px;
  min-height: 180px;
}

.bill-fields {
  display: grid;
  grid-template-columns: 1fr 130px;
  gap: 10px;
  margin-bottom: 14px;
}

.bill-fields label,
.bill-summary label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.bill-fields input,
.bill-fields select,
.bill-summary input,
.qty-control input {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
}

.cart-row,
.cart-total,
.inventory-row {
  display: grid;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  font-size: 13px;
}

.cart-row {
  grid-template-columns: minmax(0, 1fr) 112px auto 58px;
  align-items: center;
}

.cart-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.cart-row strong {
  white-space: normal;
}

.qty-control {
  display: grid;
  grid-template-columns: 30px 44px 30px;
  gap: 4px;
}

.qty-control button,
.remove-button {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  cursor: pointer;
}

.qty-control input {
  height: 34px;
  padding: 0 4px;
  text-align: center;
}

.remove-button {
  color: var(--red);
  font-size: 12px;
}

.bill-summary {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 12px;
}

.bill-summary > div,
.cart-total {
  grid-template-columns: minmax(0, 1fr) auto;
  border-bottom: 0;
  margin-top: 0;
  padding-top: 0;
  font-size: 16px;
}

.bill-summary > div {
  display: grid;
  align-items: center;
  font-size: 13px;
}

.inventory-row {
  grid-template-columns: 38px minmax(0, 1fr) 120px 130px 100px;
}

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

.settings-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.settings-grid input {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-soft);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: 320px;
  padding: 12px 14px;
  color: white;
  background: #172033;
  border-radius: var(--radius);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
  font-size: 13px;
}

.nav-collapsed .sidebar {
  transform: translateX(-100%);
}

.nav-collapsed .app-shell {
  margin-left: 0;
}

@media (max-width: 1100px) {
  .kpi-grid,
  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .pos-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .app-shell {
    margin-left: 0;
  }

  .topbar {
    height: auto;
    flex-wrap: wrap;
  }

  .search-box {
    order: 3;
    max-width: none;
    width: 100%;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .select-shell,
  .profile-button span:not(.avatar),
  kbd {
    display: none;
  }

  .content {
    padding: 14px;
  }

  .kpi-grid,
  .quick-actions {
    grid-template-columns: 1fr;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .pos-products,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .bill-fields {
    grid-template-columns: 1fr;
  }

  .cart-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .cart-row .qty-control,
  .cart-row .remove-button {
    grid-column: 1 / -1;
  }

  .cart-row .remove-button {
    width: 100%;
  }

  .inventory-row {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .inventory-row span,
  .inventory-row button {
    grid-column: 2;
  }

  .chart-wrap {
    height: 240px;
  }

  .toast {
    top: 12px;
    right: 12px;
    bottom: auto;
    left: 12px;
    max-width: none;
    text-align: center;
  }
}

@media (max-width: 760px) {
  body:not(.nav-open) .sidebar {
    transform: translateX(-100%);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }
}
