:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2f5bea; --accent-soft: #e8eefe; --green: #1f8a4c; --green-soft: #e3f5ea;
  --amber: #b36b00; --amber-soft: #fff3dc; --red: #c23a3a; --red-soft: #fde8e8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1b2029; --text: #e6e9ef; --muted: #939bad; --line: #2c3340;
    --accent: #7c9cff; --accent-soft: #1f2a48; --green: #5ccf8c; --green-soft: #173325;
    --amber: #f0b24f; --amber-soft: #3a2c14; --red: #f07a7a; --red-soft: #3d1c1c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
code { background: var(--accent-soft); padding: 0 .3em; border-radius: 4px; }

.topbar { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; padding: .6rem 1.5rem;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 800; font-size: 1.1rem; color: var(--text); letter-spacing: -.02em; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: var(--muted); padding: .35rem .7rem; border-radius: 8px; }
.topbar nav a.on, .topbar nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.scanning { color: var(--amber); font-size: .9rem; }
main { max-width: 1250px; margin: 0 auto; padding: 1.5rem; }

.flash { background: var(--green-soft); color: var(--green); padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }
.warn { color: var(--amber); } .err { color: var(--red); }
.empty { color: var(--muted); padding: 2rem; text-align: center; }
.pill { background: var(--accent); color: #fff; border-radius: 99px; padding: 0 .5em; font-size: .8rem; font-weight: 600; }
.tag { font-size: .78rem; padding: .05rem .45rem; border-radius: 6px; background: var(--line); color: var(--muted); }
.tag.red { background: var(--red-soft); color: var(--red); } .tag.green { background: var(--green-soft); color: var(--green); }

.btn { display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 8px;
  padding: .45rem .9rem; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.small { padding: .2rem .6rem; font-size: .85rem; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; }
.linkbtn:hover { color: var(--red); }

input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: .45rem .6rem; width: 100%; }
input[type=file] { padding: .35rem; }
label { display: block; font-size: .88rem; color: var(--muted); }
label input, label select, label textarea { margin-top: .2rem; }
.stack { display: grid; gap: .7rem; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; align-items: end; margin-top: .8rem; }
.grid-form .full, .grid-form details { grid-column: 1 / -1; }
.grid-form .wide { grid-column: span 2; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[name=q] { flex: 1; min-width: 200px; width: auto; }
.filters select { width: auto; } .narrow { width: 5rem !important; }
.inline { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; } .inline input { width: auto; } .inline .wide { flex: 1; min-width: 250px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1.5rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1.1rem; color: var(--text); }
.stat b { display: block; font-size: 1.8rem; line-height: 1.1; } .stat span { color: var(--muted); font-size: .88rem; }
.stat:hover { border-color: var(--accent); text-decoration: none; }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.5rem; }
.grid2.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid2, .grid2.even { grid-template-columns: 1fr; } .grid-form .wide { grid-column: auto; } }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.setup ol { margin: 0; padding-left: 1.2rem; } .setup li.done { text-decoration: line-through; color: var(--muted); }

.job { display: flex; gap: 1rem; align-items: flex-start; padding: .9rem 1rem; }
.job.unseen { border-left: 4px solid var(--accent); }
.job.dismissed { opacity: .6; }
.job-body { flex: 1; min-width: 0; }
.job h3 { margin: 0 0 .2rem; font-size: 1.02rem; }
.job h3 a { color: var(--text); }
.meta { color: var(--muted); font-size: .88rem; }
.chips { margin-top: .4rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.chip { background: var(--accent-soft); color: var(--accent); font-size: .78rem; padding: .05rem .5rem; border-radius: 99px; }
.actions { display: flex; flex-direction: column; gap: .35rem; align-items: stretch; }
.actions form, .row-actions form { margin: 0; }
.actions .btn { width: 100%; text-align: center; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .8rem; }
td.row-actions { margin: 0; }
@media (max-width: 700px) { .job { flex-wrap: wrap; } .actions { flex-direction: row; flex-wrap: wrap; width: 100%; } .actions .btn { width: auto; } }

.score { flex: none; width: 3rem; height: 3rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; }
.score.high { background: var(--green-soft); color: var(--green); }
.score.mid { background: var(--amber-soft); color: var(--amber); }
.score.low { background: var(--line); color: var(--muted); }
.detail-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.detail-head h1 { margin: 0; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; }
.cvtext { white-space: pre-wrap; max-height: 400px; overflow: auto; font-size: .8rem; background: var(--bg); padding: .8rem; border-radius: 8px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: var(--accent-soft); }
tr.inactive { opacity: .55; }
details.edit summary { cursor: pointer; color: var(--muted); }
details summary { cursor: pointer; }

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .4rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--accent); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.status { font-size: .8rem; font-weight: 600; padding: .15rem .55rem; border-radius: 99px; background: var(--line); color: var(--muted); white-space: nowrap; }
.s-inviata { background: var(--accent-soft); color: var(--accent); }
.s-in-valutazione, .s-colloquio { background: var(--amber-soft); color: var(--amber); }
.s-offerta, .s-accettata { background: var(--green-soft); color: var(--green); }
.s-rifiutata { background: var(--red-soft); color: var(--red); }

