:root {
  --bg: #0d1117; --bg2: #161b22; --bg3: #1c2128;
  --border: rgba(255,255,255,.09); --border-strong: rgba(255,255,255,.18);
  --text: #e6edf3; --muted: #8b949e;
  --accent: #58a6ff; --accent-strong: #1f6feb;
  --success: #3fb950; --success-bg: rgba(63,185,80,.12);
  --warning: #d29922; --warning-bg: rgba(210,153,34,.14);
  --danger: #f85149; --danger-bg: rgba(248,81,73,.12);
  --purple: #bc8cff; --purple-bg: rgba(188,140,255,.14);
  --radius: 10px; --gap: 1rem;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 15px/1.5 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin-bottom: .75rem; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: .5rem; background: var(--accent-strong); color: #fff; padding: .5rem 1rem; border-radius: 6px; z-index: 200; }
.skip-link:focus { left: .5rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 100; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 2rem; background: rgba(13,17,23,.9); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px var(--success); }
.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: .4rem .7rem; border-radius: 6px; }
.nav a:hover { color: var(--text); background: var(--bg3); text-decoration: none; }
.nav a[aria-current] { color: var(--text); background: var(--bg3); }
.main { max-width: 1280px; margin: 0 auto; padding: 1.5rem 2rem 4rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head .muted { margin-top: .25rem; }
.page-head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }

/* Controls */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--bg3); border: 1px solid var(--border-strong); border-radius: 8px; padding: .55rem .7rem; min-height: 40px; }
input[type=checkbox] { min-height: 0; width: 1.1rem; height: 1.1rem; accent-color: var(--accent-strong); }
textarea { width: 100%; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: .5rem 1rem;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--bg3); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; border-color: var(--border); }
.btn-sm { min-height: 34px; padding: .3rem .75rem; font-size: .9rem; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: #388bfd; border-color: #388bfd; }
.btn-ghost { background: transparent; }
.btn-link { background: transparent; border-color: transparent; color: var(--accent); }
.btn-link:hover { border-color: transparent; text-decoration: underline; }
.stack { display: grid; gap: .6rem; }

/* Toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 300; display: grid; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1rem; border-radius: var(--radius);
  background: var(--bg2); border: 1px solid var(--border-strong); border-left: 4px solid var(--accent); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

/* Dashboard */
.scanbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .75rem 1rem;
  margin-bottom: 1.25rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); }
.scanbar[data-active] .scan-text::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: .5rem; border-radius: 50%;
  background: var(--warning); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 1rem; scrollbar-width: none; }
