:root{
  --bg:#f4f7f4;
  --card:#ffffff;
  --card-alt:#f8fbf8;
  --text:#163021;
  --muted:#5f7267;
  --line:#d9e5dd;
  --primary:#1f7a3d;
  --primary-dark:#125629;
  --shadow:0 10px 30px rgba(15, 35, 20, 0.08);
  --radius:20px;
}

*{
  box-sizing:border-box;
}

body{
  margin:0;
  font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  background:linear-gradient(180deg,#eef5ef 0%, var(--bg) 180px);
  color:var(--text);
}

a{
  text-decoration:none;
  color:inherit;
}

button,
input,
select{
  font:inherit;
}

.app-shell{
  width:min(1150px, calc(100% - 24px));
  margin:0 auto;
  padding:18px 0 34px;
}

/* TOPO */

.topbar{
  display:flex;
  justify-content:space-between;
  gap:16px;
  align-items:flex-start;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:24px;
  padding:20px;
  box-shadow:var(--shadow);
}

.eyebrow{
  margin:0 0 6px;
  color:var(--primary);
  font-weight:700;
  font-size:.92rem;
}

h1{
  margin:0;
  font-size:1.9rem;
}

.subtitle{
  margin:8px 0 0;
  color:var(--muted);
}

.topbar-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

/* LAYOUT GERAL */

.main-grid{
  display:grid;
  grid-template-columns:1.05fr .95fr;
  gap:18px;
  margin-top:18px;
}

.panel{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}

.form-panel,
.result-panel,
.history-toolbar,
.history-card{
  padding:18px;
}

.section-head h2{
  margin:0;
  font-size:1.25rem;
}

.section-head p{
  margin:6px 0 0;
  color:var(--muted);
}

/* BLOCO DE INFO */

.info-strip{
  margin:14px 0 12px;
  display:grid;
  gap:6px;
  background:var(--card-alt);
  border:1px dashed #bfd4c4;
  border-radius:16px;
  padding:10px 12px;
  color:#355141;
  font-size:.93rem;
}

/* TIPO DE COMPARAÇÃO */

.comparison-type-row{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  margin-bottom:12px;
  padding:10px 12px;
  background:#f7fbf8;
  border:1px solid var(--line);
  border-radius:16px;
}

.comparison-type-label{
  font-weight:700;
  color:#274231;
}

.type-option{
  display:flex;
  align-items:center;
  gap:6px;
  padding:8px 12px;
  border-radius:999px;
  background:#edf5ef;
  color:#274231;
  font-weight:600;
  cursor:pointer;
}

.type-option input{
  margin:0;
}

/* FORMULÁRIO */

.items-container{
  display:grid;
  gap:10px;
}

.item-card{
  background:linear-gradient(180deg, #ffffff 0%, #f9fcf9 100%);
  border:1px solid var(--line);
  border-radius:18px;
  padding:12px;
}

.item-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:10px;
}

.item-title{
  margin:0;
  font-size:1rem;
}

.remove-btn{
  width:34px;
  height:34px;
  border:none;
  background:#f4dede;
  color:#933;
  border-radius:999px;
  cursor:pointer;
  font-size:1.35rem;
  line-height:1;
}

.field-grid{
  display:grid;
  gap:10px;
}

.compact-grid{
  grid-template-columns:2fr 1fr 1fr;
  align-items:start;
}

.field{
  display:flex;
  flex-direction:column;
  gap:5px;
}

.field span{
  font-weight:600;
  color:#355141;
  font-size:.95rem;
}

.field input,
.field select{
  width:100%;
  border:1px solid #c7d7cd;
  background:#fff;
  color:var(--text);
  border-radius:14px;
  padding:11px 13px;
  outline:none;
}

.field input:focus,
.field select:focus{
  border-color:#6cb387;
  box-shadow:0 0 0 4px rgba(31, 122, 61, 0.11);
}

.field .hint{
  color:var(--muted);
  min-height:16px;
  font-size:.86rem;
}

.full-row{
  grid-column:1 / -1;
}

.form-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top:14px;
}

/* BOTÕES */

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn{
  border:none;
  border-radius:14px;
  padding:12px 16px;
  cursor:pointer;
  font-weight:700;
}

.primary-btn{
  background:var(--primary);
  color:#fff;
}

.primary-btn:hover{
  background:var(--primary-dark);
}

.secondary-btn{
  background:#e7f2ea;
  color:var(--primary-dark);
}

.ghost-btn{
  background:#eef2ef;
  color:#274231;
}

.danger-btn{
  background:#fbe7e7;
  color:#942d2d;
}

.hidden{
  display:none !important;
}

/* RESULTADO DA COMPARAÇÃO */

.empty-state{
  display:grid;
  place-items:center;
  text-align:center;
  padding:30px 18px;
  color:var(--muted);
  min-height:260px;
}

.empty-icon{
  font-size:2.2rem;
}

.results-list{
  display:grid;
  gap:12px;
}

.result-card{
  border-radius:18px;
  padding:16px;
  border:1px solid var(--line);
}

.result-top{
  display:flex;
  justify-content:space-between;
  gap:10px;
  align-items:flex-start;
}

.result-top h3{
  margin:0;
  font-size:1.08rem;
}

.rank-pill{
  padding:7px 11px;
  border-radius:999px;
  font-weight:800;
  font-size:.9rem;
  white-space:nowrap;
}

.meta-list{
  display:grid;
  gap:7px;
  margin-top:10px;
  color:#2e4a39;
}

.meta-list strong{
  font-weight:800;
}

.savings{
  margin-top:10px;
  padding-top:10px;
  border-top:1px dashed rgba(0,0,0,.12);
  display:grid;
  gap:5px;
  font-weight:700;
}

