body.cashbacks-page {
  width: fit-content;
  min-width: min(100%, 28rem);
  max-width: 100%;
}

.cashbacks-panel {
  padding: 0;
  overflow: hidden;
  width: fit-content;
  max-width: 100%;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 12rem);
  width: fit-content;
  max-width: 100%;
}

.cashbacks-table {
  width: max-content;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.7rem;
}

.cashbacks-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.view-toggle {
  display: inline-flex;
  gap: 0.35rem;
  padding: 0.2rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.view-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.save-status {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 4.5rem;
}

.save-status.saved { color: var(--success); }
.save-status.error { color: var(--danger); }

.cashbacks-table th,
.cashbacks-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: middle;
  padding: 0;
}

.cashbacks-table .cat-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  width: 1%;
  min-width: 0;
  max-width: 9.5rem;
  padding: 0.2rem 0.35rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  border-right: 1px solid var(--border);
}

.cashbacks-table thead .cat-col {
  z-index: 4;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  vertical-align: bottom;
  padding: 0.3rem 0.35rem 0.35rem;
  white-space: normal;
}

.cashbacks-table thead .month-col {
  vertical-align: middle;
  padding: 0.25rem 0.3rem;
}

.month-select {
  width: 100%;
  max-width: 8.5rem;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.25rem;
  cursor: pointer;
}

.month-select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.cat-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
}

.cat-head-title {
  text-transform: uppercase;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.1;
}

.cat-search {
  width: 100%;
  min-width: 0;
  max-width: 8.5rem;
  box-sizing: border-box;
  padding: 0.25rem 0.35rem;
  font-size: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text);
  font-family: inherit;
}

.cat-search:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.cat-search-wrap.hidden { display: none !important; }

.cat-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 9rem;
}

.cat-emoji {
  flex: 0 0 auto;
  font-size: 0.85rem;
  line-height: 1;
}

.cat-name {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cashbacks-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
}

.cashbacks-table thead tr.group-row th {
  top: 0;
  z-index: 3;
  box-shadow: none;
}

.cashbacks-table thead tr.card-row th {
  top: var(--group-head-h, 1.55rem);
  z-index: 2;
  box-shadow: 0 1px 0 var(--border);
}

.group-label {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 0.35rem 0.25rem !important;
  background: var(--group-tint, var(--bg-subtle));
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.cashbacks-table tbody tr:hover .cat-col {
  background: var(--surface-hover);
}

.card-col {
  width: 1.55rem;
  min-width: 1.55rem;
  max-width: 1.55rem;
  background: var(--col-tint, transparent);
}

.card-head {
  padding: 0.15rem 0.04rem 0.12rem !important;
  text-align: center;
  vertical-align: bottom;
  cursor: pointer;
}

.card-head:hover {
  filter: brightness(0.97);
}

.card-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.card-head-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
}

.card-warn {
  font-size: 0.62rem;
  line-height: 1;
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
}

.card-warn:hover {
  filter: drop-shadow(0 0 1px rgba(217, 119, 6, 0.8));
}

.vmeta-line {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.06rem;
  min-height: 3.8rem;
  max-height: 3.8rem;
  max-width: 1.05rem;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.05;
}

.vtext {
  max-height: 1.75rem;
  overflow: hidden;
}

.vsep {
  color: var(--muted);
  font-size: 0.5rem;
  line-height: 1;
  opacity: 0.6;
  user-select: none;
}

.rate-cell {
  text-align: center;
  width: 1.55rem;
  min-width: 1.55rem;
  max-width: 1.55rem;
  background: var(--col-tint, transparent);
}

.rate-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  text-align: center;
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.65rem;
  padding: 0.2rem 0;
  color: var(--text);
}

.rate-input:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.65);
}

.rate-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.rate-cell.is-best {
  background: color-mix(in srgb, var(--success) 18%, var(--col-tint, #fff));
}

.rate-cell.is-best .rate-input {
  color: var(--success);
}

.group-start {
  border-left: 2px solid var(--group-border, #64748b) !important;
}

.group-end {
  border-right: 2px solid var(--group-border, #64748b) !important;
}

.group-row .group-start {
  border-top: 2px solid var(--group-border, #64748b) !important;
}

.group-row .group-label {
  border-top: 2px solid var(--group-border, #64748b) !important;
}

.cashbacks-table tbody tr:last-child td.group-start,
.cashbacks-table tbody tr:last-child td.group-end,
.cashbacks-table tbody tr:last-child td.rate-cell {
  border-bottom: 2px solid var(--group-border, #64748b);
}

.empty-hint {
  padding: 1rem 1.25rem;
  margin: 0;
}

.hidden { display: none !important; }

/* Card editor overlay */
.card-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(22rem, 92vw);
  box-shadow: var(--shadow-lg);
}

.card-editor::backdrop {
  background: rgba(15, 23, 42, 0.4);
}

.card-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.15rem 1.25rem 1.25rem;
}

.card-form h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.card-form .field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.card-form .field-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.optional {
  font-weight: 400;
  opacity: 0.8;
}

.card-form .field-input {
  width: 100%;
  box-sizing: border-box;
}

.card-form .color-field {
  width: 3rem;
  height: 2.25rem;
  padding: 0.15rem;
  cursor: pointer;
}

.field-color {
  align-items: flex-start;
}

.form-error {
  margin: 0;
  font-size: 0.8rem;
  color: var(--danger);
}

.card-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.card-form-actions-end {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.btn.danger {
  background: var(--danger-bg);
  border-color: #fecaca;
  color: var(--danger);
}

.btn.danger:hover:not(:disabled) {
  background: #fee2e2;
  border-color: var(--danger);
}

.btn.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
}

/* Warning advice overlay */
.warn-advice {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(26rem, 94vw);
  max-height: min(80vh, 32rem);
  box-shadow: var(--shadow-lg);
}

.warn-advice::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.warn-advice-inner {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.9rem 1rem 1rem;
  max-height: min(80vh, 32rem);
  overflow: auto;
}

.warn-advice-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.warn-advice-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
}

.warn-advice-summary {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.warn-advice-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.warn-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.warn-item.tier-1 {
  border-color: #86efac;
  background: var(--success-bg);
}

.warn-item.tier-2 {
  border-color: #fcd34d;
  background: var(--warn-bg);
}

.warn-item.tier-2.match-same {
  border-color: #93c5fd;
  background: #eff6ff;
}

.warn-item-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.warn-item-cat {
  font-size: 0.82rem;
  font-weight: 700;
}

.warn-item-detail {
  font-size: 0.72rem;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

.warn-item-why {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
}

/* History tab */
.history-panel {
  padding: 0.85rem 1rem 1rem;
  width: min(100%, 1100px);
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(11rem, 14rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.history-list-wrap h2 {
  margin: 0 0 0.2rem;
  font-size: 0.95rem;
}

.history-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: calc(100vh - 16rem);
  overflow: auto;
}

.history-item {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.history-item-main {
  flex: 1;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0.45rem 0.55rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.history-item.active .history-item-main,
.history-item-main:hover {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.history-item-title {
  font-size: 0.8rem;
  font-weight: 700;
}

.history-item-meta {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.history-preview-meta {
  margin: 0 0 0.55rem;
}

.history-table-wrap {
  max-width: 100%;
}

.history-table .card-head {
  cursor: default;
}

.history-table .rate-cell {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.65rem;
  padding: 0.25rem 0.05rem;
  text-align: center;
}

@media (max-width: 800px) {
  .history-layout {
    grid-template-columns: 1fr;
  }
}