.tabs a { padding: .6rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count { display: inline-block; min-width: 1.6em; padding: 0 .4em; margin-left: .25rem; border-radius: 99px; background: var(--bg3); font-size: .8rem; text-align: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1.25rem; }
.toolbar input[type=search] { flex: 1 1 260px; }
.field-inline, .check-inline { display: inline-flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .9rem; }
.results-title { font-size: 1rem; color: var(--muted); font-weight: 500; margin-bottom: .75rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--gap); }
.empty { grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty h2 { color: var(--text); }
.empty .btn { margin-top: 1rem; }

/* Cards */
.card { display: flex; flex-direction: column; gap: .7rem; padding: 1rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color .15s, opacity .2s; scroll-margin-top: 90px; }
.card:hover { border-color: var(--border-strong); }
.card:target { border-color: var(--accent); }
.card.is-watchlist { border-left: 3px solid var(--purple); }
.card.is-rejected, .card.is-expired { opacity: .6; }
.card-head { display: flex; gap: .75rem; align-items: flex-start; }
.logo { width: 40px; height: 40px; flex: none; border-radius: 8px; object-fit: contain; background: #fff; }
.logo-lg { width: 56px; height: 56px; }
.logo-fallback { display: grid; place-items: center; background: var(--bg3); color: var(--muted); font-weight: 700; }
.card-title-wrap { flex: 1; min-width: 0; }
.card-title { color: var(--text); font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.card-company { color: var(--muted); font-size: .9rem; }
.score { flex: none; padding: .15rem .5rem; border-radius: 6px; font-weight: 700; background: var(--bg3); }
.score small { font-weight: 400; color: var(--muted); }
.score-5, .score-4 { background: var(--success-bg); color: var(--success); }
.score-3 { background: var(--warning-bg); color: var(--warning); }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag { padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; background: var(--bg3); color: var(--muted); border: 1px solid var(--border); }
.tag-new { background: rgba(88,166,255,.15); color: var(--accent); border-color: transparent; font-weight: 600; }
.tag-applied { background: var(--success-bg); color: var(--success); border-color: transparent; }
.tag-rejected, .tag-expired { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.tag-reply, .tag-watch { background: var(--purple-bg); color: var(--purple); border-color: transparent; }
.tag-warn { background: var(--warning-bg); color: var(--warning); border-color: transparent; display: inline-block; margin-top: .25rem; }
.facts { list-style: none; display: grid; gap: .15rem; color: var(--muted); font-size: .88rem; }
.card-summary { font-size: .88rem; padding: .5rem .65rem; border-radius: 6px; background: var(--success-bg); }
.card-actions { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-top: auto; padding-top: .7rem; border-top: 1px solid var(--border); }
.card-actions form { display: flex; gap: .4rem; flex-wrap: wrap; }

/* Detail */
.back { display: inline-block; margin-bottom: 1rem; }
.detail-head { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1.5rem; }
.detail-head .tags { margin-top: .6rem; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.detail-main, .detail-side { display: grid; gap: 1rem; }

.panel { padding: 1.1rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); }
.analysis { display: grid; gap: .5rem; margin: .5rem 0 .75rem; }
.analysis dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.analysis dd { padding: .5rem .7rem; border-radius: 6px; background: var(--bg3); }
.analysis dd.good { background: var(--success-bg); }
.analysis dd.bad { background: var(--danger-bg); }
.description { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; max-height: 70vh; overflow-y: auto; }
.facts-list { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; font-size: .9rem; }
.facts-list dt { color: var(--muted); }

/* Applications */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { padding: .8rem 1rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); }
.stat strong { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat-colloquio strong, .stat-offerta strong, .stat-si strong { color: var(--success); }
.stat-no strong, .stat-ghost strong { color: var(--danger); }
.callout { padding: .75rem 1rem; margin-bottom: 1rem; border-radius: var(--radius); background: var(--warning-bg); border: 1px solid rgba(210,153,34,.35); }
.callout-error { background: var(--danger-bg); border-color: rgba(248,81,73,.35); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { padding: .75rem 1rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg2); }
.table tr:last-child td { border-bottom: 0; }
.table tr.needs-followup td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.inline-form { display: flex; gap: .4rem; }

/* Settings */
.settings-layout { display: grid; grid-template-columns: 180px minmax(0, 860px); gap: 2rem; align-items: start; }
.settings-index { position: sticky; top: 84px; display: grid; gap: .15rem; }
.settings-index a { padding: .45rem .75rem; border-radius: 6px; color: var(--muted); border-left: 2px solid transparent; }
.settings-index a:hover { color: var(--text); background: var(--bg2); text-decoration: none; }
.settings { display: grid; gap: 1.25rem; min-width: 0; }
.settings-section { padding: 1.5rem; scroll-margin-top: 84px; }
.settings-section-head { margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.settings-section-head h2 { margin-bottom: .2rem; font-size: 1.15rem; }
.settings-section-head .usage { margin-top: .75rem; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem 1.5rem; }
.field { display: grid; gap: .35rem; align-content: start; }
.field label { font-weight: 500; }
.field-wide, .field-toggle { grid-column: 1 / -1; }
.field input:not([type=checkbox]), .field textarea, .field select { width: 100%; }
.field textarea { line-height: 1.5; }
.field-toggle { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1rem; padding: .85rem 1rem; border-radius: 8px; background: var(--bg3); }
.field-toggle label { cursor: pointer; }
.field-toggle .help { display: block; margin-top: .15rem; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; inset: 0; border-radius: 99px; background: #30363d; transition: background .15s; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent-strong); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.help { color: var(--muted); font-size: .84rem; line-height: 1.4; }
.error { color: var(--danger); font-size: .84rem; }
.has-error input, .has-error textarea { border-color: var(--danger); }
.usage { padding: .5rem .75rem; border-radius: 6px; background: var(--bg3); font-size: .9rem; display: inline-block; }
.savebar { position: sticky; bottom: 0; z-index: 50; display: flex; align-items: center; justify-content: flex-end; gap: 1rem;
  padding: .85rem 1rem; margin-top: .25rem; background: var(--bg2); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 -8px 24px rgba(0,0,0,.35); }
.savebar-status { color: var(--muted); font-size: .9rem; margin-right: auto; }
.savebar.is-dirty { border-color: var(--warning); }
.savebar.is-dirty .savebar-status { color: var(--warning); }
.errorlist { list-style: none; color: var(--danger); }

/* Logs */
.terminal { background: #010409; border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; font: .85rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; }
.log-row { display: grid; grid-template-columns: 9.5rem 5.5rem 1fr; gap: .75rem; padding: .2rem .25rem; border-radius: 4px; }
.log-row:hover { background: var(--bg2); }
.log-row time { color: var(--muted); }
.log-msg { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.level-warning strong { color: var(--warning); }
.level-error strong, .level-critical strong { color: var(--danger); }
.level-info strong { color: var(--accent); }

/* Login, pagination */
.login { max-width: 420px; margin: 4rem auto; }
.login .stack { margin-top: 1rem; }
.login input { width: 100%; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 2rem 0; color: var(--muted); }

@media (max-width: 900px) {
  .detail-layout, .settings-layout { grid-template-columns: 1fr; }
  .settings-index { position: static; display: flex; overflow-x: auto; gap: .25rem; scrollbar-width: none; }
  .settings-index a { white-space: nowrap; background: var(--bg2); }

}
@media (max-width: 640px) {
  .topbar { padding: .6rem 1rem; flex-wrap: wrap; }
  .nav { width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav { gap: 0; font-size: .88rem; }
  .nav a { padding: .4rem .45rem; }
  .nav .btn-sm { min-height: 30px; padding: .2rem .55rem; font-size: .85rem; }
  .fields { grid-template-columns: 1fr; }
  .settings-section { padding: 1.1rem; }
  .main { padding: 1rem 1rem 4rem; }
  .grid { grid-template-columns: 1fr; }
  .log-row { grid-template-columns: 1fr auto; }
  .log-msg { grid-column: 1 / -1; }
  .toolbar .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