.badge{
  display:inline-block;
  margin-bottom:8px;
  background:#dff4e4;
  color:#1f7a3d;
  padding:5px 9px;
  border-radius:999px;
  font-weight:800;
  font-size:.85rem;
}

.install-note{
  margin-top:14px;
  background:#eef7f0;
  border:1px solid #d6e7da;
  border-radius:14px;
  padding:12px;
  color:#355141;
}

/* HISTÓRICO */

.history-layout{
  display:grid;
  gap:16px;
  margin-top:18px;
}

.history-toolbar{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:20px;
  box-shadow:var(--shadow);
}

.toolbar-grid{
  display:grid;
  grid-template-columns:1fr auto;
  gap:12px;
  align-items:end;
}

.toolbar-buttons{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
}

.history-list{
  display:grid;
  gap:14px;
}

.history-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:20px;
  box-shadow:var(--shadow);
}

.history-header{
  display:flex;
  justify-content:space-between;
  gap:10px;
  align-items:flex-start;
}

.history-header h3{
  margin:0 0 5px;
  font-size:1.08rem;
}

.history-sub{
  color:var(--muted);
  font-size:.95rem;
  line-height:1.4;
}

.summary-grid{
  display:grid;
  grid-template-columns:repeat(3, minmax(0,1fr));
  gap:10px;
  margin:14px 0;
}

.summary-box{
  background:var(--card-alt);
  border:1px solid var(--line);
  border-radius:16px;
  padding:12px;
  min-width:0;
}

.summary-box .label{
  color:var(--muted);
  font-size:.9rem;
}

.summary-box .value{
  margin-top:5px;
  font-weight:800;
  color:#234031;
  word-break:break-word;
}

details{
  border-top:1px dashed var(--line);
  padding-top:12px;
}

details summary{
  cursor:pointer;
  font-weight:700;
  color:#274231;
  list-style:none;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}

details summary::-webkit-details-marker{
  display:none;
}

details summary::after{
  content:"+";
  font-size:1.1rem;
  font-weight:800;
  color:#355141;
  flex-shrink:0;
}

details[open] summary::after{
  content:"−";
}

.history-items{
  display:grid;
  gap:10px;
  margin-top:12px;
}

.history-item{
  border:1px solid var(--line);
  border-radius:16px;
  padding:12px;
  background:#fcfefd;
}

.history-item.best{
  border-color:#8fcb9e;
  background:#effaf1;
}

.history-item.mid{
  border-color:#d8dc8f;
  background:#f7f9e8;
}

.history-item.warn{
  border-color:#f0ca7b;
  background:#fff7e7;
}

.history-item.expensive{
  border-color:#e3aaaa;
  background:#fff0f0;
}

.history-item .item-name{
  margin:0 0 8px;
  font-weight:800;
  color:#1d3527;
  font-size:1rem;
}

.history-item .item-meta{
  display:grid;
  gap:5px;
  color:#2e4a39;
  font-size:.95rem;
}

.history-item .item-meta strong{
  font-weight:800;
}

.history-item .item-economy{
  margin-top:8px;
  padding-top:8px;
  border-top:1px dashed rgba(0,0,0,.12);
  font-weight:700;
  color:#1f7a3d;
}

.history-empty{
  background:var(--card);
  border:1px dashed var(--line);
  border-radius:20px;
  padding:26px 18px;
  text-align:center;
  color:var(--muted);
}

.history-search-note{
  margin-top:10px;
  color:var(--muted);
  font-size:.92rem;
}

/* RESPONSIVO */

@media (max-width: 900px){
  .main-grid{
    grid-template-columns:1fr;
  }

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

  .product-field,
  .full-row{
    grid-column:1 / -1;
  }

  /* histórico mais próximo do PC */
  .toolbar-grid{
    grid-template-columns:1fr auto;
    align-items:end;
  }

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

@media (max-width: 640px){
  .app-shell{
    width:min(100% - 12px, 100%);
    padding-top:10px;
  }

  .topbar{
    padding:14px;
    border-radius:18px;
    flex-direction:column;
  }

  h1{
    font-size:1.45rem;
  }

  /* comparação continua adaptada */
  .compact-grid{
    grid-template-columns:1fr 1fr;
    gap:8px;
  }

  .product-field,
  .full-row{
    grid-column:1 / -1;
  }

  .field input{
    padding:10px 12px;
  }

  .form-actions,
  .topbar-actions{
    display:grid;
    grid-template-columns:1fr;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn{
    width:100%;
  }

  .result-top{
    flex-direction:column;
    gap:8px;
  }

  /* histórico: manter visual parecido com PC */
  .history-toolbar{
    padding:14px;
  }

  .toolbar-grid{
    grid-template-columns:1fr auto;
    gap:10px;
    align-items:end;
  }

  .toolbar-buttons{
    display:flex;
    gap:8px;
    flex-wrap:wrap;
  }

  .history-card{
    padding:14px;
  }

  .history-header{
    flex-direction:row;
    justify-content:space-between;
    align-items:flex-start;
    gap:10px;
  }

  .history-header h3{
    font-size:1rem;
  }

  .history-sub{
    font-size:.9rem;
  }

  .summary-grid{
    grid-template-columns:repeat(3, minmax(0,1fr));
    gap:8px;
  }

  .summary-box{
    padding:10px;
  }

  .summary-box .label{
    font-size:.82rem;
  }

  .summary-box .value{
    font-size:.93rem;
  }

  .history-items{
    gap:8px;
  }

  .history-item{
    padding:10px;
  }

  .history-item .item-name{
    font-size:.96rem;
  }

  .history-item .item-meta{
    font-size:.9rem;
    gap:4px;
  }

  details summary{
    align-items:center;
    justify-content:space-between;
    gap:8px;
  }
}