:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  --ink: #1e241d;
  --paper: #f7f5ef;
  --surface: #fffdf9;
  --line: #deddd5;
  --forest: #354838;
  --forest-soft: #e4ebe1;
  --muted: #70756c;
  --forest-dark: #26382a;
  --brown: #765744;
}

body { margin: 0; background: var(--paper); color: var(--ink); }
main { box-sizing: border-box; }
.popup-page main { width: 410px; padding: 16px; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 22px; margin-bottom: 3px; }
h2 { font-size: 15px; margin: 15px 0 8px; }
section + section { border-top: 1px solid color-mix(in srgb, CanvasText 14%, transparent); margin-top: 14px; padding-top: 1px; }
label { display: grid; gap: 5px; margin: 9px 0; font-size: 13px; }
input, select, button { box-sizing: border-box; width: 100%; min-height: 36px; font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font-weight: 650; }
.popup-page main { background: var(--paper); }
.dashboard { background: var(--paper); }
input, select { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 0 10px; }
button:hover { border-color: #aaa99f; }
.primary { background: var(--forest); border-color: var(--forest); color: #fff; box-shadow: 0 6px 18px #35483829; }
.primary:hover { background: #26382a; }
.primary { font-weight: 700; margin-top: 10px; }
.secondary { margin-top: 7px; }
.small-button { min-height: 31px; font-size: 12px; }
.compact { width: 128px; min-height: 34px; font-size: 12px; }
.dashboard-button { margin-bottom: 24px; font-weight: 650; }
.muted { opacity: .66; font-size: 12px; overflow-wrap: anywhere; }
.popup-title-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.product-preview { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid color-mix(in srgb, CanvasText 18%, transparent); }
.field-action-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px; gap: 7px; }
.detected-grid { display: grid; grid-template-columns: 70px 1fr; gap: 5px 9px; font-size: 13px; }
.fallback-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.criteria { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; margin: 7px 0; }
.check-row { display: flex; align-items: center; gap: 7px; margin: 0; }
.check-row input { width: auto; min-height: auto; }
.disabled-row { opacity: .55; }
#message { margin-top: 12px; min-height: 20px; font-size: 12px; }

.dashboard { max-width: 1040px; margin: 0 auto; padding: 32px 28px 64px; }
.back-link { display: inline-block; margin-bottom: 12px; color: var(--forest); font-size: 12px; font-weight: 700; text-decoration: none; }
.dashboard-subtitle { margin: 5px 0 0; color: #596259; font-size: 13px; }
.connection-panel { display: flex; align-items: center; gap: 8px; margin: 20px 0 14px; padding: 11px 14px; border: 1px solid #d5a44d; border-radius: 12px; background: #fff5dc; color: #5c4518; font-size: 12px; }
.connection-panel span { opacity: .78; }
.connection-panel.is-connected { border-color: #b8cfb7; background: #edf5ea; color: #29432c; }
.discovery-block { display: grid; gap: 6px; margin-top: 4px; }
.candidate-list { max-width: 380px; font-size: 11px; text-align: left; }
.candidate-list summary { cursor: pointer; font-weight: 700; }
.candidate-list a { margin-top: 6px; color: inherit; text-decoration: none; }
.candidate-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center; }
.candidate-row img { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; }
.candidate-row small { display: block; margin-top: 2px; opacity: .7; }
.dashboard header { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.dashboard header button { width: auto; padding-inline: 18px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.header-actions .primary { margin-top: 0; }
.tabs { display: flex; gap: 8px; margin: 20px 0; }
.tabs button { width: auto; padding: 8px 18px; }
.tabs .active { font-weight: 700; }
.watch-card { position: relative; display: grid; grid-template-columns: 112px minmax(0,1fr) minmax(130px, auto); gap: 20px; align-items: center; border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; background: var(--surface); box-shadow: 0 10px 26px #3548380d; }
.watch-card[draggable="true"] { cursor: grab; }
.watch-card.is-dragging { opacity: .45; }
.drag-handle { position: absolute; left: 3px; top: 50%; transform: translateY(-50%); color: #899187; cursor: grab; font-size: 20px; }
.watch-image { width: 112px; height: 112px; object-fit: cover; border-radius: 12px; background: var(--forest-soft); }
.watch-image.placeholder { display: grid; place-items: center; font-size: 11px; opacity: .6; text-align: center; }
.watch-main p { margin-bottom: 3px; }
.status { display: grid; gap: 7px; text-align: right; font-size: 13px; min-width: 130px; }
.status-line { display: block; }
.low-stock { font-weight: 700; }
.health-warning { font-weight: 700; }
.price-history { display: grid; gap: 2px; justify-items: end; }
.price-history .old-price { text-decoration: line-through; opacity: .62; }
.price-history .current-price { font-weight: 700; }
.price-history .rrp-label { margin-right: 5px; font-size: 11px; opacity: .72; text-decoration: none; }
.card-actions { display: grid; gap: 7px; justify-items: stretch; margin-top: 6px; }
.card-actions button, .card-actions a { width: 100%; min-width: 112px; font-size: 12px; }
.card-actions a { box-sizing: border-box; min-height: 34px; display: grid; place-items: center; padding: 6px 10px; color: inherit; text-decoration: none; border: 1px solid color-mix(in srgb, CanvasText 28%, transparent); border-radius: 4px; background: ButtonFace; color: ButtonText; }
.empty { padding: 40px 0; opacity: .65; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.manage-dialog { width: min(460px, calc(100vw - 32px)); border: 1px solid color-mix(in srgb, CanvasText 22%, transparent); border-radius: 12px; padding: 18px; background: Canvas; color: CanvasText; }
.manage-dialog::backdrop { background: rgba(0,0,0,.42); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.dialog-header h2 { margin-top: 0; font-size: 18px; }
.icon-button { width: 34px; min-height: 34px; font-size: 22px; line-height: 1; }
.manage-criteria { margin: 18px 0; }
.dialog-actions { display: flex; justify-content: space-between; gap: 16px; margin-top: 22px; }
.dialog-actions-right { display: flex; gap: 8px; }
.dialog-actions button { width: auto; padding-inline: 14px; }
.danger { color: #b42318; }

@media (max-width: 720px) {
  .watch-card { grid-template-columns: 76px 1fr; }
  .watch-image { width: 76px; height: 76px; }
  .status { grid-column: 2; text-align: left; justify-items: start; }
  .price-history { justify-items: start; }
  .card-actions { justify-content: start; }
}

.popup-title-row { margin-top: 2px; }
.manual-properties-wrap { position: relative; margin-top: 8px; }
.text-button { width: auto; min-height: 28px; padding: 3px 0; border: 0; background: transparent; color: inherit; text-decoration: underline; text-underline-offset: 2px; font-size: 12px; opacity: .72; text-align: left; }
.manual-properties-menu { position: absolute; z-index: 20; left: 0; top: 32px; min-width: 190px; padding: 6px; border: 1px solid color-mix(in srgb, CanvasText 20%, transparent); border-radius: 8px; background: Canvas; box-shadow: 0 5px 18px rgba(0,0,0,.18); }
.manual-properties-menu button { display: block; width: 100%; min-height: 31px; border: 0; background: transparent; text-align: left; padding: 5px 8px; }
.manual-properties-menu button:hover { background: color-mix(in srgb, CanvasText 8%, Canvas); }

/* CostWatch v0.5 refinements */
.dashboard header { display: flex; align-items: center; justify-content: space-between; }
.dashboard header h1 { margin-bottom: 0; }

.subtle-action {
  width: auto;
  min-height: 24px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .66;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-align: left;
}
.subtle-action:hover { opacity: 1; }
.fallback-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 4px;
}

.manage-dialog { width: min(500px, calc(100vw - 32px)); }
.manage-criteria {
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  padding: 4px 0 2px;
}
.dialog-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}
.dialog-actions-right {
  display: contents;
}
.dialog-actions button {
  width: 100%;
  min-height: 40px;
  padding-inline: 12px;
}

/* CostWatch v0.6 */
.popup-title-row {
  align-items: flex-start;
}
.image-tools {
  display: grid;
  justify-items: center;
  gap: 4px;
  width: 92px;
}
.image-tools[hidden] {
  display: none;
}
.image-action {
  width: 92px;
  text-align: center;
  line-height: 1.2;
  font-size: 10px;
}
.product-preview {
  width: 82px;
  height: 82px;
}

.manage-criteria {
  grid-template-columns: 1fr 1fr;
}
.dialog-actions {
  grid-template-columns: 1fr 1fr;
}
.dialog-actions .primary {
  margin-top: 0;
}

/* CostWatch v0.9 wishlist categories and Waiting-state detail */
.dashboard-tools {
  display: flex;
  align-items: end;
  gap: 10px;
  margin: -8px 0 18px;
  padding: 0;
  border: 0;
}
.dashboard-tools label { margin: 0; font-weight: 650; }
.dashboard-tools select { width: min(260px, 100%); }
.category-badge {
  display: inline-flex;
  width: fit-content;
  margin-top: 7px;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, CanvasText 9%, Canvas);
  font-size: 11px;
  font-weight: 650;
}
.last-checked { font-size: 11px; opacity: .65; }
.last-checked.is-stale { color: #b54708; opacity: 1; font-weight: 700; }
.discovery-block { display: grid; gap: 5px; margin-top: 4px; }
.discovery-status { font-size: 11px; font-weight: 700; }
.discovery-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px 9px; }
.discovery-links a { color: inherit; font-size: 11px; text-underline-offset: 2px; }
.candidate-list { max-width: 340px; font-size: 11px; text-align: left; }
.candidate-list summary { cursor: pointer; font-weight: 700; }
.candidate-list a { display: block; margin-top: 5px; color: inherit; overflow-wrap: anywhere; }
.candidate-list .candidate-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px; align-items: center; }
.candidate-row img { width: 34px; height: 34px; object-fit: cover; border-radius: 4px; }
.candidate-row small { display: block; margin-top: 2px; opacity: .7; }
.category-settings-list { display: grid; gap: 8px; margin: 18px 0 12px; }
.category-setting-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid color-mix(in srgb, CanvasText 15%, transparent); border-radius: 7px; }
.category-setting-row button { width: auto; min-height: 30px; font-size: 12px; }
.category-add-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.category-add-row button { width: auto; min-width: 72px; }
.settings-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.settings-actions button { width: auto; padding-inline: 18px; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Pleasure Purchases uses the same collection layout as Home Inventory. */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 164px minmax(0, 1fr); background: radial-gradient(circle at 91% 4%, #ebe6db 0, transparent 27rem), var(--paper); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px; background: #29352b; color: #f4f1e9; border-right: 1px solid #39463b; display: flex; flex-direction: column; z-index: 10; }
.brand-mark { width: 44px; height: 44px; margin: 0 auto 36px; border-radius: 14px; display: grid; place-items: center; background: #e9dfcb; color: #364439; font: 700 17px Georgia, serif; letter-spacing: -.04em; text-decoration: none; }
.sidebar nav { display: grid; gap: 9px; }
.sidebar nav button, .settings-link { width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 13px; background: transparent; color: #aeb7ad; text-align: left; font-size: 12px; font-weight: 700; box-shadow: none; }
.sidebar nav button:hover, .sidebar nav button.active, .settings-link:hover { color: white; background: #48584b; border-color: transparent; }
.settings-link { margin-top: auto; }
.workspace { min-width: 0; padding: 30px 40px 64px; }
.dashboard { max-width: 1440px; margin: 0 auto; padding: 0; background: transparent; }
.topbar { margin: 0 0 26px; display: flex !important; justify-content: space-between !important; align-items: center !important; gap: 18px; }
.eyebrow { margin: 0 0 5px; color: var(--brown); font-size: 10px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.dashboard h1 { margin: 0; font: 500 34px/1 Georgia, serif; }
.back-link, .dashboard-subtitle { display: none; }
.header-actions .primary { min-height: 42px; padding: 0 16px; border-radius: 11px; }
.connection-panel { max-width: 1440px; margin: 0 0 18px; border-radius: 14px; background: #edf4eb; border-color: #bbceb7; color: #36583a; }
.dashboard-tools { max-width: 1440px; margin: 0 0 16px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: #fffdf9ad; }
.dashboard-tools label { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.dashboard-tools select { min-height: 39px; background: #fff; }
#list { max-width: 1440px; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--surface); box-shadow: 0 10px 38px rgb(53 72 56 / 6%); }
.watch-card { grid-template-columns: auto 58px minmax(180px, 1fr) minmax(175px, auto); min-height: 88px; gap: 14px; margin: 0; padding: 14px 24px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; }
.watch-card:last-child { border-bottom: 0; }
.watch-card:hover { background: #faf9f4; }
.drag-handle { position: static; transform: none; color: #899187; font-size: 18px; }
.watch-image { width: 58px; height: 58px; border-radius: 12px; }
.watch-main h2 { margin: 0 0 5px; font: 500 19px/1.15 Georgia, serif; }
.watch-main p { color: var(--muted); font-size: 12px; }
.status { min-width: 160px; color: var(--muted); font-size: 11px; }
.status strong, .current-price { color: var(--ink); font-size: 12px; }
.category-badge { border-radius: 7px; background: #f0eee8; color: var(--muted); font-size: 9px; letter-spacing: .05em; text-transform: uppercase; }
.card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.card-actions button, .card-actions a { width: auto; min-width: 0; min-height: 31px; padding: 0 10px; border-radius: 9px; background: #fff; color: var(--ink); font-size: 11px; }
.card-actions .subtle-action { background: transparent; border: 0; color: var(--forest); text-decoration: none; opacity: 1; }
.card-actions .primary-link { background: var(--forest); border-color: var(--forest); color: white; }
.empty { min-height: 220px; display: grid; place-items: center; margin: 0; padding: 40px; color: var(--muted); text-align: center; font-size: 13px; }
.manage-dialog { border-color: var(--line); border-radius: 17px; padding: 24px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 80px rgb(25 33 27 / 25%); }
.manage-dialog::backdrop { background: rgb(24 31 25 / 24%); backdrop-filter: blur(3px); }
.dialog-header h2 { font: 500 24px Georgia, serif; }
.manage-dialog label { color: var(--muted); font-size: 11px; font-weight: 700; }
.manage-dialog input, .manage-dialog select { min-height: 39px; background: #fff; font-size: 13px; font-weight: 400; }

@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; height: auto; padding: 10px 14px; flex-direction: row; align-items: center; gap: 10px; }
  .brand-mark { width: 38px; height: 38px; margin: 0; flex: 0 0 auto; }
  .sidebar nav { display: flex; gap: 5px; overflow-x: auto; }
  .sidebar nav button { min-height: 38px; padding: 0 10px; white-space: nowrap; }
  .settings-link { width: auto; min-height: 38px; margin: 0 0 0 auto; }
  .workspace { padding: 22px 16px 44px; }
  .topbar { align-items: flex-start !important; }
  .watch-card { grid-template-columns: 46px minmax(0, 1fr); padding: 14px 16px; }
  .drag-handle { display: none; }
  .watch-image { width: 46px; height: 46px; }
  .status { grid-column: 2; text-align: left; justify-items: start; }
  .card-actions { justify-content: flex-start; }
}

@media (max-width: 520px) {
  .dashboard header { align-items: flex-start; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .dashboard-tools { align-items: stretch; flex-direction: column; }
  .dashboard-tools select { width: 100%; }
  .discovery-links { justify-content: flex-start; }
  .two-fields { grid-template-columns: 1fr; gap: 0; }
}
