:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #1f2a2e;
  --muted: #6b7478;
  --line: #ece7dd;
  --accent: #2f7d6b;
  --accent-soft: #e0f0eb;
  --up: #2f7d6b;
  --down: #d4553f;
  --warn: #e0a03a;
  --p1: #cfeadf;  --p1-ink: #1d6a57;
  --p2: #e3f1d3;  --p2-ink: #4a7a1f;
  --p3: #fbecc9;  --p3-ink: #8a6414;
  --p4: #ece9e2;  --p4-ink: #6b7478;
  --radius: 20px;
  --shadow: 0 6px 24px rgba(40, 50, 45, .07);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
body.lock { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

/* ---------- struttura ---------- */
.app { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.side { padding: 24px 18px; border-right: 1px solid var(--line); background: #efeae0; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { font-weight: 700; font-size: 20px; margin: 0 8px 18px; }
.sidelabel { font-size: 13px; color: var(--muted); margin: 0 10px 6px; }
.mock { background: #fff3d6; color: #7a5a10; border-radius: 14px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 14px; }
.plist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.plist button {
  text-align: left; border: 0; background: transparent; padding: 10px 14px; border-radius: 14px; cursor: pointer;
  display: flex; flex-direction: column;
}
.plist button:hover { background: rgba(255,255,255,.6); }
.plist button.on { background: var(--card); box-shadow: var(--shadow); }
.plist b { font-weight: 600; }
.plist small { color: var(--muted); }

.newproj summary, .addkw summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 6px 8px; }
.newproj form { display: flex; flex-direction: column; gap: 10px; padding: 8px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 9px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  border: 0; background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 999px; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost.danger { color: var(--down); }
.btn.small { padding: 5px 12px; font-size: 13px; }

.main { padding: 32px clamp(16px, 3vw, 40px); min-width: 0; }
.empty { max-width: 460px; margin: 15vh auto; text-align: center; }
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.phead h1 { font-size: 28px; }
.domain { color: var(--accent); text-decoration: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- riepilogo ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 18px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 28px; line-height: 1.15; }
.stat span { display: block; font-weight: 600; font-size: 13.5px; }
.stat small { display: block; color: var(--muted); font-size: 12.5px; }
.stat.g1 b { color: var(--p1-ink); }
.stat.g2 b { color: var(--p2-ink); }
.stat .up { color: var(--up); }
.stat .down { color: var(--down); }

.notice { background: var(--accent-soft); border-radius: 16px; padding: 12px 16px; margin-bottom: 16px; }
.notice.err { background: #fbe3dd; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 22px; margin-bottom: 18px; }
.addkw form { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 12px; align-items: end; margin-top: 12px; }
.addkw .wide { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.sub { margin: 2px 0 0; font-size: 13.5px; }

/* ---------- filtri ---------- */
.tagbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 13.5px;
}
.chip small { color: var(--muted); margin-left: 4px; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.on small { color: rgba(255,255,255,.85); }

.toolbar { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type=search] { min-width: 240px; border-radius: 999px; padding-left: 16px; }
.sortlabel select { border-radius: 999px; padding: 8px 14px; }
.legend-pos { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; font-size: 12.5px; color: var(--muted); padding-bottom: 8px; }
.legend-pos i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend-pos i.p0 { background: transparent; border: 2px solid #cfc9bb; }

i.p1, .pos.p1 { background: var(--p1); }
i.p2, .pos.p2 { background: var(--p2); }
i.p3, .pos.p3 { background: var(--p3); }
i.p4, .pos.p4 { background: var(--p4); }

.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--accent-soft); border-radius: 999px; padding: 8px 16px; margin-bottom: 14px; }
.bulk b { margin-right: 6px; }

/* ---------- tabella ---------- */
.tablecard { padding: 6px 8px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 12px 14px; }
td { padding: 14px; border-top: 1px solid var(--line); vertical-align: top; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #faf8f3; }
tr.row.sel td { background: var(--accent-soft); }
.c { text-align: center; }
th.chk, td.chk { width: 34px; padding-right: 0; }
td.chk input, th.chk input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }
.kw b { font-weight: 600; font-size: 15.5px; }
.kw small, .muted { color: var(--muted); }
.kw small { font-size: 12.5px; }
.pad { padding: 18px; }

.kwtags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.kwtag { background: var(--accent-soft); color: #1d6a57; border: 0; border-radius: 999px; padding: 1px 10px; font-size: 12px; cursor: pointer; }
tr.row.sel .kwtag { background: #fff; }
.kwtag.add { background: transparent; border: 1px dashed #d6cfbf; color: var(--muted); }

.pos {
  display: inline-flex; align-items: center; justify-content: center; min-width: 52px; height: 40px; padding: 0 14px;
  border-radius: 999px; font-weight: 700; font-size: 18px; background: var(--p4); color: var(--p4-ink);
}
.pos.p1 { color: var(--p1-ink); }
.pos.p2 { color: var(--p2-ink); }
.pos.p3 { color: var(--p3-ink); }
.pos.none { background: transparent; border: 2px solid #d6cfbf; color: var(--muted); }
.delta { display: block; font-size: 12.5px; margin-top: 5px; font-weight: 600; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); font-weight: 400; }

.snip { max-width: 520px; }
.snip .t { color: #1a4fa0; font-weight: 600; }
.snip .u { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip.none { color: var(--muted); }
.badge-change { display: inline-block; background: #fff3d6; color: #7a5a10; border-radius: 999px; padding: 1px 10px; font-size: 12px; margin-top: 7px; }
.ahead-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 7px; font-size: 12.5px; color: var(--muted); }
.comp { border-radius: 999px; padding: 1px 10px; font-size: 12px; background: #fbe3dd; color: #a23a27; }
.when { color: var(--muted); font-size: 12px; margin-top: 6px; }
.rowact { white-space: nowrap; text-align: right; }

.emptystate { text-align: center; padding: 34px 18px; color: var(--muted); }
.emptystate b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.emptystate .btn { margin-top: 12px; }

/* ---------- concorrenti ---------- */
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.cardhead h2 { font-size: 18px; }
form.inline { display: flex; gap: 8px; }
form.inline input { min-width: 240px; }
.ctable { width: 100%; }
.ctable td, .ctable th { padding: 11px 8px; }
.ctable .own td { background: var(--accent-soft); }
.ctable .own td:first-child { border-radius: 14px 0 0 14px; }
.ctable .own td:last-child { border-radius: 0 14px 14px 0; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; }
.vis { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.vis .bar { flex: 1; height: 10px; background: #eceae4; border-radius: 99px; overflow: hidden; }
.vis .bar i { display: block; height: 100%; border-radius: 99px; }
.x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; }
.x:hover { color: var(--down); }

details.card > summary { cursor: pointer; font-weight: 600; }
.evlist { list-style: none; margin: 12px 0 0; padding: 0; }
.evlist li { padding: 12px 4px; border-top: 1px solid var(--line); font-size: 14px; }
.evlist .who { font-weight: 600; }
.evlist .who.own { color: var(--accent); }
.evlist .from { color: var(--down); }
.evlist .to { color: #1d6a57; }
.evlist .meta { color: var(--muted); font-size: 12.5px; }
.evlist a { color: inherit; }

/* ---------- pannello di dettaglio ---------- */
.drawer-back { position: fixed; inset: 0; background: rgba(31, 42, 46, .38); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(780px, 100vw); z-index: 41;
  background: var(--bg); box-shadow: -10px 0 40px rgba(31, 42, 46, .18); overflow-y: auto;
  padding: 24px clamp(16px, 3vw, 32px) 40px;
  animation: slidein .22s ease-out;
}
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.dhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.dhead h2 { font-size: 24px; line-height: 1.25; }
.dhead .muted { font-size: 13px; margin-top: 4px; }
.close { border: 0; background: var(--card); width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer; box-shadow: var(--shadow); flex: none; }
.close:hover { color: var(--down); }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: 18px; padding: 12px 16px; box-shadow: var(--shadow); }
.tile small { color: var(--muted); display: block; font-size: 12.5px; }
.tile b { font-size: 24px; line-height: 1.2; }
.tile .up { color: var(--up); } .tile .down { color: var(--down); }
.tile .note { font-size: 12.5px; color: var(--muted); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab:hover { background: rgba(255,255,255,.7); }
.tab.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.tab .n { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11.5px; padding: 0 7px; margin-left: 6px; }

.dcard { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 14px; }
.dcard h3 { font-size: 16px; margin-bottom: 2px; }
.dcard > .sub { margin: 0 0 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.lg { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 12px 3px 10px; font-size: 13px; cursor: pointer; }
.lg i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; }
.lg.off { opacity: .45; }
.lg.off i { background: #cfc9bb !important; }

.chartwrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: inherit; }
.ctip {
  position: absolute; pointer-events: none; background: #fff; border-radius: 14px; box-shadow: 0 8px 28px rgba(31,42,46,.22);
  padding: 10px 14px; font-size: 13px; min-width: 170px; z-index: 5; transform: translate(-50%, -105%);
}
.ctip b { display: block; margin-bottom: 4px; }
.ctip div { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.ctip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chartnote { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }

.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; }
.rank li.me { background: var(--accent-soft); font-weight: 600; }
.rank .n { text-align: center; font-weight: 700; color: var(--muted); }
.rank .out { color: var(--muted); font-size: 13px; }

.sel-row { margin: 8px 0 12px; }
.serp { list-style: none; margin: 0; padding: 0; }
.serp li { display: grid; grid-template-columns: 38px 1fr; gap: 10px; padding: 10px 6px; border-top: 1px solid var(--line); }
.serp li.own { background: var(--accent-soft); border-radius: 14px; border-top-color: transparent; padding: 10px; }
.serp li.rival { background: #fbf3e4; border-radius: 14px; border-top-color: transparent; padding: 10px; }
.serp .n { color: var(--muted); font-weight: 700; text-align: center; }
.serp .t { font-weight: 600; color: #1a4fa0; }
.serp .u { color: var(--muted); font-size: 12.5px; word-break: break-all; }
.serp .d { font-size: 13.5px; }
.serp .who { display: inline-block; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 0 8px; margin-left: 6px; background: #fff; color: var(--muted); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.tag { background: #efeae0; border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--muted); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; }
  .addkw form { grid-template-columns: 1fr 1fr; }
  .legend-pos { margin-left: 0; }
  .tiles { grid-template-columns: 1fr; }
}
.legend-pos i.p1 { background: #5fbf9f; }
.legend-pos i.p2 { background: #9bcf6a; }
.legend-pos i.p3 { background: #efc15a; }
.legend-pos i.p4 { background: #c9c4b8; }
.stat b { white-space: nowrap; }

/* ---------- schede del progetto, finestra, blocchi della SERP ---------- */
.btn.strong { border-color: var(--accent); color: var(--accent); }
.ptabs { margin-bottom: 16px; }
.ptabs .tab { font-size: 15px; }
#paneComp h2, #paneCambi h2 { font-size: 18px; }

.dlg { border: 0; border-radius: 24px; padding: 24px 26px; width: min(620px, 94vw); box-shadow: 0 20px 60px rgba(31,42,46,.3); color: var(--ink); background: var(--card); }
.dlg::backdrop { background: rgba(31, 42, 46, .4); }
.dlg form { display: flex; flex-direction: column; gap: 14px; }
.dlg .dhead { margin: 0; }
.dlg h2 { font-size: 22px; }
.dlg .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.dlg .hint { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.newproj label small { font-weight: 400; }

.bdg { display: inline-block; background: #efeae0; color: #5c6469; border-radius: 999px; padding: 2px 10px; font-size: 12px; margin: 0 4px 4px 0; }
.bdg.good { background: var(--p1); color: var(--p1-ink); font-weight: 600; }

.drawer { width: min(1060px, 100vw); }

.serp-top { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.serp-top .sel-row { margin: 0; flex-direction: row; align-items: center; gap: 10px; font-size: 14px; }
.sumstrip { display: flex; flex-wrap: wrap; gap: 8px; }
.sum { border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; cursor: pointer; }
.sum b { font-weight: 700; }
.sum.good { background: var(--p1); color: var(--p1-ink); }
.sum.off { color: var(--muted); }

.blk { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 22px; margin-bottom: 14px; scroll-margin-top: 16px; }
.blk > header { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.blk > header h3 { font-size: 17px; margin: 0; }
.blk .why { color: var(--muted); font-size: 13px; }
.blk .tagline { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 600; background: #efeae0; color: var(--muted); }
.blk.cont { background: transparent; box-shadow: none; padding: 0 22px; }

.local { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.local li { display: grid; grid-template-columns: 38px 1fr; gap: 10px; padding: 12px 12px; border-radius: 16px; background: #faf8f3; }
.local li.own, .serp li.own { background: var(--accent-soft); }
.local .n { width: 30px; height: 30px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); }
.local .name { font-weight: 600; }
.local .info { color: #4d5559; font-size: 13.5px; }
.local .meta { color: var(--muted); font-size: 13px; }
.who { display: inline-block; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 0 8px; margin-left: 6px; background: #fff; color: var(--accent); }
.note { color: var(--muted); font-size: 13px; margin: 10px 2px 0; }

.paa { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.paa details { background: #faf8f3; border-radius: 16px; padding: 12px 16px; }
.paa summary { cursor: pointer; font-weight: 600; }
.paa .ans { margin-top: 8px; font-size: 14px; }
.paa .ans.own { background: var(--accent-soft); border-radius: 12px; padding: 8px 12px; }
.paa .ans a { color: #1a4fa0; font-weight: 600; }
.paa .noans { color: var(--muted); }

.imggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.imggrid figure { margin: 0; }
.imggrid .ph { aspect-ratio: 1; border-radius: 14px; background: #efeae0 center / cover no-repeat; display: block; }
.imggrid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 14px; display: block; background: #efeae0; }
.imggrid figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; word-break: break-word; }
.imggrid .own figcaption { color: var(--accent); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips span { background: #efeae0; border-radius: 999px; padding: 4px 14px; font-size: 13.5px; }
.refs { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13.5px; }
.refs li { padding: 3px 0; }
.refs a { color: #1a4fa0; }
.refs .own { font-weight: 600; color: var(--accent); }

.serp li { border-top: 0; padding: 12px 10px; border-radius: 14px; }
.serp li + li { margin-top: 2px; }
.serp .t a { color: #1a4fa0; text-decoration: none; }

@media (max-width: 860px) {
  .dlg .row4 { grid-template-columns: 1fr 1fr; }
}
.who-ev { font-weight: 600; }
.who-ev.own { color: var(--accent); }

/* ---------- ritocchi alla tabella e ai blocchi ---------- */
.bdg { white-space: nowrap; }
.blk.cont { background: var(--card); box-shadow: var(--shadow); padding: 18px 22px; }
#kwTable th, #kwTable td { padding-left: 10px; padding-right: 10px; }
#kwTable td.kw, #kwTable th:nth-child(2) { min-width: 200px; }
#kwTable td:nth-child(4) { min-width: 230px; }
#kwTable td:nth-child(5), #kwTable th:nth-child(5) { min-width: 190px; }
.spark { margin-top: 6px; line-height: 0; }
.snip { max-width: 340px; }
.rowact { width: 132px; }
.rowact .btn.block { display: block; width: 100%; margin-bottom: 6px; }
.rowact2 { display: flex; gap: 6px; justify-content: flex-end; }
.rowact2 .btn:first-child { flex: 1; }

/* ---------- accesso e uscita (versione online) ---------- */
.linkbtn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 10px 8px; margin-top: 14px; }
.linkbtn:hover { color: var(--down); }
.loginbox { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.loginbox .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; margin: 0; }
.loginbox h1 { font-size: 26px; }
.loginbox p { margin: 0; }
