:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dce5f1;
  --blue: #2563eb;
  --green: #16a34a;
  --teal: #0f766e;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(22, 32, 51, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  padding: 12px clamp(16px, 4vw, 44px);
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  margin-right: auto;
  font-size: 20px;
  font-weight: 900;
  color: var(--blue);
}

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

.navlinks a,
.logout {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 800;
}

.logout {
  color: var(--red);
}

.shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.login-wrap {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.login-card,
.install-card,
.empty-state,
.metric,
.chart-panel,
.table-panel,
.low-stock {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card,
.install-card {
  width: min(440px, 100%);
  padding: 28px;
}

.install-card {
  margin: 40px auto;
}

.login-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 28px;
  font-weight: 900;
}

h1 {
  margin: 14px 0 6px;
  font-size: clamp(28px, 5vw, 42px);
  letter-spacing: 0;
}

.login-card p,
.empty-state p,
.sync-info span,
.metric span,
.security-note {
  color: var(--muted);
}

label {
  display: block;
  margin: 16px 0 7px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  font: inherit;
  background: #fff;
}

input:focus,
select:focus {
  outline: 3px solid rgba(37, 99, 235, .16);
  border-color: var(--blue);
}

.primary-btn,
.filter-bar button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 900;
  padding: 0 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.login-card .primary-btn {
  width: 100%;
  margin-top: 22px;
}

.alert {
  margin: 14px 0;
  padding: 12px;
  border-radius: 8px;
  font-weight: 800;
}

.danger {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
}

.success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin: 8px 0 22px;
}

.eyebrow,
.back-link {
  color: var(--blue);
  font-weight: 900;
}

