/* Monitor de Preço: visual inspirado no macOS (Sonoma) */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --bg: #ffffff;
  --sidebar: rgba(236, 236, 241, 0.78);
  --sidebar-solid: #ececf1;
  --toolbar: rgba(255, 255, 255, 0.8);
  --grouped-bg: #f5f5f7;
  --card: #ffffff;
  --label: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #a1a1a6;
  --separator: rgba(0, 0, 0, 0.09);
  --separator-strong: rgba(0, 0, 0, 0.16);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --hover: rgba(0, 0, 0, 0.04);
  --accent: #007aff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --on-accent: #ffffff;
  --green: #28a745;
  --green-soft: rgba(52, 199, 89, 0.15);
  --orange: #e67e00;
  --orange-soft: rgba(255, 149, 0, 0.15);
  --red: #e5352b;
  --red-soft: rgba(255, 59, 48, 0.12);
  --control: #ffffff;
  --seg-on: #ffffff;
  --control-border: rgba(0, 0, 0, 0.12);
  --shadow-control: 0 0.5px 1px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  --shadow-sheet: 0 24px 60px rgba(0, 0, 0, 0.22), 0 0 0 0.5px rgba(0, 0, 0, 0.12);
  --hud: rgba(40, 40, 42, 0.86);
  --scrim: rgba(0, 0, 0, 0.2);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1e;
    --sidebar: rgba(44, 44, 46, 0.78);
    --sidebar-solid: #2a2a2c;
    --toolbar: rgba(30, 30, 30, 0.82);
    --grouped-bg: #161617;
    --card: #232325;
    --label: #f5f5f7;
    --secondary: #a1a1a6;
    --tertiary: #6e6e73;
    --separator: rgba(255, 255, 255, 0.08);
    --separator-strong: rgba(255, 255, 255, 0.16);
    --fill: rgba(120, 120, 128, 0.24);
    --fill-strong: rgba(120, 120, 128, 0.36);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.2);
    --green: #32d74b;
    --green-soft: rgba(50, 215, 75, 0.16);
    --orange: #ff9f0a;
    --orange-soft: rgba(255, 159, 10, 0.16);
    --red: #ff453a;
    --red-soft: rgba(255, 69, 58, 0.16);
    --control: #3a3a3c;
    --seg-on: #636366;
    --control-border: rgba(255, 255, 255, 0.1);
    --shadow-control: 0 0.5px 1px rgba(0, 0, 0, 0.4), inset 0 0.5px 0 rgba(255, 255, 255, 0.08);
    --shadow-sheet: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 0 0.5px rgba(255, 255, 255, 0.12);
    --scrim: rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 13px/1.4 var(--font);
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
svg.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--secondary); }
.tertiary { color: var(--tertiary); }
[hidden] { display: none !important; }

/* ---------- janela ---------- */

.window { display: grid; grid-template-columns: 228px 1fr; height: 100vh; height: 100dvh; }

