:root{
  --bg: #f3f6fb;
  --panel: #ffffff;
  --border: rgba(10, 30, 60, .10);
  --text: #0b1f33;
  --muted: rgba(11, 31, 51, .62);
  --brand: #0176d3;
  --brand2: #0b5cab;
  --ok: #2e844a;
  --bad: #ba0517;
  --shadow: 0 8px 24px rgba(10, 30, 60, .08);
  --radius: 14px;
}

*{ box-sizing: border-box; }
html, body{ height:100%; }
body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Animated background layers - smooth, seamless flow */
body::before,
body::after {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  pointer-events: none;
  z-index: 0;
  opacity: 1;
}

body::before {
  background: 
    radial-gradient(1400px 700px at 50% 50%, rgba(1,118,211,.22), transparent 52%),
    radial-gradient(1000px 600px at 50% 50%, rgba(46,132,74,.16), transparent 55%);
  animation: gradientFloat1 28s ease-in-out infinite;
}

body::after {
  background: 
    radial-gradient(900px 500px at 50% 50%, rgba(1,118,211,.12), transparent 60%),
    radial-gradient(1200px 650px at 50% 50%, rgba(46,132,74,.10), transparent 52%);
  animation: gradientFloat2 32s ease-in-out infinite;
  animation-delay: -8s;
}

@keyframes gradientFloat1 {
  0% {
    transform: translate(0%, 0%) scale(1);
  }
  25% {
    transform: translate(3%, 4%) scale(1.08);
  }
  50% {
    transform: translate(-2%, 2%) scale(1.05);
  }
  75% {
    transform: translate(1%, -1%) scale(1.06);
  }
  100% {
    transform: translate(0%, 0%) scale(1);
  }
}

@keyframes gradientFloat2 {
  0% {
    transform: translate(0%, 0%) scale(1) rotate(0deg);
  }
  30% {
    transform: translate(-3%, -2%) scale(1.07) rotate(2deg);
  }
  60% {
    transform: translate(2%, -4%) scale(1.04) rotate(-1deg);
  }
  100% {
    transform: translate(0%, 0%) scale(1) rotate(0deg);
  }
}

.topbar{
  position: sticky;
  top:0;
  z-index: 100;
  height: 64px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.92), rgba(255,255,255,.78));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar__left,
.topbar__right{
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand{
  display:flex;
  align-items:center;
  gap: 12px;
}
.brand__mark{
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display:grid;
  place-items:center;
  color:white;
  font-weight: 700;
  letter-spacing: .5px;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  box-shadow: 0 10px 18px rgba(1,118,211,.22);
}
.brand__mark--image{
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
}
.brand__name{ font-weight: 700; line-height: 1.1; }
.brand__sub{ font-size: 12px; color: var(--muted); margin-top: 2px; }

.recent-chips{
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 56vw;
  overflow-x: auto;
  padding: 6px 2px;
  -webkit-overflow-scrolling: touch;
}

.recent-chip{
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.70);
  color: var(--text);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  transition: all 0.2s;
}

.recent-chip:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.25);
}

.pill{
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.7);
}

.shell{
  display:flex;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 18px;
  gap: 16px;
  position: relative;
  z-index: 1;
  flex: 1 0 auto;
}

.sidebar{
  width: 240px;
  flex: 0 0 240px;
}

.sidebar__section{
  background: rgba(255,255,255,.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.sidebar__now{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.70);
}
.sidebar__now-icon{
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--brand2);
  background: rgba(1,118,211,.10);
  border: 1px solid rgba(1,118,211,.18);
}
.sidebar__now-icon svg{
  width: 18px;
  height: 18px;
  display: block;
}
.sidebar__now-text{
  min-width: 0;
}
.sidebar__now-date{
  font-weight: 750;
  font-size: 13px;
  line-height: 1.15;
  text-transform: capitalize;
}
.sidebar__now-time{
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}
.sidebar__divider{
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}
.sidebar__label{
  font-size: 12px;
  color: var(--muted);
  margin: 2px 6px 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.navitem{
  display:block;
  padding: 10px 10px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
}
.navitem:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.18);
}
.navitem--active{
  background: rgba(1,118,211,.12);
  border-color: rgba(1,118,211,.25);
  font-weight: 600;
}
.navitem--disabled{
  color: rgba(11, 31, 51, .35);
  cursor: not-allowed;
  user-select: none;
}