.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); margin-left: .5rem; }
.timeline li { display: flex; gap: 1rem; padding: 0 0 1.1rem 1rem; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .35rem; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.tl-date { color: var(--muted); font-size: .88rem; min-width: 5.5rem; }
.tl-body { flex: 1; }
.row-line { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.row-line:last-child { border-bottom: 0; }
.log-mini { font-size: .88rem; padding: .25rem 0; }
.pager { display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; }

/* ---- account, filtri, paginazione, import ---- */
.account-menu { display: flex; gap: .7rem; align-items: center; font-size: .88rem; }
.account-menu a { color: var(--muted); max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu a.on { color: var(--accent); }
.account-menu form { margin: 0; }
.flash.error { background: var(--red-soft); color: var(--red); }
.tag.blue { background: var(--accent-soft); color: var(--accent); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
body.auth { display: grid; place-items: start center; min-height: 100vh; }
.auth-box { width: 100%; max-width: 420px; margin: 0; padding: 3rem 1.2rem; }
.auth-box .brand { display: block; font-size: 1.6rem; margin-bottom: 1.2rem; }
.auth-box .card { margin-bottom: .8rem; }
.danger-zone { border-color: var(--red); }
label.check { display: flex; gap: .5rem; align-items: flex-start; color: var(--text); }
label.check input { width: auto; margin-top: .25rem; }
label.inl { display: inline-flex; align-items: center; gap: .4rem; }
.filters details.more { flex-basis: 100%; }
.filters details.more .grid-form { margin-top: .6rem; }
fieldset.sources { border: 1px solid var(--line); border-radius: 8px; padding: .4rem .7rem; margin: 0; }
fieldset.sources legend { font-size: .8rem; color: var(--muted); padding: 0 .3rem; }
.pager { display: flex; gap: 1rem 1.5rem; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 1rem; font-size: .9rem; }
.pager .pages { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; }
.pager a { padding: .15rem .55rem; border-radius: 6px; }
.pager a.cur { background: var(--accent); color: #fff; }
.pager .perpage a { padding: .1rem .4rem; }
.progress { height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; max-width: 600px; }
.progress div { height: 100%; background: var(--accent); transition: width .4s; }
table.plain td { border: 0; padding: .35rem .5rem .35rem 0; }
.suggestions { margin-top: .8rem; align-items: center; }
button.chip { border: 0; cursor: pointer; font: inherit; font-size: .78rem; }
button.chip:hover { filter: brightness(.95); }
td input { min-width: 9rem; }

/* ---- barra superiore: altezza fissa, icone ---- */
.topbar { min-height: 3.4rem; }
.icon-btn { width: 2.2rem; height: 2.2rem; display: inline-grid; place-items: center; flex: none; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; padding: 0; }
.icon-btn:hover, .icon-btn.on { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.icon-btn.spinning { color: var(--amber); }
.icon-btn.spinning svg { animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-menu { position: relative; }
/* il wrapper .popover ha il padding superiore: così passando dall'icona al popover il mouse non esce dall'area */
.popover { position: absolute; right: 0; top: 100%; padding-top: .45rem; z-index: 10; display: none; }
.scan-menu:hover .popover, .scan-menu.open .popover { display: block; }
.pop-inner { width: 210px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .14); font-size: .88rem; line-height: 1.35; }
.pop-inner form { margin: .5rem 0 0; }
.pop-inner .btn { width: 100%; text-align: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress.small { height: 5px; margin: .45rem 0 0; }
.logout { margin: 0; }
.account-menu { display: none; }

/* barra sempre su una riga: se non c'è spazio i link scorrono in orizzontale */
.topbar { flex-wrap: nowrap; gap: 1rem; }
.topbar .brand { white-space: nowrap; }
.topbar nav { flex-wrap: nowrap; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a { white-space: nowrap; }
@media (max-width: 700px) { .topbar { padding: .6rem 1rem; } }

/* ---- tabella aziende: sempre entro lo schermo, senza scorrimento orizzontale ---- */
.companies-table { table-layout: auto; }
.companies-table td, .companies-table th { overflow-wrap: anywhere; word-break: break-word; }
.companies-table td:first-child { min-width: 14rem; width: 42%; }
.companies-table td.col-actions { display: flex; flex-direction: column; gap: .3rem; align-items: stretch; min-width: 7.5rem; border-bottom: 0; }
.companies-table td.col-actions .btn { width: 100%; text-align: center; white-space: nowrap; }
.companies-table td.col-actions form { margin: 0; }
.companies-table tr { border-bottom: 1px solid var(--line); }
.companies-table th, .companies-table td { padding: .55rem .6rem; }
.companies-table details.edit .inline input { width: 100%; min-width: 0; }
.companies-table details.edit .inline .wide { flex-basis: 100%; min-width: 0; }
.companies-table td input { min-width: 0; }
@media (max-width: 760px) {
  .companies-table thead { display: none; }
  .companies-table, .companies-table tbody, .companies-table tr, .companies-table td { display: block; width: 100%; }
  .companies-table tr { padding: .6rem .4rem; }
  .companies-table td { border: 0; padding: .2rem .6rem; }
  .companies-table td:first-child { width: 100%; min-width: 0; }
  .companies-table td.col-actions { flex-direction: row; flex-wrap: wrap; min-width: 0; }
  .companies-table td.col-actions .btn { width: auto; }
}
.companies-table .num { white-space: nowrap; overflow-wrap: normal; word-break: normal; text-align: center; width: 1%; }
.companies-table td:first-child { width: auto; }
.companies-table .pill { display: inline-block; white-space: nowrap; }
@media (max-width: 760px) { .companies-table .num { display: inline-block; width: auto; text-align: left; padding-right: .3rem; }
  .companies-table td.num::before { content: attr(data-l) ": "; color: var(--muted); } }

.note { color: var(--muted); font-style: italic; margin: .15rem 0; }

.howto h3 { margin: 0 0 .3rem; font-size: .98rem; }
.howto p { margin: .3rem 0; }