.sync-info {
  min-width: 230px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sync-info span,
.sync-info strong,
.sync-info small {
  display: block;
}

.sync-info small {
  margin-top: 6px;
  color: var(--amber);
  font-weight: 800;
}

.dashboard-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.big-action {
  min-height: 168px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: 8px;
  color: #fff;
  box-shadow: var(--shadow);
}

.big-action span {
  font-size: 22px;
  font-weight: 900;
}

.big-action strong {
  font-size: 18px;
}

.big-action.sales { background: var(--blue); }
.big-action.products { background: var(--green); }
.big-action.stock { background: var(--teal); }
.big-action.debt { background: #7c3aed; }
.big-action.supplier { background: #0891b2; }
.big-action.personnel { background: #9333ea; }
.big-action.expenses { background: #db2777; }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 180px)) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.stock-filter {
  grid-template-columns: minmax(180px, 1fr) auto;
}

.report-filter {
  grid-template-columns: repeat(2, minmax(0, 180px)) auto;
}

.product-filter {
  grid-template-columns: repeat(2, minmax(0, 160px)) minmax(220px, 1fr) minmax(190px, 1fr) minmax(180px, 1fr) auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.metric-grid.wide,
.product-summary {
  grid-template-columns: repeat(4, 1fr);
}

.metric,
.chart-panel,
.table-panel,
.empty-state,
.low-stock {
  padding: 18px;
  margin-bottom: 16px;
}

.metric {
  padding: 14px;
}

.metric span,
.metric strong {
  display: block;
}

.metric strong {
  margin-top: 6px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.table-panel h2,
.low-stock h2,
.chart-panel h2 {
  margin: 0 0 14px;
  font-size: 22px;
}

.muted-text {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.tone-positive {
  color: var(--green) !important;
}

.tone-negative {
  color: var(--red) !important;
}

.tone-neutral {
  color: var(--muted) !important;
}

.amount-cell {
  font-weight: 900;
  white-space: nowrap;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th {
  text-align: left;
  color: var(--muted);
  font-size: 13px;
  padding: 11px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 13px 11px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.compact-table {
  min-width: 640px;
}

.compact-table th,
.compact-table td {
  padding: 10px;
  font-size: 12px;
}

.distribution-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.compact-panel {
  min-height: 100%;
}

.legend-list,
.bar-list {
  display: grid;
  gap: 10px;
}

.legend-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-weight: 800;
}

.legend-row:last-child {
  border-bottom: 0;
}

.legend-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend-row small {
  color: var(--muted);
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.bar-head span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.bar-head strong {
  white-space: nowrap;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: #e8eef8;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.bar-fill.negative {
  background: linear-gradient(90deg, #ef4444, #dc2626);
}

.chart-bar-list {
  gap: 13px;
}

.chart-bar-row {
  padding: 2px 0;
}

.chart-bar-row .bar-head {
  color: var(--text);
}

.chart-bar-row .bar-head span {
  font-size: 14px;
}

.chart-bar-row .bar-track {
  height: 13px;
}

.warning-row td {
  background: #fff7ed;
  color: #9a3412;
}

.low-stock-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.low-stock-grid div {
  border: 1px solid #fed7aa;
  background: #fff7ed;
  border-radius: 8px;
  padding: 12px;
}

.low-stock-grid strong,
.low-stock-grid span {
  display: block;
}

.low-stock-grid span {
  color: #9a3412;
  margin-top: 5px;
  font-weight: 800;
}

canvas {
  width: 100%;
  height: 140px;
  max-height: 140px;
  display: block;
}

.chart-panel canvas {
  min-height: 0;
}

.chart-panel {
  overflow: hidden;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .navlinks {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .navlinks a {
    white-space: nowrap;
  }

  .page-head,
  .dashboard-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .sync-info {
    min-width: 0;
  }

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

  .filter-bar,
  .stock-filter,
  .report-filter,
  .product-filter {
    grid-template-columns: 1fr;
  }

  .filter-bar span {
    display: none;
  }

  .low-stock-grid,
  .distribution-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  h1 {
    font-size: clamp(25px, 8vw, 34px);
  }

  .table-panel {
    padding: 14px;
  }

  .chart-panel {
    padding: 12px;
    margin-bottom: 12px;
  }

  .table-panel h2,
  .low-stock h2,
  .chart-panel h2 {
    font-size: 17px;
    margin-bottom: 8px;
  }

  .table-scroll {
    overflow: visible;
  }

  .table-scroll table,
  .table-scroll thead,
  .table-scroll tbody,
  .table-scroll tr,
  .table-scroll th,
  .table-scroll td,
  table.compact-table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .table-scroll thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .table-scroll tr {
    margin: 0 0 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 10px 22px rgba(22, 32, 51, .06);
  }

  .table-scroll tbody tr:last-child {
    margin-bottom: 0;
  }

  .table-scroll td,
  .compact-table td {
    min-height: 34px;
    display: grid;
    grid-template-columns: minmax(98px, 42%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 8px 0;
    border-bottom: 1px solid #eef2f7;
    font-size: 13px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  .table-scroll td:last-child {
    border-bottom: 0;
  }

  .table-scroll td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 900;
  }

  .warning-row td {
    background: transparent;
    color: inherit;
  }

  .warning-row {
    background: #fff7ed !important;
    border-color: #fed7aa !important;
  }

  .legend-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .bar-head {
    display: grid;
    gap: 4px;
  }

  .chart-bar-list {
    gap: 11px;
  }

  .chart-bar-row .bar-head {
    grid-template-columns: 1fr;
  }

  .chart-bar-row .bar-head span,
  .chart-bar-row .bar-head strong {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .chart-bar-row .bar-track {
    height: 12px;
  }

  canvas {
    height: 104px;
    max-height: 104px;
  }
}

@media (max-width: 520px) {
  .shell {
    width: min(100% - 18px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    padding: 10px;
  }

  .navlinks a,
  .logout {
    padding: 9px 10px;
    font-size: 14px;
  }

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

  .big-action {
    min-height: 132px;
  }

  .login-card,
  .install-card,
  .metric,
  .chart-panel,
  .table-panel,
  .low-stock {
    border-radius: 8px;
  }
}