.content{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pagehead{
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 10px 2px 16px;
}
.h1{
  font-size: 28px;
  margin: 0;
  letter-spacing: -0.02em;
}
.h1--with-back{
  display: flex;
  align-items: center;
  gap: 10px;
}
.h1__back{
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.75);
  text-decoration: none;
  color: var(--text);
  line-height: 1;
}
.h1__back:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.25);
}
.h1__back:focus{
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(1,118,211,.12);
}
.muted{ color: var(--muted); margin: 6px 0 0; }

.btn{
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.75);
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn--primary{
  border-color: rgba(1,118,211,.30);
  background: linear-gradient(180deg, rgba(1,118,211,.95), rgba(11,92,171,.95));
  color: white;
  box-shadow: 0 10px 18px rgba(1,118,211,.20);
}
.btn:disabled{
  opacity: .55;
  cursor: not-allowed;
}

.grid{
  display:grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

/* Home dashboard: Cantieri 40% / Checkins 60% (desktop only) */
.grid--home{
  grid-template-columns: 2fr 3fr;
}

.grid--home > .card{
  grid-column: auto;
}
.card{
  grid-column: span 6;
  background: rgba(255,255,255,.78);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}
.card--muted{
  background: rgba(255,255,255,.65);
}
.card__head{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card__title{
  font-weight: 700;
}
.card__body{
  padding: 16px;
}

.tabs{
  display:flex;
  align-items:center;
  gap: 10px;
  flex-wrap: wrap;
}
.tab{
  display:inline-flex;
  align-items:center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.72);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}
.tab:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.25);
}
.tab--active{
  background: rgba(1,118,211,.12);
  border-color: rgba(1,118,211,.35);
}
.tab--disabled{
  opacity: .55;
  cursor: not-allowed;
  user-select: none;
}
.tabpanel{
  display:none;
}
.tabpanel--active{
  display:block;
}
.file-list{
  display:flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.file-item{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.72);
}
.file-item__name{
  font-weight: 700;
  word-break: break-word;
}
.file-item__actions{
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* "Finder-like" attachments grid */
.allegati-grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin-top: 10px;
}
.allegato-tile{
  position: relative;
  display: grid;
  grid-template-rows: 84px auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 1px 0 rgba(10, 30, 60, .04);
  text-decoration: none;
  color: inherit;
  outline: none;
}
.allegato-tile:hover{
  border-color: rgba(1,118,211,.35);
  background: rgba(255,255,255,.85);
}
.allegato-tile:focus-visible{
  box-shadow: 0 0 0 3px rgba(1,118,211,.18);
}
.allegato-icon{
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(1,118,211,.08);
  border: 1px solid rgba(1,118,211,.18);
}
.allegato-icon svg{
  width: 42px;
  height: 42px;
}
.allegato-icon--pdf{
  background: rgba(186,5,23,.08);
  border-color: rgba(186,5,23,.18);
}
.allegato-icon--image{
  background: rgba(46,132,74,.08);
  border-color: rgba(46,132,74,.18);
}
.allegato-icon--doc{
  background: rgba(1,118,211,.10);
  border-color: rgba(1,118,211,.22);
}
.allegato-name{
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  word-break: break-word;
  line-clamp: 2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
}
.allegato-actions{
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}
.allegato-actions .btn{
  padding: 6px 10px;
}