.sidebar {
  background: var(--sidebar);
  backdrop-filter: saturate(180%) blur(30px);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  border-right: 0.5px solid var(--separator-strong);
  display: flex; flex-direction: column;
  padding: 0 10px 12px;
  min-height: 0;
}
.traffic { display: flex; gap: 8px; padding: 18px 8px 22px; }
.traffic span { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.15); }
.traffic span:nth-child(1) { background: #ff5f57; }
.traffic span:nth-child(2) { background: #febc2e; }
.traffic span:nth-child(3) { background: #28c840; }
.sidebar h6 { margin: 14px 10px 4px; font-size: 11px; font-weight: 600; color: var(--tertiary); }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 6px 10px; border: 0; border-radius: 6px;
  background: none; text-align: left; cursor: default;
  color: var(--label);
}
.nav-item svg { color: var(--accent); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--fill-strong); }
.nav-item .count { margin-left: auto; color: var(--secondary); font-size: 12px; }
.sidebar-footer { margin-top: auto; padding: 10px; color: var(--secondary); font-size: 11px; line-height: 1.5; }
.sidebar-footer .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 5px; vertical-align: 1px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.toolbar {
  height: 52px; flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px 0 20px;
  background: var(--toolbar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator-strong);
  position: relative; z-index: 2;
}
.toolbar h1 { font-size: 15px; font-weight: 700; margin: 0; white-space: nowrap; }
.toolbar .subtitle { color: var(--secondary); font-size: 11px; font-weight: 400; margin-left: 2px; }
.toolbar .spacer { flex: 1; }
.tool-btn.back-btn { display: none; }

.content { flex: 1; overflow: auto; min-height: 0; }

/* ---------- controles ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 26px; padding: 0 11px;
  border: 0; border-radius: 6px;
  background: var(--control); box-shadow: var(--shadow-control);
  font-size: 13px; font-weight: 500; white-space: nowrap; cursor: default;
}
.btn:active { filter: brightness(0.94); }
.btn:disabled { opacity: 0.45; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 0.5px 1px rgba(0, 0, 0, 0.2), inset 0 0.5px 0 rgba(255, 255, 255, 0.2); }
.btn-danger { color: var(--red); }
.btn-lg { height: 30px; padding: 0 14px; }
.tool-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 28px; min-width: 32px; padding: 0 8px;
  border: 0; border-radius: 6px; background: none; color: var(--secondary); cursor: default;
}
.tool-btn:hover { background: var(--hover); color: var(--label); }
.tool-btn:active { background: var(--fill); }
.tool-btn svg { width: 17px; height: 17px; }
.tool-btn.busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.search {
  display: flex; align-items: center; gap: 6px;
  height: 28px; width: 220px; padding: 0 8px;
  border-radius: 7px; background: var(--fill); color: var(--secondary);
}
.search input { border: 0; outline: 0; background: none; width: 100%; color: var(--label); }
.search:focus-within { box-shadow: 0 0 0 3.5px var(--accent-soft), 0 0 0 1px var(--accent); }

.field {
  height: 26px; width: 100%; padding: 0 8px;
  border: 0.5px solid var(--control-border); border-radius: 6px;
  background: var(--control); outline: 0;
  box-shadow: inset 0 0.5px 1px rgba(0, 0, 0, 0.06);
}
.field:focus { box-shadow: 0 0 0 3.5px var(--accent-soft), 0 0 0 1px var(--accent); border-color: transparent; }
.field:disabled { opacity: 0.5; }
.field.money { text-align: right; font-variant-numeric: tabular-nums; }
select.field { appearance: none; padding-right: 24px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='14' viewBox='0 0 10 14'%3E%3Cpath d='M2 5l3-3 3 3M2 9l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 7px center; }
.input-prefix { display: flex; align-items: center; gap: 6px; }
.input-prefix span { color: var(--secondary); }

.segmented { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--fill); gap: 2px; }
.segmented button { border: 0; background: none; height: 22px; padding: 0 12px; border-radius: 5px; font-size: 12px; font-weight: 500; cursor: default; }
.segmented button.on { background: var(--seg-on); box-shadow: var(--shadow-control); }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: default; }
.switch i { position: absolute; inset: 0; border-radius: 11px; background: var(--fill-strong); transition: background 0.2s; pointer-events: none; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s; }
.switch input:checked + i { background: var(--green); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { box-shadow: 0 0 0 3px var(--accent-soft); }

.check { display: inline-flex; align-items: center; gap: 7px; cursor: default; }
.check input { appearance: none; width: 15px; height: 15px; margin: 0; border-radius: 4px; background: var(--control); box-shadow: var(--shadow-control), inset 0 0 0 0.5px var(--control-border); display: grid; place-items: center; }
.check input:checked { background: var(--accent); box-shadow: none; }
.check input:checked::after { content: ""; width: 8px; height: 4px; border: solid #fff; border-width: 0 0 1.8px 1.8px; transform: rotate(-45deg) translate(1px, -1px); }

.pill { display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 7px; border-radius: 9px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.pill.gray { background: var(--fill); color: var(--secondary); }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.red { background: var(--red-soft); color: var(--red); }
.chip { display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 4px 0 8px; border-radius: 10px; background: var(--fill); font-size: 12px; }
.chip.neg { text-decoration: line-through; text-decoration-color: var(--tertiary); color: var(--secondary); padding-right: 8px; }
.chip button { border: 0; background: none; width: 16px; height: 16px; border-radius: 50%; padding: 0; display: grid; place-items: center; color: var(--secondary); cursor: default; }
.chip button:hover { background: var(--fill-strong); }

.tokens { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 28px; padding: 3px 6px; border: 0.5px solid var(--control-border); border-radius: 6px; background: var(--control); }
.tokens:focus-within { box-shadow: 0 0 0 3.5px var(--accent-soft), 0 0 0 1px var(--accent); border-color: transparent; }
.tokens input { flex: 1; min-width: 90px; border: 0; outline: 0; background: none; height: 20px; }

/* ---------- lista + detalhe ---------- */

.split { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100%; }
.list { border-right: 0.5px solid var(--separator-strong); overflow: auto; }
.detail { overflow: auto; background: var(--grouped-bg); }

.row-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  margin: 2px 8px; padding: 9px 10px; border-radius: 8px; cursor: default;
}
.row-item:first-child { margin-top: 8px; }
.row-item:hover { background: var(--hover); }
.row-item.active { background: var(--accent); color: var(--on-accent); }
.row-item.active .muted, .row-item.active .tertiary { color: rgba(255, 255, 255, 0.78); }
.row-item.active .pill { background: rgba(255, 255, 255, 0.22); color: #fff; }
.row-item.active .spark { stroke: #fff !important; }
.row-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .price { font-weight: 600; text-align: right; }
.row-item .meta { display: flex; align-items: center; gap: 6px; font-size: 12px; min-width: 0; overflow: hidden; white-space: nowrap; }
.row-item .meta .merchant { overflow: hidden; text-overflow: ellipsis; }
.row-item.paused { opacity: 0.6; }
.row-sep { height: 0.5px; background: var(--separator); margin: 0 18px; }

.empty { display: grid; place-items: center; text-align: center; height: 100%; padding: 40px 20px; color: var(--secondary); }
.empty svg.big { width: 44px; height: 44px; stroke-width: 1.3; color: var(--tertiary); margin-bottom: 10px; }
.empty h2 { margin: 0 0 4px; font-size: 17px; color: var(--label); }
.empty p { margin: 0 0 14px; }

/* ---------- detalhe / grupos estilo Ajustes do Sistema ---------- */

.page { max-width: 780px; margin: 0 auto; padding: 24px 28px 48px; }
.page-narrow { max-width: 640px; }
.hero { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.hero h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.hero .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.price-card { display: flex; align-items: center; gap: 16px; padding: 16px 18px; border-radius: 12px; background: var(--card); box-shadow: 0 0 0 0.5px var(--separator); margin-bottom: 14px; }
.price-card .big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.price-card .where { color: var(--secondary); }
.price-card .where b { color: var(--label); font-weight: 600; }
.price-card .btn { margin-left: auto; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { padding: 11px 13px; border-radius: 10px; background: var(--card); box-shadow: 0 0 0 0.5px var(--separator); }
.tile .k { font-size: 11px; color: var(--secondary); font-weight: 500; }
.tile .v { font-size: 16px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }

.section-title { margin: 22px 4px 7px; font-size: 13px; font-weight: 650; }
.section-title .muted { font-weight: 400; }
.section-note { margin: 6px 4px 0; font-size: 11.5px; color: var(--secondary); line-height: 1.45; }

.group { border-radius: 10px; background: var(--card); box-shadow: 0 0 0 0.5px var(--separator); overflow: hidden; }
.group .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-height: 40px; padding: 7px 14px; position: relative; }
.group .row + .row::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; height: 0.5px; background: var(--separator); }
.group .row .label { flex: 1 1 180px; min-width: 0; }
.group .row .label small { display: block; color: var(--secondary); font-size: 11.5px; }
.group .row .control { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-left: auto; }
.group .row .control .field { width: 130px; }
.group .row.stack { flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 14px; }
.group .row.link { cursor: default; }
.group .row.link:hover { background: var(--hover); }

.offer-row .p { width: 96px; flex: none; font-weight: 650; font-variant-numeric: tabular-nums; }
.offer-row .info { flex: 1; min-width: 0; }
.offer-row .info .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offer-row .info .m { font-size: 11.5px; color: var(--secondary); }
.offer-row.best .p { color: var(--green); }
.offer-row a.ext { color: var(--tertiary); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; }
.offer-row a.ext:hover { background: var(--fill); color: var(--accent); }

.chart { padding: 14px 14px 8px; }
.chart svg { display: block; overflow: visible; }
.chart-box { min-height: 190px; }
.chart .axis { font-size: 10px; fill: var(--tertiary); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--separator); stroke-width: 1; }
.chart .target { stroke: var(--green); stroke-dasharray: 4 4; stroke-width: 1.2; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: url(#areaGrad); }
.chart .hover-line { stroke: var(--separator-strong); stroke-width: 1; }
.chart .dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart-tip { font-size: 11.5px; color: var(--secondary); min-height: 17px; padding: 0 2px; }
.chart-tip b { color: var(--label); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status-dot.ok { background: var(--green); }
.status-dot.warn { background: var(--orange); }
.status-dot.bad { background: var(--red); }
.status-dot.off { background: var(--tertiary); }
code, .mono { font-family: var(--mono); font-size: 11.5px; }

.activity-day { margin: 20px 4px 7px; font-size: 12px; font-weight: 600; color: var(--secondary); text-transform: capitalize; }
.alert-row .time { width: 44px; flex: none; color: var(--secondary); font-variant-numeric: tabular-nums; font-size: 12px; }
.alert-row .reasons { font-size: 12px; color: var(--secondary); }

/* ---------- sheet (modal) ---------- */

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 52px 16px 16px; animation: fade 0.18s ease-out; }
.sheet {
  width: 100%; max-width: 620px; max-height: calc(100dvh - 72px);
  display: flex; flex-direction: column;
  background: var(--grouped-bg); border-radius: 12px; box-shadow: var(--shadow-sheet);
  animation: drop 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
  overflow: hidden;
}
.sheet.wide { max-width: 900px; }
.sheet header { padding: 16px 20px 4px; }
.sheet header h3 { margin: 0; font-size: 15px; font-weight: 700; }
.sheet header p { margin: 3px 0 0; color: var(--secondary); font-size: 12px; }
.sheet .body { overflow: auto; padding: 4px 20px 16px; }
.sheet footer { display: flex; gap: 8px; align-items: center; padding: 12px 20px; border-top: 0.5px solid var(--separator); background: var(--card); }
.sheet footer .spacer { flex: 1; }
.sheet-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.alert-sheet { max-width: 280px; text-align: center; padding: 20px 16px 16px; }
.alert-sheet .alert-icon { width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 13px; display: grid; place-items: center; background: linear-gradient(160deg, #4facfe, #007aff); color: #fff; }
.alert-sheet .alert-icon svg { width: 28px; height: 28px; }
.alert-sheet h3 { margin: 0 0 4px; font-size: 13px; font-weight: 700; }
.alert-sheet p { margin: 0 0 16px; font-size: 11.5px; color: var(--secondary); }
.alert-sheet .btns { display: grid; gap: 6px; }
.alert-sheet .btn { height: 28px; }
@keyframes fade { from { opacity: 0; } }
@keyframes drop { from { transform: translateY(-24px) scale(0.98); opacity: 0; } }

.preview { margin-top: 4px; }
.preview .head { display: flex; align-items: center; gap: 8px; margin: 0 4px 7px; }
.preview .head .section-title { margin: 0; }
.preview .list-box { max-height: 420px; overflow: auto; }
.preview .placeholder { padding: 28px 16px; text-align: center; color: var(--secondary); font-size: 12px; }

/* ---------- HUD ---------- */

.hud {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 100; display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 12px;
  background: var(--hud); color: #fff; font-weight: 500;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  animation: hud 0.25s ease-out;
}
.hud.error { background: rgba(200, 40, 30, 0.92); }
@keyframes hud { from { opacity: 0; transform: translate(-50%, 8px); } }

.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--fill-strong); border-top-color: var(--secondary); animation: spin 0.8s linear infinite; display: inline-block; }

/* ---------- tab bar (celular) ---------- */

.tabbar { display: none; }

@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .window { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--toolbar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--separator-strong);
  }
  .tabbar button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--tertiary); padding: 2px 0; }
  .tabbar button svg { width: 22px; height: 22px; }
  .tabbar button.active { color: var(--accent); }
  .split { grid-template-columns: 1fr; }
  .split.show-detail .list { display: none; }
  .split:not(.show-detail) .detail { display: none; }
  .tool-btn.back-btn.visible { display: inline-flex; }
  .toolbar { padding: 0 8px 0 12px; }
  .search { width: 100%; max-width: 200px; }
  .page { padding: 18px 16px 40px; }
  .hero { flex-wrap: wrap; }
  .hero .actions { margin-left: 0; width: 100%; justify-content: flex-start; }
  .sheet-cols { grid-template-columns: 1fr; }
  .scrim { padding: 12px 8px; }
  .sheet { max-height: calc(100dvh - 24px); }
  .list { border-right: 0; }
}

@media (max-width: 520px) {
  .toolbar h1 .subtitle { display: none; }
  .price-card { flex-wrap: wrap; }
  .price-card .btn { margin-left: 0; }
  .group .row .control .field { width: 110px; }
  .offer-row .p { width: 84px; }
}
