:root {
  color-scheme: light;
}

html, body {
  margin: 0;
  font-family: var(--ts-font-family, 'Segoe UI', system-ui, sans-serif);
  background: var(--ts-background, #F4F7F5);
  color: var(--ts-text, #102018);
}

.cp-shell { display: flex; min-height: 100vh; }
.cp-sidebar {
  width: var(--ts-sidebar-width, 260px);
  background: var(--ts-primary-dark, #004225);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1rem .85rem;
  gap: 1rem;
  position: relative;
  z-index: 30;
  transition: width .2s ease;
}
.cp-shell-collapsed .cp-sidebar { width: var(--ts-sidebar-width-compact, 72px); }
.cp-shell-collapsed .cp-nav-label,
.cp-shell-collapsed .cp-brand-sub,
.cp-shell-collapsed .cp-profile-name { display: none; }
.cp-brand { display: flex; flex-direction: column; gap: .25rem; padding: .25rem .5rem; }
.cp-brand strong { font-size: 1.05rem; }
.cp-brand-sub { opacity: .85; font-size: .85rem; }
.cp-collapse-btn {
  display: none;
  align-self: flex-end;
  background: rgba(255,255,255,.12);
  border: 0; color: #fff; border-radius: 6px;
  min-width: var(--ts-touch-min, 44px); min-height: var(--ts-touch-min, 44px);
  width: auto; height: auto; padding: .5rem; cursor: pointer;
}
.cp-nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.cp-nav a {
  color: #fff; text-decoration: none; padding: .7rem .75rem; border-radius: 8px;
  font-size: 1rem; display: flex; align-items: center; gap: .65rem; min-height: 44px;
}
.cp-nav a.active, .cp-nav a:hover { background: rgba(255,255,255,.12); }
.cp-nav-ico { width: 1.25rem; text-align: center; }
.cp-sidebar-footer { display: flex; flex-direction: column; gap: .65rem; margin-top: auto; }
.cp-bell { background: transparent; border: 0; color: #fff; opacity: .5; font-size: 1.1rem; cursor: not-allowed; position: relative; }
.cp-bell-active { opacity: 1; cursor: pointer; }
.cp-bell-wrap { position: relative; }
.cp-bell-badge {
  position: absolute; top: -4px; right: -6px; min-width: 1.1rem; height: 1.1rem;
  padding: 0 .25rem; border-radius: 999px; background: #1F7036; color: #fff;
  font-size: .65rem; font-weight: 700; display: inline-grid; place-items: center;
  border: 1px solid #004225;
}
.cp-bell-panel {
  position: absolute; bottom: 2.2rem; left: 0; width: min(20rem, 80vw);
  background: #fff; color: #1a1a1a; border: 1px solid #DDE7E0; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: .75rem; z-index: 40;
}
.cp-bell-list { list-style: none; margin: 0 0 .75rem; padding: 0; max-height: 16rem; overflow: auto; }
.cp-bell-item {
  width: 100%; text-align: left; border: 0; background: transparent; padding: .5rem;
  border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: .15rem;
}
.cp-bell-item:hover { background: #F3F7F4; }
.cp-bell-item.unread { border-left: 3px solid #1F7036; }
.cp-row-unread { background: #F7FBF8; }
.cp-profile { display: flex; align-items: center; gap: .5rem; padding: .25rem .4rem; }
.cp-avatar {
  width: 2rem; height: 2rem; border-radius: 50%; background: #1F7036;
  display: grid; place-items: center; font-weight: 700;
}
.cp-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.cp-topbar {
  display: none; align-items: center; gap: .75rem;
  padding: .75rem 1rem; background: #fff; border-bottom: 1px solid var(--ts-border, #DDE7E0);
}
.cp-menu-btn {
  border: 0; background: #1F7036; color: #fff; border-radius: 8px;
  width: 2.5rem; height: 2.5rem; font-size: 1.2rem; cursor: pointer;
}
.cp-main { flex: 1; padding: 1.5rem; }
.cp-logout { margin-top: 0; }
.cp-backdrop { display: none; }

.cp-auth-layout {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: linear-gradient(160deg, #004225 0%, #1F7036 55%, #F4F7F5 55%);
}
.cp-auth-card {
  width: min(420px, 100%);
  background: #fff; border-radius: 12px; padding: 1.75rem;
  box-shadow: 0 8px 24px rgba(16,32,24,.12);
}
.cp-auth-brand { margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: .2rem; }
.cp-auth-brand strong { color: #004225; font-size: 1.2rem; }

.cp-form { display: flex; flex-direction: column; gap: 1rem; }
.cp-form label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; }
.cp-form input {
  border: 1px solid var(--ts-border, #DDE7E0);
  border-radius: 8px; padding: .75rem .85rem; font-size: 1rem;
}
.cp-btn {
  border: 0; border-radius: 8px; padding: .85rem 1rem; font-size: 1rem; font-weight: 600; cursor: pointer;
  min-height: 44px;
}
.cp-btn-primary { background: #1F7036; color: #fff; }
.cp-btn-primary:hover { background: #004225; }
.cp-btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); width: 100%; }
.cp-error { color: #78350f; background: #fffbeb; border-left: 4px solid #d97706; padding: .75rem; border-radius: 6px; }
.cp-ok { color: #004225; background: #e8f5ec; padding: .75rem; border-radius: 6px; }
.cp-muted { color: var(--ts-text-muted, #5a6b60); }
.cp-empty { color: var(--ts-text-muted, #5a6b60); margin: 0; }
.cp-loading { padding: 1rem; color: var(--ts-text-muted, #5a6b60); }
.cp-links { margin-top: 1rem; font-size: .95rem; }
.cp-links a { color: #1F7036; }
.cp-card {
  background: #fff; border: 1px solid var(--ts-border, #DDE7E0); border-radius: 12px; padding: 1.25rem;
  box-shadow: var(--ts-shadow, 0 1px 3px rgba(16,32,24,.08));
}
.cp-card h2 { margin: 0 0 .75rem; font-size: 1.05rem; color: #004225; }
.cp-dash-header { margin-bottom: 1.25rem; }
.cp-dash-header h1 { margin: 0 0 .35rem; font-size: clamp(1.4rem, 2vw, 1.85rem); color: #004225; }
.cp-dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.cp-card-wide { grid-column: 1 / -1; }
.cp-action-list, .cp-timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .65rem; }
.cp-job { display: flex; flex-direction: column; gap: .25rem; padding: .5rem 0; border-bottom: 1px solid var(--ts-border, #DDE7E0); }

@media (min-width: 901px) {
  .cp-collapse-btn { display: inline-flex; align-items: center; justify-content: center; }
}

@media (max-width: 900px) {
  .cp-sidebar {
    position: fixed; inset: 0 auto 0 0; transform: translateX(-105%);
    width: min(280px, 86vw); box-shadow: 0 8px 24px rgba(0,0,0,.2);
  }
  .cp-drawer-open .cp-sidebar { transform: translateX(0); }
  .cp-drawer-open .cp-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(16,32,24,.45); z-index: 20;
  }
  .cp-topbar { display: flex; }
  .cp-collapse-btn { display: none; }
  .cp-dash-grid { grid-template-columns: 1fr; }
  .cp-shell-collapsed .cp-sidebar { width: min(280px, 86vw); }
  .cp-shell-collapsed .cp-nav-label,
  .cp-shell-collapsed .cp-brand-sub,
  .cp-shell-collapsed .cp-profile-name { display: inline; }
}

@media (min-width: 1200px) {
  .cp-dash-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cp-card-wide { grid-column: 1 / -1; }
}

.cp-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
  background: #fff;
  border: 1px solid var(--ts-border, #DDE7E0);
  border-radius: 12px;
  padding: 1rem;
}
.cp-filters label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .9rem; }
.cp-filters input, .cp-filters select {
  border: 1px solid var(--ts-border, #DDE7E0); border-radius: 8px; padding: .55rem .65rem; min-height: 44px;
}
.cp-check { flex-direction: row !important; align-items: center; gap: .5rem !important; }
.cp-table-wrap { overflow-x: auto; background: #fff; border-radius: 12px; border: 1px solid var(--ts-border, #DDE7E0); }
.cp-table { width: 100%; border-collapse: collapse; }
.cp-table th, .cp-table td { padding: .75rem; text-align: left; border-bottom: 1px solid var(--ts-border, #DDE7E0); }
.cp-table th { background: #004225; color: #fff; }
.cp-badge {
  display: inline-block; padding: .2rem .55rem; border-radius: 999px;
  background: #E8F2EC; color: #004225; font-size: .85rem; font-weight: 600;
}
.cp-offerte-cards { display: none; gap: .85rem; }
.cp-pager { display: flex; gap: .75rem; align-items: center; margin-top: 1rem; }
.cp-doc-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .65rem; }
.cp-doc-list li { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.cp-warn {
  background: #FFF8E8; border: 1px solid #E6D7A8; color: #5C4B12;
  border-radius: 12px; padding: 1rem; margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .cp-offerte-desktop { display: none; }
  .cp-offerte-cards { display: grid; }
}

.cp-progress {
  height: 10px; background: #E8F2EC; border-radius: 999px; overflow: hidden; margin: .5rem 0;
}
.cp-progress-bar { height: 100%; background: #1F7036; border-radius: 999px; }

.cp-header-actions, .cp-action-row, .cp-upload-row {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.cp-btn-secondary { background: #E8F2EC; color: #004225; border: 1px solid #BFD5C6; }
.cp-btn-danger { background: #8B2E2E; color: #fff; }
.cp-card-list { display: grid; gap: .85rem; }
.cp-mobile-only { display: none; }
.cp-assistenza-form { display: grid; gap: 1rem; max-width: 900px; }
.cp-assistenza-form label, .cp-reply label {
  display: flex; flex-direction: column; gap: .35rem; margin: .65rem 0; font-weight: 600;
}
.cp-assistenza-form input, .cp-assistenza-form select, .cp-assistenza-form textarea, .cp-reply textarea {
  border: 1px solid var(--ts-border, #DDE7E0); border-radius: 8px; padding: .7rem; font: inherit;
}
.cp-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.cp-summary { display: flex; flex-direction: column; gap: .3rem; margin-top: 1rem; padding: .85rem; background: #F3F7F4; border-radius: 8px; }
.cp-preline { white-space: pre-line; }
.cp-chat { display: flex; flex-direction: column; gap: .75rem; margin: 1rem 0; }
.cp-chat-bubble { max-width: min(78%, 760px); padding: .85rem 1rem; border-radius: 12px; }
.cp-chat-bubble header { display: flex; justify-content: space-between; gap: 1rem; font-size: .85rem; }
.cp-chat-bubble time { color: var(--ts-text-muted, #5a6b60); }
.cp-chat-bubble p { margin: .45rem 0 0; }
.cp-chat-client { align-self: flex-end; background: #E8F2EC; border-bottom-right-radius: 3px; }
.cp-chat-titon { align-self: flex-start; background: #F3F4F6; border-bottom-left-radius: 3px; }
.cp-attachments { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.cp-reply { border-top: 1px solid var(--ts-border, #DDE7E0); padding-top: .75rem; }

@media (max-width: 900px) {
  .cp-desktop-only { display: none; }
  .cp-mobile-only { display: grid; }
  .cp-form-grid { grid-template-columns: 1fr; }
  .cp-chat-bubble { max-width: 92%; }
}

/* === PC-W12: safe area, skip link, rete, PWA, a11y === */
.cp-skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: #1F7036; color: #fff; padding: .75rem 1rem; border-radius: 0 0 8px 0;
}
.cp-skip-link:focus { left: 0; }
.cp-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.cp-shell, .cp-main, .cp-topbar {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.cp-main { padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); max-width: 1200px; }
.cp-topbar { justify-content: flex-start; }
.cp-topbar-title { flex: 1; font-weight: 700; color: #004225; }
.cp-topbar-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.cp-topbar-bell {
  min-width: 44px; min-height: 44px; color: #004225 !important; opacity: 1 !important;
  background: #E8F2EC; border-radius: 8px; border: 0; position: relative;
}
.cp-btn-on-light { color: #004225 !important; border-color: #BFD5C6 !important; }
.cp-pager .cp-btn-ghost { color: #004225; border-color: #BFD5C6; width: auto; }
.cp-net-banner {
  position: sticky; top: 0; z-index: 90; text-align: center; padding: .55rem 1rem;
  font-weight: 600; font-size: .95rem;
}
.cp-net-banner--offline { background: #FFF8E8; color: #5C4B12; border-bottom: 1px solid #E6D7A8; }
.cp-net-banner--online { background: #E8F2EC; color: #004225; border-bottom: 1px solid #BFD5C6; }
.cp-pwa-install-bar, .cp-pwa-ios-help {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between;
  background: #fff; border: 1px solid #DDE7E0; border-radius: 10px; padding: .75rem 1rem; margin: .75rem 1rem 0;
  box-shadow: var(--ts-shadow);
}
.cp-card-title { margin: 0 0 .35rem; font-size: 1.05rem; color: #004225; }
.cp-bell { min-width: 44px; min-height: 44px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
html { overflow-x: hidden; }
body { overflow-x: hidden; }