/* "..." menu */
.allegato-menu{
  position: relative;
}
.allegato-menu__panel{
  position: absolute;
  top: 34px;
  right: 0;
  min-width: 160px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.95);
  box-shadow: var(--shadow);
  z-index: 10;
}
.allegato-menu__panel form{
  margin: 0;
}
.allegato-menu__item{
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.allegato-menu__item:hover{
  background: rgba(1,118,211,.08);
}
.allegato-menu__item--danger{
  color: var(--bad);
}
.allegato-menu__item--danger:hover{
  background: rgba(186,5,23,.08);
}

/* Preview modal (images/PDF) */
.preview-modal{
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
}
.preview-modal[aria-hidden="false"]{
  display: block;
}
.preview-modal__backdrop{
  position: absolute;
  inset: 0;
  background: rgba(10, 30, 60, .55);
  backdrop-filter: blur(4px);
}
.preview-modal__dialog{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(980px, calc(100vw - 28px));
  height: min(720px, calc(100vh - 28px));
  background: rgba(255,255,255,.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}
.preview-modal__head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.75);
}
.preview-modal__title{
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 4px;
}
.preview-modal__body{
  position: relative;
  padding: 0;
  background: rgba(255,255,255,.85);
}
.preview-modal__body img{
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  background: rgba(255,255,255,.85);
}
.preview-modal__body iframe{
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: rgba(255,255,255,.85);
}

.badge{
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.7);
}
.badge--ok{
  color: var(--ok);
  border-color: rgba(46,132,74,.35);
  background: rgba(46,132,74,.08);
}
.badge--bad{
  color: var(--bad);
  border-color: rgba(186,5,23,.35);
  background: rgba(186,5,23,.08);
}

.kv{
  display:grid;
  grid-template-columns: 100px 1fr;
  gap: 12px;
  padding: 10px 0;
}
.kv + .kv{
  border-top: 1px dashed rgba(10, 30, 60, .14);
}
.kv__k{
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
}
.kv__v{
  font-weight: 600;
}
.kv__v--mono{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-weight: 500;
  color: rgba(11, 31, 51, .82);
  word-break: break-word;
}

.list{
  margin: 0;
  padding-left: 18px;
  color: rgba(11,31,51,.78);
}
.list li{ margin: 8px 0; }

.footer{
  margin-top: 18px;
  padding: 14px 2px 6px;
  color: rgba(11,31,51,.45);
  font-size: 12px;
  text-align: center;
  margin-top: auto;
}

/* Login page styles */
.login-container{
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 64px);
  padding: 40px 18px;
  width: 100%;
}

