:root {
  --bg: #FAF6F0;
  --sand: #EFE8DC;
  --paper: #FFFFFF;
  --ink: #292018;
  --muted: #6C5B4D;
  --border: #DFD5C6;
  --matcha: #2F6F4E;
  --matcha-dark: #23553B;
  --matcha-soft: #DCFCE7;
  --terra: #C2410C;
  --terra-soft: #FFEDD5;
  --rose: #BE123C;
  --rose-soft: #FFE4E6;
  --radius: 16px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
}

.app-shell {
  inline-size: min(1340px, 100%);
  margin-inline: auto;
  padding: 20px clamp(16px, 3vw, 32px) 56px;
}

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tag-store {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--matcha-soft);
  color: var(--matcha);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 999px;
}

.tag-storage {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sand);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
}
.tag-storage.online {
  background: #ECFEFF;
  border-color: #A5F3FC;
  color: #0E7490;
}
.tag-storage.warn {
  background: var(--terra-soft);
  border-color: #FDBA74;
  color: var(--terra);
}

.app-header h1 {
  margin: 8px 0 4px;
  font-size: clamp(23px, 2.8vw, 31px);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sub {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.header-right {
  display: grid;
  gap: 10px;
  justify-items: end;
}
@media (max-width: 820px) {
  .header-right {
    justify-items: start;
    inline-size: 100%;
  }
}

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

.head-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  font-weight: 700;
}

.head-pill {
  background: var(--paper);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}
.head-pill.up {
  background: var(--rose-soft);
  border-color: #FECDD3;
  color: var(--rose);
}
.head-pill.down {
  background: var(--matcha-soft);
  border-color: #BBF7D0;
  color: var(--matcha);
}

/* Buttons & Inputs */
.btn-primary {
  border: 0;
  background: var(--matcha);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-primary:hover {
  background: var(--matcha-dark);
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  font-size: 12.5px;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn-secondary:hover {
  background: var(--sand);
}

.btn-danger {
  border: 1px solid #FECDD3;
  background: var(--rose-soft);
  color: var(--rose);
  font-weight: 700;
  font-size: 12.5px;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.btn-danger:hover {
  background: #FECDD3;
}

/* Top Cards */
.top-cards {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
@media (max-width: 900px) {
  .top-cards {
    grid-template-columns: 1fr;
  }
}

.warm-card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: 0 2px 10px rgba(41, 32, 24, 0.04);
}
.warm-card h2 {
  margin: 0 0 5px;
  font-size: 16.5px;
}
.card-help {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.wa-card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.wa-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.file-btn {
  position: relative;
  overflow: hidden;
}
.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.wa-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
@media (max-width: 620px) {
  .wa-row {
    grid-template-columns: 1fr;
  }
}

.wa-row textarea {
  inline-size: 100%;
  min-block-size: 92px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  resize: vertical;
}

.wa-side-actions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-inline-size: 185px;
}
.wa-side-actions input[type="date"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
}
.wa-date-field {
  display: grid;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
}
.wa-date-field input[type="date"] {
  inline-size: 100%;
}

.wa-foot {
  margin-top: 9px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.check-lbl {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.check-lbl input {
  inline-size: 16px;
  block-size: 16px;
  accent-color: var(--matcha);
}
.sync-msg {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--matcha);
}

.profit-box {
  background: linear-gradient(145deg, #F0FDF4 0%, #FAF6F0 100%);
  border-color: #BBF7D0;
  display: grid;
  gap: 10px;
  align-content: start;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.p-btn {
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.p-btn.active {
  background: var(--matcha);
  color: #FFFFFF;
  border-color: var(--matcha);
}
.presets input[type="range"] {
  accent-color: var(--matcha);
  flex: 1 1 120px;
}

/* Tabs (modern-web-guidance) */
[role="tablist"] {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
[role="tablist"]::-webkit-scrollbar {
  display: none;
}
[role="tablist"] button {
  position: relative;
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 700;
  padding: 11px 15px;
  cursor: pointer;
  white-space: nowrap;
}
[role="tablist"] button[aria-selected="true"] {
  color: var(--matcha);
}
[role="tablist"] button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 3px solid var(--matcha);
}

.panels-grid {
  display: grid;
}
[role="tabpanel"] {
  grid-area: 1 / 1;
  min-block-size: 0;
}
[role="tabpanel"][hidden="until-found"] {
  visibility: hidden;
  pointer-events: none;
  block-size: 0;
  overflow: hidden;
}

/* Filter bar */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.filter-row input,
.filter-row select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
}
.filter-row input[type="search"] {
  flex: 1 1 250px;
}
.shown-count {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  margin-inline-start: auto;
  font-variant-numeric: tabular-nums;
}

/* Responsive + Sortable Table */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(600px, 70dvh);
  border: 1px solid var(--border);
  border-radius: 12px;
  container-type: inline-size;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}
.table-wrapper:focus-visible {
  outline: 2px solid var(--matcha);
  outline-offset: 2px;
}
table {
  inline-size: 100%;
  min-inline-size: 800px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
caption {
  text-align: start;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--sand);
  border-bottom: 1px solid var(--border);
}
thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--sand);
}
th[scope="col"] {
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  background: var(--sand);
  white-space: nowrap;
}
th[scope="col"]:not(:has(> button)) {
  padding: 10px 12px;
  text-align: start;
}
th[scope="col"]:has(> button) {
  padding: 0;
}
th[scope="col"] > button {
  inline-size: 100%;
  min-block-size: 38px;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  text-align: start;
}
th[scope="col"] > button:hover {
  background: #E3DACB;
  color: var(--ink);
}
th[scope="col"] > button:focus-visible {
  outline: 2px solid var(--matcha);
  outline-offset: -2px;
}
th[aria-sort] {
  color: var(--matcha);
}
.sort-ic::after {
  content: "↕";
  opacity: 0.35;
}
th[aria-sort="ascending"] .sort-ic::after {
  content: "▲";
  opacity: 1;
}
th[aria-sort="descending"] .sort-ic::after {
  content: "▼";
  opacity: 1;
}

tbody tr[hidden] {
  display: none;
}
tbody tr {
  view-transition-name: match-element;
}
tbody tr:hover td,
tbody tr:hover th[scope="row"] {
  background: #FAF6F0;
}
tbody tr.just-updated td,
tbody tr.just-updated th[scope="row"] {
  background: #F0FDF4;
}
tbody th[scope="row"] {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--paper);
  text-align: start;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.num {
  text-align: end;
}
.unit-sub {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}
.old-strike {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-decoration: line-through;
}
.ecer-sub {
  display: block;
  font-size: 11px;
  color: var(--terra);
  font-weight: 700;
}
.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.pill.up {
  background: var(--rose-soft);
  color: var(--rose);
}
.pill.down {
  background: var(--matcha-soft);
  color: var(--matcha);
}
.pill.flat {
  background: var(--sand);
  color: var(--muted);
}
.pill.new {
  background: var(--terra-soft);
  color: var(--terra);
  margin-inline-start: 6px;
}
.pill.manual {
  background: #FEF3C7;
  color: #92400E;
  font-size: 10.5px;
  padding: 1px 6px;
  margin-inline-start: 4px;
}

.btn-row-edit {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-row-edit:hover {
  background: var(--matcha);
  color: #FFFFFF;
  border-color: var(--matcha);
}

/* Brand Shelves */
.brand-shelf {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--bg);
}
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.shelf-item {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 12.5px;
  text-align: start;
  cursor: pointer;
  display: grid;
  gap: 5px;
}
.shelf-item:hover {
  border-color: var(--matcha);
}

/* Monthly & Top Sales */
.sales-split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}
.monthly-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.m-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12px;
}
.m-card strong {
  display: block;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.top-item {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 13px;
}
.bar-track {
  inline-size: 100%;
  block-size: 8px;
  background: var(--sand);
  border-radius: 999px;
  overflow: clip;
}
.bar-fill {
  block-size: 100%;
  background: var(--matcha);
  border-radius: 999px;
}

/* Archive Cards */
.tx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.tx-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px;
}
.tx-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 8px;
  padding-bottom: 7px;
  border-bottom: 1px dashed var(--border);
}

/* Native <dialog> Modals (modern-web-guidance) */
dialog {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  inline-size: min(560px, calc(100% - 24px));
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(41, 32, 24, 0.24);
}
dialog:modal {
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(41, 32, 24, 0.55);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dlg-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--sand);
}
.dlg-head h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}
.dlg-body {
  padding: 16px 20px 20px;
  max-block-size: 74dvh;
  overflow-y: auto;
  display: grid;
  gap: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 520px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}
