/* Design system shared with Abbonamenti (righettiservice.ch). Keep the token
   names and values in sync with that app so the two look like siblings. */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dfe3e8;
  --border-strong: #c6ccd4;
  --text: #1b1f24;
  --muted: #656d76;
  --accent: #2f6fd0;
  --accent-text: #ffffff;
  --overdue: #b3261e;
  --overdue-bg: #fdeceb;
  --soon: #9a6400;
  --soon-bg: #fdf4e3;
  --ok: #1f7a44;
  --ok-bg: #edf7f1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #22262b;
    --border: #2f353c;
    --border-strong: #414952;
    --text: #e6e9ec;
    --muted: #9aa4af;
    --accent: #5b9bf8;
    --accent-text: #0d1117;
    --overdue: #f4756b;
    --overdue-bg: #35211f;
    --soon: #e0aa4a;
    --soon-bg: #332a1b;
    --ok: #62c98c;
    --ok-bg: #1a2b21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14171a;
  --surface: #1c2024;
  --surface-2: #22262b;
  --border: #2f353c;
  --border-strong: #414952;
  --text: #e6e9ec;
  --muted: #9aa4af;
  --accent: #5b9bf8;
  --accent-text: #0d1117;
  --overdue: #f4756b;
  --overdue-bg: #35211f;
  --soon: #e0aa4a;
  --soon-bg: #332a1b;
  --ok: #62c98c;
  --ok-bg: #1a2b21;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { color: var(--muted); margin: .35rem 0 0; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */

header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 20px clamp(16px, 3vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 15px; min-width: 0; color: var(--text); }
.brand:hover { text-decoration: none; }
.company-logo { display: block; width: clamp(120px, 12vw, 156px); height: auto; }
.brand-text { font-weight: 650; letter-spacing: -.01em; }
.brand-text small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
nav form, .actions form { margin: 0; }

/* ---------- buttons ---------- */

button, .button {
  font: inherit;
  font-size: 14px;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-block;
}

button:hover, .button:hover { filter: brightness(1.07); text-decoration: none; }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled, button:disabled:hover { opacity: .45; cursor: not-allowed; filter: none; }

.secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
  font-weight: 500;
}
.secondary:hover { background: var(--surface-2); filter: none; }

.text-button, nav .text-button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 7px 10px;
}
.text-button:hover { background: var(--surface-2); color: var(--text); filter: none; }

.small-button { padding: 5px 10px; font-size: 13px; }
.warning { background: var(--soon); border-color: var(--soon); color: var(--accent-text); }

.theme-toggle { display: inline-flex; align-items: center; gap: 6px; }
.theme-toggle-icon { width: 1.1em; text-align: center; line-height: 1; }

/* ---------- layout ---------- */

main { max-width: 1240px; margin: 0 auto; padding: 32px clamp(16px, 3vw, 40px) 80px; }

.page-heading, .request-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

h1 { font-size: 22px; letter-spacing: -.01em; margin: 0; }
h2 { margin: .1rem 0; font-size: 17px; }
h3 { font-size: 15px; }
.page-heading p, .request-heading p, .section-heading p, .integration-title p { margin: 2px 0 0; font-size: 13px; }

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: .05em;
  font-weight: 650;
  text-transform: uppercase;
}

.actions, .workflow-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 18px; font-size: 14px; }

/* ---------- banners ---------- */

.alert {
  margin: 14px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--ok);
  background: var(--ok-bg);
  color: var(--ok);
  font-size: 14px;
}
.alert.error { background: var(--overdue-bg); border-color: var(--overdue); color: var(--overdue); }

/* ---------- stats ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.stat.is-overdue .stat-value { color: var(--overdue); }
.stat.is-soon .stat-value { color: var(--soon); }
.stat.is-ok .stat-value { color: var(--ok); }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow: auto; }

.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 11px 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 600;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab span { padding: 1px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; font-weight: 500; }
.tab.selected { color: var(--accent); border-color: var(--accent); }

/* ---------- cards and tables ---------- */

.table-card, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.table-card { margin-top: 18px; overflow-x: auto; }
.card { padding: 24px; margin-bottom: 18px; }
.card hr { border: 0; border-top: 1px solid var(--border); margin: 26px 0; }

table { width: 100%; min-width: 940px; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 15px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
td small { display: block; color: var(--muted); margin-top: 5px; max-width: 420px; line-height: 1.5; }

/* ---------- status pills ---------- */

.status {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.status-new { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.status-in_review { background: var(--soon-bg); border-color: var(--soon); color: var(--soon); }
.status-needs_changes { background: var(--overdue-bg); border-color: var(--overdue); color: var(--overdue); }
.status-approved { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.status-exported { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }

.source-pill {
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- empty state ---------- */

.empty {
  display: flex;
  align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty > span { font-size: 26px; color: var(--muted); }
.empty h2 { margin: 0 0 6px; font-size: 17px; color: var(--text); }
.empty p { margin: 0 0 12px; font-size: 14px; }

/* ---------- forms ---------- */

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(300px, .8fr); gap: 20px; align-items: start; }
.section-heading, .integration-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }

label { display: block; margin: 16px 0; font-weight: 600; font-size: 13.5px; }
label small { display: block; color: var(--muted); font-weight: 400; margin-top: 4px; }

input, textarea, select {
  width: 100%;
  margin-top: 6px;
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea { resize: vertical; }

/* ---------- export panel ---------- */

.workflow-actions { justify-content: flex-end; margin-top: 18px; }
.export-card { border-color: var(--accent); }
.export-button { width: 100%; }

.success-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ok-bg);
  border: 1px solid var(--ok);
  color: var(--ok);
  font-size: 1.2rem;
  margin: 14px 0;
}

/* ---------- activity timeline ---------- */

.activity { list-style: none; padding: 0; margin: 0; }
.activity li { position: relative; padding: 0 0 20px 20px; border-left: 2px solid var(--border); }
.activity li:last-child { border-color: transparent; padding-bottom: 0; }
.activity li:before {
  content: "";
  position: absolute;
  left: -5px;
  top: 5px;
  width: 8px;
  height: 8px;
  background: var(--border-strong);
  border-radius: 50%;
}
.activity span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.activity p { margin: .35rem 0 0; font-size: 13.5px; }

/* ---------- raw source ---------- */

.source summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.source pre {
  max-height: 450px;
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
}

/* ---------- integrations ---------- */

.integration { padding: 26px; }
.integration-title { justify-content: flex-start; }
.integration-logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--accent-text);
  font-weight: 700;
  font-size: 13px;
}
.connecteam { background: var(--accent); }
.bexio { background: var(--ok); }

/* ---------- login ---------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: min(400px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .company-logo { width: min(200px, 70%); margin: 0 auto 18px; }
.login-card h1 { margin-bottom: 4px; }
.login-card label { text-align: left; }
.login-card button { width: 100%; margin-top: 6px; }

/* ---------- footer ---------- */

.foot { margin-top: 28px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  header { align-items: flex-start; }
  nav { justify-content: flex-end; }
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid.three { grid-template-columns: 1fr 1fr; }
  .table-card { overflow: auto; }
}

@media (max-width: 620px) {
  header, .page-heading, .request-heading { flex-direction: column; }
  nav { justify-content: flex-start; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .workflow-actions, .workflow-actions button { width: 100%; }
}
