/* Design system shared with Righetti Service's other internal apps
   (connecteam-bexio, Pinkline Reminder CRM). Keep the token names and
   values in sync so the apps 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);
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%231b1f24' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

@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);
    --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23e6e9ec' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    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);
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23e6e9ec' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  color-scheme: dark;
}

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

* { box-sizing: border-box; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; margin-top: 0; }
[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 calc(max(0px, (100% - 1240px) / 2) + 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; }
nav > :last-child { margin-right: -10px; }

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

button, .button {
  font: inherit;
  font-size: 14px;
  min-height: 40px;
  padding: 8px 14px;
  line-height: 1.4;
  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 { min-height: 0; 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, .case-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, .case-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: 780px; 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-open { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.status-in_progress { background: var(--soon-bg); border-color: var(--soon); color: var(--soon); }
.status-escalated { background: var(--overdue-bg); border-color: var(--overdue); color: var(--overdue); }
.status-disputed { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
.status-paid { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.status-written_off { background: var(--surface-2); border-color: var(--border); color: var(--muted); }

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

.empty {
  display: flex;
  align-items: center;
  flex-direction: column;
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  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;
  min-height: 40px;
  padding: 8px 12px;
  line-height: 1.4;
  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; min-height: 76px; }

select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 34px;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
}

/* ---------- 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;
}

/* ---------- 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, .case-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%; }
}

/* ---------- integration token warning ---------- */

.token-alert {
  padding: 12px clamp(16px, 3vw, 40px);
  background: var(--soon-bg);
  border-bottom: 1px solid var(--soon);
  color: var(--soon);
  font-size: 14px;
  text-align: center;
}
.token-alert.is-expired { background: var(--overdue-bg); border-bottom-color: var(--overdue); color: var(--overdue); }
.token-alert a { color: inherit; text-decoration: underline; font-weight: 600; }

/* ---------- dashboard sections ---------- */

.dashboard-section { margin-top: 28px; }
.dashboard-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.dashboard-section-heading h2 { font-size: 17px; letter-spacing: -.01em; margin: 0; }
.dashboard-section-heading p { margin: 2px 0 0; font-size: 13px; }
.queue-count {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 17px;
  font-weight: 650;
}
.action-queue { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); box-shadow: var(--shadow); }
.action-queue .table-card { margin-top: 0; box-shadow: none; }
.all-cases { padding-top: 6px; }
.all-cases .tabs { margin-top: 14px; }
@media (max-width: 620px) { .dashboard-section-heading { align-items: flex-start; } .action-queue { padding: 14px; } }

/* ---------- filter bar ---------- */

.search-card { margin: 14px 0 0; padding: 14px; }
.search-card label { margin: 0; }
.search-grid { display: grid; grid-template-columns: minmax(160px, 1fr) auto; gap: 10px; align-items: end; }
@media (max-width: 620px) { .search-grid { grid-template-columns: 1fr; } }

/* ---------- user cards ---------- */

.user-pill { display: inline-flex; gap: 4px; align-items: center; min-height: 40px; padding: 4px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-size: 13px; }
a.user-pill:hover { background: var(--surface); color: var(--text); border-color: var(--border-strong); text-decoration: none; }
.check-label { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; color: var(--muted); }
.check-label input { width: auto; margin: 0; }

.user-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.user-card { margin: 0; }
.user-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.user-inactive { opacity: .62; }
.user-card button { margin-top: 10px; }
@media (max-width: 760px) { .user-grid { grid-template-columns: 1fr; } }