.field {
  display: grid;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}
.field input,
.field select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
}
.dlg-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 6px;
}
.hist-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}
.hist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12.5px;
}
.hist-item.current {
  border-color: var(--matcha);
  background: #F0FDF4;
}

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: clip;
  clip-path: inset(50%);
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none;
  }
}

@container (width < 680px) {
  table {
    min-inline-size: 0;
    --label-2: "Jenis";
    --label-3: "Harga Terbaru";
    --label-4: "Patokan Jual";
    --label-5: "Naik / Turun";
    --label-6: "Terakhir Update";
    --label-7: "Aksi";
  }
  table, thead, tbody, tr, th, td {
    display: block;
  }
  thead {
    display: none;
  }
  tbody tr {
    margin: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: clip;
  }
  tbody th[scope="row"] {
    position: sticky;
    inset-block-start: 0;
    background: var(--sand);
    z-index: 2;
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: normal;
    text-align: end;
  }
  tbody td:nth-child(2)::before { content: var(--label-2) ": "; color: var(--muted); font-weight: 600; }
  tbody td:nth-child(3)::before { content: var(--label-3) ": "; color: var(--muted); font-weight: 600; }
  tbody td:nth-child(4)::before { content: var(--label-4) ": "; color: var(--muted); font-weight: 600; }
  tbody td:nth-child(5)::before { content: var(--label-5) ": "; color: var(--muted); font-weight: 600; }
  tbody td:nth-child(6)::before { content: var(--label-6) ": "; color: var(--muted); font-weight: 600; }
  tbody td:nth-child(7)::before { content: var(--label-7) ": "; color: var(--muted); font-weight: 600; }
}

@media print {
  .no-print,
  .top-cards,
  [role="tablist"],
  .filter-row,
  .head-actions,
  .col-action {
    display: none !important;
  }
  .table-wrapper {
    max-block-size: none;
    overflow: visible;
    border: 0;
  }
  body {
    background: #FFFFFF;
  }
}