.login-card{
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.client-portal .login-card{
  max-width: 520px;
}

.client-portal .login-title{
  font-size: 28px;
}

.client-portal .form-label{
  font-size: 14px;
}

.client-portal .form-input{
  padding: 16px 18px;
  font-size: 18px;
  border-radius: 14px;
}

.client-portal .btn{
  padding: 6px 18px;
  font-size: 18px;
  border-radius: 14px;
  touch-action: manipulation;
}

.client-portal .login-form{
  gap: 22px;
}

.client-portal .client-home{
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Operator portal layout: narrow, centered, touch-friendly */
.client-portal .shell{
  justify-content: center;
}

.client-portal .content{
  width: 100%;
  max-width: 600px;
}

.client-portal .portal-switch__link{
  padding: 10px 14px;
  font-size: 16px;
  border-radius: 12px;
  touch-action: manipulation;
}

/* Default: keep portal switch looking the same (text-only) */
.portal-switch__icon{
  display: none;
  width: 18px;
  height: 18px;
}

/* Operator portal on phones: hide brand title and show only icons in portal switch */
@media (max-width: 520px){
  .client-portal .brand__text{
    display: none;
  }
  .client-portal .portal-switch__icon{
    display: inline-block;
  }
  .client-portal .portal-switch__link{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    min-width: 44px;
  }
  .client-portal .portal-switch__label{
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
}

.client-portal .user-actions a{
  padding: 10px 14px;
  font-size: 16px;
  border-radius: 12px;
  touch-action: manipulation;
}

.touch-list{
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.touch-item{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.82);
  box-shadow: var(--shadow);
  min-height: 64px;
}

.touch-item--link{
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.touch-item--link:active{
  transform: translateY(1px);
  background: rgba(255,255,255,.92);
  border-color: rgba(1,118,211,.30);
}

.touch-item__chev{
  font-size: 26px;
  font-weight: 800;
  color: rgba(11,31,51,.45);
  line-height: 1;
}

.touch-item__title{
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.touch-item__meta{
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

/* Operator home: planning row layout (day number + vertical divider + details) */
.plan-row__left{
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1 1 auto;
}

.plan-row__day{
  min-width: 44px;
  text-align: center;
  font-size: 34px;
  font-weight: 900;
  color: #000;
  line-height: 1;
  letter-spacing: -0.02em;
}

.plan-row__divider{
  width: 1px;
  align-self: stretch;
  background: #000;
}

.plan-row__detail{
  min-width: 0;
}

.plan-row__titleline{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.plan-row__titleline .badge{
  flex: 0 0 auto;
  white-space: nowrap;
}

.plan-row--today{
  background: rgba(0,0,0,.03);
}

.plan-row--weekend{
  background: rgba(0,0,0,.03);
}

.client-portal .op-picker{
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.client-portal .op-picker__hint{
  margin-bottom: 10px;
}

.client-portal .op-picker__actions{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.client-portal .op-picker__action{
  width: 100%;
}

.client-portal .op-picker__list{
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.client-portal .op-picker__item{
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.82);
  min-height: 64px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.client-portal .op-picker__item:active{
  transform: translateY(1px);
  background: rgba(255,255,255,.92);
  border-color: rgba(1,118,211,.30);
}

.client-portal .op-picker__item--selected{
  background: rgba(1,118,211,.10);
  border-color: rgba(1,118,211,.42);
}

.client-portal .op-picker__checkbox{
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  accent-color: var(--brand);
  transform: scale(1.1);
}

.client-portal .op-picker__text{
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.dark-mode .client-portal .op-picker__item{
  background: rgba(30, 41, 59, .70);
  border-color: rgba(255, 255, 255, .10);
}

.dark-mode .client-portal .op-picker__item--selected{
  background: rgba(59, 130, 246, .14);
  border-color: rgba(59, 130, 246, .30);
}

.client-portal .client-actions{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.client-portal .client-action{
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.78);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  min-height: 120px;
}

.client-portal .client-action__title{
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.client-portal .client-action__desc{
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.client-portal .client-action:focus-visible{
  outline: none;
  box-shadow: 0 0 0 3px rgba(1,118,211,.18), var(--shadow);
}

.client-portal .client-action:hover{
  border-color: rgba(1,118,211,.35);
  background: rgba(255,255,255,.90);
}

.login-card__header{
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

.login-card__body{
  padding: 32px;
}

.login-title{
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 24px;
  text-align: center;
  letter-spacing: -0.01em;
}

.login-form{
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group{
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-label{
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.form-input{
  appearance: none;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.95);
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus{
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(1,118,211,.12);
}

.btn--block{
  width: 100%;
  margin-top: 4px;
}

.alert{
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 20px;
}

.alert--error{
  background: rgba(186,5,23,.08);
  border: 1px solid rgba(186,5,23,.25);
  color: var(--bad);
}

.user-menu{
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info{
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 13px;
}

.user-name{
  font-weight: 600;
  color: var(--text);
}

.user-actions{
  display: flex;
  gap: 8px;
}

.portal-switch{
  display: flex;
  gap: 8px;
  margin-right: 10px;
}

.portal-switch__link{
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.7);
  transition: all 0.2s;
  font-weight: 800;
}

.portal-switch__link:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.25);
}

.portal-switch__link--active{
  background: rgba(1,118,211,.12);
  border-color: rgba(1,118,211,.35);
}

.user-actions a{
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.7);
  transition: all 0.2s;
}

.user-actions a:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.25);
}

/* Table styles */
.table-container{
  overflow-x: auto;
  margin: -16px;
  padding: 16px;
}

.table{
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table thead{
  background: rgba(1,118,211,.06);
  border-bottom: 2px solid var(--border);
}

.table th{
  padding: 12px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.table td{
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.table th.table-col-actions,
.table td.table-col-actions{
  white-space: nowrap;
}

/* Keep "Azioni" column always visible on horizontal scroll */
.table th.table-col-actions{
  position: sticky;
  right: 0;
  z-index: 3;
  background: inherit; /* inherit thead background */
  border-left: 1px solid var(--border);
}

.table td.table-col-actions{
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--panel);
  border-left: 1px solid var(--border);
}

.table tbody tr:hover td.table-col-actions{
  background: rgba(1,118,211,.04);
}

.table tbody tr:hover{
  background: rgba(1,118,211,.04);
}

.table tbody tr.js-checkin-row{
  cursor: pointer;
}

.table tbody tr.js-checkin-row:focus{
  outline: none;
}

.table tbody tr.js-checkin-row:focus-visible{
  box-shadow: inset 0 0 0 2px rgba(1,118,211,.35);
}

.resolve-modal .preview-modal__dialog{
  width: min(720px, calc(100vw - 28px));
  height: auto;
  max-height: min(640px, calc(100vh - 28px));
  grid-template-rows: auto 1fr;
}

.resolve-modal__body{
  padding: 16px;
  overflow: auto;
  height: 100%;
}

.resolve-ops__list{
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.resolve-ops__item{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.70);
  font-weight: 700;
}

.table tbody tr.checkin-missing-checkout{
  background: rgba(186,5,23,.06);
}

.table tbody tr.checkin-missing-checkout td:first-child{
  box-shadow: inset 3px 0 0 rgba(186,5,23,.35);
}

.table tbody tr.checkin-missing-checkout:hover{
  background: rgba(186,5,23,.10);
}

.table-actions{
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn--small{
  padding: 6px 12px;
  font-size: 13px;
}
.btn--icon{
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon{
  width: 16px;
  height: 16px;
  display: block;
}

.btn--secondary{
  background: rgba(255,255,255,.9);
  border-color: var(--border);
  color: var(--text);
}

.btn--danger{
  background: rgba(186,5,23,.1);
  border-color: rgba(186,5,23,.3);
  color: var(--bad);
}

.btn--danger:hover{
  background: rgba(186,5,23,.15);
  border-color: rgba(186,5,23,.4);
}

.btn--success{
  border-color: rgba(46,132,74,.35);
  background: linear-gradient(180deg, rgba(46,132,74,.95), rgba(20,120,70,.95));
  color: white;
  box-shadow: 0 10px 18px rgba(46,132,74,.20);
}

.empty-state{
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state a{
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

.empty-state a:hover{
  text-decoration: underline;
}

/* Form styles */
.form{
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.form-grid{
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

/* Cantieri - Dettagli layout (Identificazione + Mappa) */
.cantiere-dettagli-grid{
  display: grid;
  grid-template-columns: 1.25fr .95fr;
  gap: 16px;
  align-items: start;
}
.map-embed-wrap{
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255,255,255,.72);
}
.map-embed{
  width: 100%;
  height: 320px;
  border: 0;
  display: block;
}

.form-actions{
  display: flex;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.alert--success{
  background: rgba(46,132,74,.08);
  border: 1px solid rgba(46,132,74,.25);
  color: var(--ok);
}

/* Dark mode styles */
.dark-mode {
  --bg: #0f172a;
  --panel: #1e293b;
  --border: rgba(255, 255, 255, .10);
  --text: #f1f5f9;
  --muted: rgba(241, 245, 249, .62);
  --brand: #3b82f6;
  --brand2: #2563eb;
  --ok: #10b981;
  --bad: #ef4444;
  --shadow: 0 8px 24px rgba(0, 0, 0, .3);
}

.dark-mode body::before {
  background: 
    radial-gradient(1400px 700px at 50% 50%, rgba(59, 130, 246, .15), transparent 52%),
    radial-gradient(1000px 600px at 50% 50%, rgba(16, 185, 129, .10), transparent 55%);
}

.dark-mode body::after {
  background: 
    radial-gradient(900px 500px at 50% 50%, rgba(59, 130, 246, .08), transparent 60%),
    radial-gradient(1200px 650px at 50% 50%, rgba(16, 185, 129, .06), transparent 52%);
}

.dark-mode .topbar {
  background: linear-gradient(180deg, rgba(30, 41, 59, .92), rgba(30, 41, 59, .78));
  border-bottom-color: rgba(255, 255, 255, .10);
}

.dark-mode .sidebar__section {
  background: rgba(30, 41, 59, .72);
  border-color: rgba(255, 255, 255, .10);
}

.dark-mode .sidebar__now{
  background: rgba(30, 41, 59, .62);
  border-color: rgba(255, 255, 255, .10);
}
.dark-mode .sidebar__now-icon{
  background: rgba(59, 130, 246, .14);
  border-color: rgba(59, 130, 246, .30);
  color: var(--brand);
}

.dark-mode .footer{
  color: rgba(241, 245, 249, .55);
}

.dark-mode .navitem--disabled{
  color: rgba(241, 245, 249, .45);
}

.dark-mode .navitem--disabled:hover{
  background: transparent;
  border-color: transparent;
}

.dark-mode .card {
  background: rgba(30, 41, 59, .78);
  border-color: rgba(255, 255, 255, .10);
}

.dark-mode .card--muted {
  background: rgba(30, 41, 59, .65);
}

.dark-mode .btn {
  background: rgba(30, 41, 59, .75);
  border-color: rgba(255, 255, 255, .10);
  color: var(--text);
}

.dark-mode .btn--primary {
  border-color: rgba(59, 130, 246, .30);
  background: linear-gradient(180deg, rgba(59, 130, 246, .95), rgba(37, 99, 235, .95));
  color: white;
  box-shadow: 0 10px 18px rgba(59, 130, 246, .20);
}

.dark-mode .form-input {
  background: rgba(30, 41, 59, .95);
  border-color: rgba(255, 255, 255, .10);
  color: var(--text);
}

.dark-mode .form-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}

.dark-mode .login-card {
  background: rgba(30, 41, 59, .85);
  border-color: rgba(255, 255, 255, .10);
}

.dark-mode .autocomplete-dropdown {
  background: var(--panel);
  border-color: var(--border);
}

.dark-mode .autocomplete-item:hover,
.dark-mode .autocomplete-item.active {
  background-color: rgba(59, 130, 246, .15);
}

.dark-mode .autocomplete-item-main {
  color: var(--text);
}

.dark-mode .autocomplete-item-secondary {
  color: var(--muted);
}

.dark-mode .table thead {
  background: rgba(59, 130, 246, .08);
  border-bottom-color: var(--border);
}

.dark-mode .table tbody tr:hover {
  background: rgba(59, 130, 246, .06);
}

.dark-mode .table tbody tr:hover td.table-col-actions{
  background: rgba(59, 130, 246, .06);
}

.dark-mode .kv + .kv {
  border-top-color: rgba(255, 255, 255, .14);
}

.dark-mode .kv__v--mono {
  color: rgba(241, 245, 249, .82);
}

/* Settings page styles */
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-item__content {
  flex: 1;
}

.settings-item__label {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}

.settings-item__description {
  font-size: 13px;
  color: var(--muted);
}

.settings-item__action {
  margin-left: 16px;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.toggle__input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle__slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, .2);
  transition: .3s;
  border-radius: 26px;
  border: 1px solid var(--border);
}

.toggle__slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
}

.toggle__input:checked + .toggle__slider {
  background-color: var(--brand);
  border-color: var(--brand);
}

.toggle__input:checked + .toggle__slider:before {
  transform: translateX(22px);
}

.toggle__input:focus + .toggle__slider {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}

.dark-mode .toggle__slider {
  background-color: rgba(255, 255, 255, .15);
  border-color: rgba(255, 255, 255, .20);
}

.dark-mode .toggle__input:checked + .toggle__slider {
  background-color: var(--brand);
  border-color: var(--brand);
}

@media (max-width: 980px){
  .shell{ flex-direction: column; }
  .sidebar{ width: 100%; flex: 0 0 auto; }
  .card{ grid-column: span 12; }
  .user-info{ display: none; }
  .form-grid{ grid-template-columns: 1fr; }
  .cantiere-dettagli-grid{ grid-template-columns: 1fr; }
  .table-container{ overflow-x: scroll; }
  .recent-chips{ display: none; }
}

@media (max-width: 720px){
  .client-portal .client-actions{
    grid-template-columns: 1fr;
  }
}

/* Planning page */
.planning-layout{
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  align-items: start;
}

.planning-main.card .card__body{
  padding: 0;
}

.planning-gridwrap{
  overflow: auto;
  max-height: calc(100vh - 230px);
  border-top: 1px solid var(--border);
}

.planning-grid{
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 980px;
}

.planning-grid th,
.planning-grid td{
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0;
  vertical-align: middle;
}

.planning-grid thead th{
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(10px);
}

.planning-sticky-col{
  position: sticky;
  left: 0;
  z-index: 2;
  background: rgba(255,255,255,.92);
  min-width: 210px;
  padding: 10px 12px !important;
}

.planning-sticky-head{
  z-index: 4;
}

.planning-day-head{
  text-align: center;
  min-width: 44px;
  width: 44px;
  padding: 6px 4px !important;
  font-variant-numeric: tabular-nums;
}

.planning-day-head .planning-day-num{
  font-weight: 800;
  line-height: 1.05;
}
.planning-day-head .planning-day-dow{
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 2px;
}

.planning-day-head.is-weekend{
  background: rgba(242, 201, 76, .18);
}
.planning-day-head.is-holiday{
  background: rgba(235, 87, 87, .14);
}

.planning-day-head.is-today{
  box-shadow: inset 0 -2px 0 rgba(1,118,211,.85);
}

.planning-cell.is-weekend{
  background: rgba(242, 201, 76, .08);
}
.planning-cell.is-holiday{
  background: rgba(235, 87, 87, .06);
}

.planning-cell.is-today{
  background: rgba(1,118,211,.06);
}

.planning-cell.is-today .planning-cell-btn{
  border-color: rgba(1,118,211,.25);
}

.planning-op__name{
  font-weight: 800;
  line-height: 1.15;
}
.planning-op__meta{
  font-size: 12px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.planning-cell-btn{
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .2s ease, border-color .2s ease, background .2s ease;
  color: var(--text);
}

.planning-cell-btn:hover{
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(10,30,60,.10);
  border-color: rgba(1,118,211,.28);
}

.planning-cell-btn[data-has-color="1"]{
  background: var(--cell-color);
  border-color: rgba(255,255,255,.35);
  color: white;
  box-shadow: 0 10px 18px rgba(10,30,60,.14);
}

.planning-cell-text{
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  line-height: 1.1;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40px;
}

.planning-cell-btn--busy{
  opacity: .6;
  pointer-events: none;
}

.planning-side-actions{
  display:flex;
  gap:10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.planning-cantieri{
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.planning-cantiere{
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.70);
  cursor: pointer;
  transition: all .2s;
}

.planning-cantiere:hover{
  background: rgba(1,118,211,.08);
  border-color: rgba(1,118,211,.25);
}

.planning-cantiere--selected{
  border-color: rgba(1,118,211,.55);
  box-shadow: 0 10px 18px rgba(1,118,211,.12);
}

.planning-cantiere-swatch{
  width: 14px;
  height: 14px;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.planning-cantiere-name{
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1100px){
  .planning-layout{ grid-template-columns: 1fr; }
  .planning-grid{ min-width: 860px; }
  .planning-gridwrap{ max-height: none; }
}

.dark-mode .planning-grid thead th{
  background: rgba(30, 41, 59, .92);
}
.dark-mode .planning-sticky-col{
  background: rgba(30, 41, 59, .92);
}
.dark-mode .planning-cantiere{
  background: rgba(30, 41, 59, .78);
  border-color: rgba(255,255,255,.10);
}
.dark-mode .planning-cantiere:hover{
  background: rgba(59, 130, 246, .10);
  border-color: rgba(59, 130, 246, .25);
}
