@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap");

:root {
  /* Brand tokens */
  --brand-50: #eef2ff;
  --brand-100: #dce4ff;
  --brand-500: #4a72ff;
  --brand-600: #3d66ff;
  --brand-700: #2f55e6;
  --deal-500: #10b981;
  --deal-600: #059669;
  --warn-500: #f59e0b;
  --warn-700: #b45309;
  --bad: #dc2626;

  --bg: #f6f7f9;
  --bg-2: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: var(--brand-600);
  --accent-2: var(--brand-700);
  --ok: var(--deal-600);
  --warn: var(--warn-700);
  --shadow: 0 1px 2px 0 rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.1);
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 14.5px/1.5 "Geist", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { color: var(--accent-2); text-decoration: underline; text-underline-offset: 2px; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--ink);
}
.brand:hover { text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: contain;
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
}

.wrap {
  padding: 1.25rem 1.1rem 2.25rem;
  max-width: 980px;
  margin: 0 auto;
}

h1, h2, h3 {
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.25;
  margin: 0 0 .55rem;
}
h1 { font-size: 1.625rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }

.hero-copy {
  max-width: 40rem;
  margin: 0 0 1rem;
  color: var(--muted);
  line-height: 1.55;
}

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

.cards { display: grid; gap: .7rem; }
.simple-list { max-width: 760px; }

.gestionale {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.gestionale:hover {
  text-decoration: none;
  border-color: color-mix(in srgb, var(--brand-500) 40%, var(--line));
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.gestionale .g-title { font-size: 1rem; font-weight: 650; letter-spacing: -0.02em; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  flex-wrap: wrap;
}
.gap { gap: .55rem; justify-content: flex-start; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .02em;
  padding: .18rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
}
.badge.ok, .badge.succeeded {
  color: var(--deal-600);
  border-color: #a7f3d0;
  background: #ecfdf5;
}
.badge.warn, .badge.queued {
  color: var(--warn-700);
  border-color: #fde68a;
  background: #fffbeb;
}
.badge.running {
  color: var(--brand-700);
  border-color: #b8c9ff;
  background: #eef2ff;
}
.badge.failed, .badge.cancelled {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.error {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
}
.ok-box {
  color: #065f46;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
}
.admin-form-grid {
  display: grid;
  gap: .55rem .85rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
select {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  background: #fff;
  color: var(--ink);
}

button, .linkish {
  appearance: none;
  border: 1px solid var(--brand-600);
  background: var(--brand-600);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: .5rem .85rem;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
button:hover { background: var(--brand-700); border-color: var(--brand-700); }
button.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  font-weight: 500;
}
button.secondary:hover { background: var(--bg-2); }
button.ai {
  background: #fff;
  color: var(--brand-700);
  border-color: color-mix(in srgb, var(--brand-500) 45%, var(--line));
}
button.ai:hover { background: var(--brand-50); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand-500) 55%, #fff);
  outline-offset: 2px;
}

button.linkish, .linkish {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 0;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

label { display: block; margin: .65rem 0; font-weight: 500; }
input, textarea {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 72px; resize: vertical; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(700px 320px at 10% -10%, color-mix(in srgb, var(--brand-100) 70%, transparent), transparent 60%),
    var(--bg);
}
.login-card { width: min(400px, 94vw); }
.login-card h1 { margin-bottom: .15rem; }

.section-gap { margin-top: 1.1rem; }

.jobs-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.jobs-card {
  overflow: hidden;
}
table.jobs {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.jobs th, table.jobs td {
  text-align: left;
  padding: .55rem .35rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.jobs th {
  color: var(--muted);
  font-weight: 650;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
table.jobs tr:hover td { background: var(--bg); }
.jobs-data,
.jobs-error {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.jobs-error { margin-top: .35rem; }

.job-block {
  border-top: 1px solid var(--line);
  padding: .85rem 0;
}
.job-block:first-child { border-top: none; padding-top: .15rem; }

.downloads {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin: .45rem 0;
}
.downloads a {
  display: inline-flex;
  align-items: center;
  padding: .32rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  text-decoration: none;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 550;
}
.downloads a:hover {
  border-color: var(--brand-500);
  color: var(--brand-700);
  background: var(--brand-50);
  text-decoration: none;
}

.log-wrap { margin-top: .55rem; }
.log-wrap summary { cursor: pointer; color: var(--muted); }
pre.log {
  background: #0f172a;
  color: #e2e8f0;
  padding: .8rem;
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow: auto;
  font: 12px/1.45 "Geist Mono", ui-monospace, monospace;
  white-space: pre-wrap;
  margin: .5rem 0 0;
}

.ai-box {
  margin-top: .7rem;
  padding: .85rem .95rem;
  border-radius: var(--radius);
  border: 1px dashed color-mix(in srgb, var(--brand-500) 35%, var(--line));
  background: #f8faff;
}
.ai-box h4 {
  margin: 0 0 .45rem;
  font-size: .95rem;
  letter-spacing: -0.01em;
}
.ai-answer {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.55;
}
.ai-meta {
  margin-top: .5rem;
  font-size: 12px;
  color: var(--muted);
}

.assistant-panel {
  margin-top: 1.2rem;
  border-left: 3px solid var(--brand-500);
}
.options-box {
  margin: .7rem 0 1rem;
  padding: .75rem .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.options-grid { display: grid; gap: .45rem; }
.option-item {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  margin: 0;
  font-weight: 500;
}
.option-item input {
  width: auto;
  margin: .2rem 0 0;
}

.status-panel .status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .8rem;
}
@media (max-width: 720px) {
  .status-panel .status-grid { grid-template-columns: 1fr; }
  .wrap { padding: 1rem .85rem 2rem; }
  .top { padding: .7rem .9rem; }
  h1 { font-size: 1.4rem; }
  button { width: 100%; }
  .row.gap { flex-direction: column; align-items: stretch; }
  .row.gap .linkish { width: auto; align-self: flex-start; }
  table.jobs thead { display: none; }
  table.jobs,
  table.jobs tbody,
  table.jobs tr,
  table.jobs td {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  table.jobs {
    table-layout: fixed;
  }
  table.jobs tr {
    padding: .75rem 0;
    border-bottom: 1px solid var(--line);
  }
  table.jobs tr:last-child { border-bottom: none; }
  table.jobs td {
    border-bottom: none;
    padding: .15rem 0;
  }
  table.jobs td.jobs-when { color: var(--muted); font-size: 12px; }
  table.jobs td.jobs-actions { margin-top: .25rem; }
  .card, .jobs-wrap, .wrap { max-width: 100%; }
  body { overflow-x: hidden; }
}

.advanced-panel summary,
details.card > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.advanced-panel summary::-webkit-details-marker,
details.card > summary::-webkit-details-marker { display: none; }

.toast-wrap {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: grid;
  gap: .5rem;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  background: #0f172a;
  color: #f8fafc;
  border-radius: var(--radius);
  padding: .75rem .9rem;
  box-shadow: var(--shadow-md);
  font-size: 13px;
}
.toast.ok { border-left: 3px solid #34d399; }
.toast.err { border-left: 3px solid #f87171; }
.toast.warn { border-left: 3px solid #fbbf24; }

.status-dot {
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

.steps {
  margin: .4rem 0 .9rem;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  .gestionale, button { transition: none; }
}
