:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d7dde8;
  --accent: #1967d2;
  --accent-ink: #ffffff;
  --good: #137a47;
  --warn: #b45309;
  --bad: #b42318;
  --soft-blue: #eaf2ff;
  --soft-green: #e9f7ef;
  --soft-red: #fff0ed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

.app-header {
  align-items: center;
  background: #253043;
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: 22px 28px;
}

.app-header h1 {
  font-size: 24px;
  margin: 2px 0 0;
}

.eyebrow {
  color: #b8c5d9;
  font-size: 13px;
  margin: 0;
}

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

.app-shell {
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 1440px;
  padding: 18px;
}

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

.metric,
.entry-panel,
.controls,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 16px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 6px;
}

.metric.warning {
  background: var(--soft-red);
  border-color: #ffd2ca;
}

.entry-panel {
  padding: 14px;
}

.movement-form {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: 1.1fr 1.4fr 1fr .8fr 1fr 1.4fr auto;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 5px;
}

label[hidden] {
  display: none;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #c7ceda;
  border-radius: 6px;
  color: var(--ink);
  min-height: 38px;
  padding: 7px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(25, 103, 210, .16);
}

.primary-btn,
.secondary-btn,
.header-primary-btn,
.ghost-btn,
.tab {
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  padding: 8px 12px;
}

.primary-btn {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.header-primary-btn {
  background: #fff;
  border: 1px solid #fff;
  color: #174ea6;
  font-weight: 750;
}

.secondary-btn {
  background: #fff;
  border: 1px solid #c7ceda;
  color: #344054;
}

.danger-btn {
  background: #fff;
  border: 1px solid #d92d20;
  border-radius: 6px;
  color: #b42318;
  cursor: pointer;
  font-weight: 700;
  min-height: 38px;
  padding: 8px 12px;
}

.danger-btn:hover {
  background: var(--soft-red);
}

.danger-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.ghost-btn {
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .32);
  color: #fff;
}

.ghost-btn.danger {
  border-color: rgba(255, 170, 160, .7);
  color: #ffd8d2;
}

.controls {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tab {
  background: #f4f6fa;
  border: 1px solid #cfd6e2;
  color: #344054;
  font-weight: 650;
}

.tab.active {
  background: var(--soft-blue);
  border-color: #8bb8f8;
  color: #174ea6;
}

.filters {
  display: grid;
  gap: 8px;
  grid-template-columns: 180px 300px;
}

.product-navigation {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.product-navigation[hidden] {
  display: none;
}

.product-navigation .secondary-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.table-wrap {
  overflow: auto;
  position: relative;
}

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

th,
td {
  border-bottom: 1px solid #e7ebf2;
  font-size: 13px;
  padding: 9px 10px;
  text-align: center;
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #475467;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

td.num,
th.num {
  text-align: center;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
}

.badge.good {
  background: var(--soft-green);
  color: var(--good);
}

.badge.bad {
  background: var(--soft-red);
  color: var(--bad);
}

.badge.warn {
  background: #fff6df;
  color: var(--warn);
}

.empty-state {
  color: var(--muted);
  display: none;
  padding: 26px;
  text-align: center;
}

.row-edit-btn,
.row-stock-btn {
  background: #fff;
  border: 1px solid #b8c5d9;
  border-radius: 5px;
  color: #174ea6;
  cursor: pointer;
  min-height: 30px;
  padding: 4px 9px;
}

.row-delete-btn {
  background: #fff;
  border: 1px solid #d92d20;
  border-radius: 5px;
  color: var(--bad);
  cursor: pointer;
  min-height: 30px;
  padding: 4px 9px;
}

.row-delete-btn:hover {
  background: var(--soft-red);
}

.row-stock-btn {
  background: var(--soft-blue);
  border-color: #8bb8f8;
}

.stock-current {
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  margin: 16px 0;
  padding: 12px 14px;
}

.stock-current span {
  color: var(--muted);
  font-size: 13px;
}

.stock-current strong {
  font-size: 22px;
}

.product-link {
  background: none;
  border: 0;
  color: #174ea6;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.product-link:hover {
  color: #0b418f;
}

.edit-dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(31, 41, 55, .24);
  color: var(--ink);
  max-width: 620px;
  padding: 0;
  width: calc(100% - 32px);
}

.edit-dialog::backdrop {
  background: rgba(31, 41, 55, .48);
}

.edit-dialog form {
  padding: 20px;
}

.dialog-heading,
.dialog-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.dialog-heading h2 {
  font-size: 20px;
  margin: 3px 0 0;
}

.dialog-vendor {
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  align-items: center;
  background: #f4f6fa;
  border: 1px solid #cfd6e2;
  border-radius: 6px;
  color: #344054;
  cursor: pointer;
  display: inline-flex;
  font-size: 22px;
  height: 36px;
  justify-content: center;
  padding: 0;
  width: 36px;
}

.edit-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.wide-field {
  grid-column: 1 / -1;
}

.dialog-actions {
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

.dialog-actions button {
  min-width: 86px;
}

.manage-fields {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 18px;
}

.manage-note {
  background: var(--soft-red);
  border-left: 3px solid #d92d20;
  color: #7a271a;
  font-size: 13px;
  line-height: 1.5;
  margin: 16px 0 0;
  padding: 10px 12px;
}

.manage-actions {
  flex-wrap: wrap;
}

.blank-date {
  color: #98a2b3;
}

@media (max-width: 980px) {
  .app-header,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

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

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

  .memo-field,
  .primary-btn {
    grid-column: 1 / -1;
  }

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

@media (max-width: 560px) {
  .metrics,
  .movement-form,
  .edit-grid,
  .manage-fields {
    grid-template-columns: 1fr;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .wide-field {
    grid-column: auto;
  }
}
