/* Compact controls and calendar. Keep the existing workspace colors and navigation. */
body[data-area] #page .heading { gap: 12px; margin-bottom: 14px; }
body[data-area] #page .heading h1 { font-size: clamp(1.55rem, 2.6vw, 2.15rem); line-height: 1.12; }
body[data-area] #page .panel:not(.pm-h3-card) { box-shadow: 0 2px 8px #1e293b22; }
body[data-area] #page .panelhead { padding-block: 9px; }
body[data-area] #page .panelbody { padding-block: 12px; }
body[data-area] #page .toolbar { gap: 8px; }
#page button:focus-visible, #page a:focus-visible, #page input:focus-visible, #page select:focus-visible,
#page summary:focus-visible { outline: 2px solid #a51935; outline-offset: 2px; }
#page .pm-h3-kpi { min-height: 76px; }
#page .pm-h3-kpi:is(:hover,:focus-visible), #page .pm-h3-site:is(:hover,:focus-visible) {
  border-color: #a85869;
}
#page .pm-calendar-filters {
  display: flex; flex-wrap: wrap; align-items: end; gap: 8px 14px; margin-bottom: 10px;
}
#page .pm-calendar-filters label { display: grid; gap: 4px; font-size: .8rem; }
#page .pm-calendar-filters input, #page .pm-calendar-filters select {
  min-height: 38px; margin: 0; padding: 6px 9px; max-width: 100%;
}
#page .pm-calendar-filters small { color: inherit; padding-bottom: 8px; }
#page .calendarlegend { gap: 6px 14px; margin-block: 8px 12px; }
#page .pm-calendar-navigation {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0 0 8px;
}
#page .pm-calendar-navigation h2 { flex: 1 1 auto; margin: 0 8px; font-size: 1.03rem; }
#page .pm-calendar-navigation button { min-height: 36px; padding: 4px 9px; }
#page .pm-calendar-jump { display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; }
#page .pm-calendar-jump input { width: auto; min-height: 36px; margin: 0; padding: 4px 6px; }
#page .pm-calendar-modes {
  display: inline-flex; flex-wrap: wrap; gap: 2px; border: 1px solid #7f8e9e;
  padding: 2px; border-radius: 9px; background: #3c4855;
}
#page .pm-calendar-modes button { background: transparent; border-color: transparent; color: #f4f6f9; }
#page .pm-calendar-modes button[aria-pressed="true"] { background: #f2f5f8; color: #252e39; }
#page .pm-calendar-grid {
  display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: 1px; overflow: clip;
  border: 1px solid #8997a5; border-radius: 10px; background: #8997a5;
}
#page .pm-calendar-grid .calendar-day {
  min-height: 66px; min-width: 0; margin: 0; padding: 6px; border: 0;
  border-radius: 0; background: #e1e7ed; color: #273542;
}
#page .pm-calendar-grid .calendar-day.is-today {
  background: #f6e3e7; outline: none; box-shadow: inset 0 3px #a51935;
}
#page .pm-calendar-grid .calendar-day-number { display: block; margin-bottom: 4px; font-size: .75rem; }
#page .pm-calendar-grid .calendar-today-label { font-size: .64rem; padding: 1px 4px; }
#page :is(.pm-calendar-grid,.pm-week-calendar) .google-event {
  margin: 3px 0; padding: 4px 6px; border-width: 0 0 0 3px; border-radius: 5px;
  box-shadow: none; line-height: 1.25;
}
#page .pm-calendar-grid .google-event[hidden] { display: none !important; }
#page .pm-calendar-grid .calendar-source { font-size: .64rem; }
#page .pm-calendar-grid .google-event-title {
  display: block; width: 100%; min-height: 28px; margin: 0; padding: 2px 0;
  font-size: .78rem; line-height: 1.2; text-align: left; overflow-wrap: anywhere;
}
#page .pm-calendar-grid .google-event-title:hover { text-decoration: underline; }
#page .pm-calendar-grid .google-event p { margin: 1px 0; font-size: .72rem; }
#page .pm-calendar-grid :is(.google-event > a,.google-event p + p) { display: none; }
#page .pm-calendar-grid .google-new-event {
  float: right; min-height: 24px; margin: 0 0 2px 3px; padding: 1px 5px; font-size: .72rem;
}
#page .pm-calendar-list, #page .pm-calendar-day { grid-template-columns: minmax(0,1fr); }
#page .pm-calendar-list .calendar-day { min-height: 0; }
#page .pm-calendar-list .empty-day:not(.is-today) { display: none; }
#page .pm-calendar-list .calendar-day, #page .pm-calendar-day .calendar-day {
  display: grid; grid-template-columns: minmax(75px,126px) minmax(0,1fr) auto;
  gap: 6px; align-items: start;
}
/* The legacy mobile transport rule hides empty days. Keep real date slots
   in the planning grids, including historical days with no appointment. */
#page :is(.pm-calendar-week,.pm-calendar-month) .calendar-day { display: block; }
#page :is(.pm-calendar-list,.pm-calendar-day) .calendar-day-number { grid-column: 1; grid-row: 1; }
#page :is(.pm-calendar-list,.pm-calendar-day) [data-google-slot] { grid-column: 2; grid-row: 1; }
#page :is(.pm-calendar-list,.pm-calendar-day) .google-new-event { grid-column: 3; grid-row: 1; }
#page .pm-calendar-month .google-event :is(.calendar-source,p) { display: none; }
#page .pm-calendar-month .google-event-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#page .pm-internal-schedule {
  margin-top: 10px; padding: 9px 12px; border: 1px solid #8997a5; border-radius: 8px;
}
#page .pm-internal-schedule summary { cursor: pointer; font-weight: 650; }
@media (max-width: 820px) {
  #page .pm-calendar-navigation h2 { order: -1; flex-basis: 100%; margin: 0 0 3px; }
  #page .pm-calendar-modes { margin-inline-start: auto; }
  #page .pm-calendar-week { grid-template-columns: minmax(0,1fr); }
  #page .pm-calendar-week .calendar-day { min-height: 40px; }
  #page .pm-calendar-month .calendar-day { padding: 3px; min-height: 43px; }
  #page .pm-calendar-month .calendar-day-number { font-size: .62rem; }
  #page .pm-calendar-month .calendar-today-label { display: none; }
  #page .pm-calendar-month .google-new-event { float: none; }
  #page .pm-calendar-grid .google-new-event { min-height: 31px; }
  #page .pm-calendar-month .google-event-title { min-height: 28px; font-size: .68rem; }
}

/* Touch targets and clearer card hierarchy without changing the approved palette. */
#page .pm-calendar-filters :is(input,select) { min-inline-size: 0; }
#page .pm-calendar-navigation button { min-inline-size: 40px; }
#page .pm-calendar-navigation button:focus-visible { outline-color: #d74962; }
#page .pm-calendar-grid .google-event-title:focus-visible { outline-offset: -2px; }
#page .pm-internal-schedule summary { min-height: 32px; padding-block: 5px; }
#page .pm-h3-card-head { gap: 8px; }
@media (max-width: 600px) {
  #page .pm-calendar-filters { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; }
  #page .pm-calendar-filters label { min-width: 0; }
  #page .pm-calendar-filters :is(input,select) { width: 100%; min-height: 44px; font-size: 1rem; }
  #page .pm-calendar-filters small { grid-column: 1 / -1; padding: 0; }
  #page .pm-calendar-filters small:empty { display: none; }
  #page .pm-calendar-navigation button { min-height: 44px; }
  #page .pm-calendar-jump input { min-height: 44px; font-size: 1rem; }
  #page .pm-calendar-modes { margin-inline-start: 0; }
  #page .pm-calendar-navigation h2 { font-size: 1.13rem; }
  #page .pm-calendar-grid:not(.pm-calendar-month) .google-event-title { min-height: 40px; font-size: .9rem; }
  #page .pm-calendar-grid:not(.pm-calendar-month) .google-new-event { min-width: 40px; min-height: 40px; }
  #page .pm-calendar-list .calendar-day, #page .pm-calendar-day .calendar-day { grid-template-columns: minmax(55px, .38fr) minmax(0,1fr) auto; }
}

/* Source colors are applied to the title itself; labels remain for identification without color. */
#page .google-event.calendar-work .google-event-title { color: #8e2031; }
#page .google-event.calendar-transport .google-event-title { color: #784308; }
#page .google-event.calendar-agenda .google-event-title { color: #1b5b3d; }
#page .google-event.calendar-appointments .google-event-title { color: #204e82; }
#page .google-event.calendar-deadlines .google-event-title { color: #653879; }
#page .pm-calendar-list [data-google-slot] { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,205px),1fr)); gap: 5px; }
#page .pm-calendar-list .google-event { margin: 0; padding: 5px 7px; }
#page .pm-calendar-list .google-event p + p { display: block; }
body[data-area="amministrazione"] #page .pm-office-tasks .workspace-cards { gap: 8px; }
body[data-area="amministrazione"] #page .pm-office-tasks .workspace-cards a { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) {
  #page .pm-calendar-list [data-google-slot] { grid-template-columns: minmax(0,1fr); }
  #page .pm-calendar-list .calendar-day-number { overflow-wrap: anywhere; }
}


/* Month is an overview; tapping the whole cell opens the selected day. */
#page .pm-calendar-weekdays {
  display: grid; grid-template-columns: repeat(7,minmax(0,1fr));
  gap: 1px; margin-bottom: 4px; text-align: center;
  font-size: .72rem; line-height: 1.5; font-weight: 700; color: #e8eef3;
}
#page .pm-calendar-month .pm-month-date {
  display: inline-grid; place-items: center; width: 28px; min-width: 0; min-height: 28px;
  margin: 0; padding: 0; border: 0; border-radius: 16px;
  background: none; color: #273542; font-weight: 750; font-size: .99rem; line-height: 1;
}
#page .pm-calendar-month .pm-month-date:is(:hover,:focus-visible) { background: #cbd5df; }
#page .pm-calendar-month .pm-month-date:focus-visible { outline-offset: -2px; }
#page .pm-calendar-month .pm-month-outside { background: #ced8e0; }
#page .pm-calendar-month .pm-month-outside .pm-month-date { color: #465769; }
#page .pm-calendar-month .is-today .pm-month-date { background: #9a2339; color: white; }
#page .pm-month-dots { display: none; }

/* Instance-level calendar magnification; never scale the toolbar, month or page. */
#page .pm-calendar-zoom {
  display: inline-flex; align-items: center; gap: 2px; min-width: 0;
  padding: 2px; border: 1px solid #7f8e9e; border-radius: 9px; background: #3c4855;
}
#page .pm-calendar-zoom output { min-width: 45px; text-align: center; font-size: .75rem; color: #f4f6f9; }
#page .pm-calendar-zoom button { min-width: 36px; padding-inline: 6px; }
#page .pm-calendar-zoom button:disabled { opacity: .53; }
#page .pm-calendar-grid[data-calendar-zoom-level] {
  --calendar-row-height: 66px;
  --calendar-cell-padding: 6px;
  --calendar-date-size: .94rem;
  --calendar-event-size: .78rem;
  --calendar-detail-size: .72rem;
  touch-action: pan-x pan-y;
}
#page .pm-calendar-grid[data-calendar-zoom-level="1"] {
  --calendar-row-height: 84px; --calendar-cell-padding: 8px;
  --calendar-date-size: 1.10rem; --calendar-event-size: .98rem; --calendar-detail-size: .90rem;
}
#page .pm-calendar-grid[data-calendar-zoom-level="2"] {
  --calendar-row-height: 99px; --calendar-cell-padding: 9px;
  --calendar-date-size: 1.25rem; --calendar-event-size: 1.17rem; --calendar-detail-size: 1.08rem;
}
#page .pm-calendar-grid[data-calendar-zoom-level] .calendar-day {
  min-height: var(--calendar-row-height); padding: var(--calendar-cell-padding);
}
#page .pm-calendar-grid[data-calendar-zoom-level] .calendar-day-number { font-size: var(--calendar-date-size); }
#page .pm-calendar-grid[data-calendar-zoom-level] .google-event-title { font-size: var(--calendar-event-size); }
#page .pm-calendar-grid[data-calendar-zoom-level] .google-event :is(p,.calendar-source) { font-size: var(--calendar-detail-size); }
@media (max-width: 820px) {
  #page .pm-calendar-grid.pm-calendar-month { grid-template-columns: repeat(7,minmax(0,1fr)); }
  #page .pm-calendar-grid.pm-calendar-month .calendar-day { position: relative; min-height: 47px; padding: 0; }
  #page .pm-calendar-month .pm-month-date {
    position: absolute; inset: 0; width: 100%; height: 100%;
    min-height: 0; padding: 4px 0 0; align-items: start; border-radius: 0;
    font-size: 1rem;
  }
  #page .pm-calendar-month .pm-month-date span {
    display: grid; place-items: center; inline-size: 27px; block-size: 27px; border-radius: 50%;
  }
  #page .pm-calendar-month .is-today .pm-month-date { background: #f6e3e7; color: #273542; }
  #page .pm-calendar-month .is-today .pm-month-date span { background: #9a2339; color: white; }
  #page .pm-calendar-month .calendar-day :is([data-google-slot],.google-new-event) { display: none; }
  #page .pm-month-dots {
    position: absolute; inset-inline: 1px; inset-block-end: 6px;
    display: flex; justify-content: center; gap: 2px; pointer-events: none;
  }
  #page .pm-month-dots i { inline-size: 4px; block-size: 4px; border-radius: 50%; flex: 0 0 4px; }
  #page .pm-month-dots i[hidden] { display: none; }
  #page .pm-month-dots .calendar-work { background: #8e2031; }
  #page .pm-month-dots .calendar-transport { background: #875217; }
  #page .pm-month-dots .calendar-agenda { background: #1b5b3d; }
  #page .pm-month-dots .calendar-appointments { background: #204e82; }
  #page .pm-month-dots .calendar-deadlines { background: #653879; }
}
@media (max-width: 600px) {
  #page .pm-calendar-modes button { padding-inline: 7px; }
  #page .pm-calendar-zoom button { min-width: 44px; }
  #page .pm-calendar-grid[data-calendar-zoom-level="0"] {
    --calendar-row-height: 48px; --calendar-event-size: .9rem; --calendar-date-size: .94rem;
  }
  /* Do not put the day title in a squeezed sidebar when a detail view is enlarged. */
  #page .pm-calendar-day[data-calendar-zoom-level] .calendar-day {
    grid-template-columns: minmax(0,1fr) auto;
  }
  #page .pm-calendar-day[data-calendar-zoom-level] [data-google-slot] { grid-column: 1 / -1; grid-row: 2; }
  #page .pm-calendar-day[data-calendar-zoom-level] .google-new-event { grid-column: 2; }
}

/* The default monthly list omits unused dates; Mese is the overview of all dates. */
#page .pm-calendar-list .calendar-day-number { font-size: .86rem; font-weight: 750; }
@media (max-width: 600px) {
  #page .pm-calendar-list .calendar-day { gap: 5px; padding: 4px 6px; }
  #page .pm-calendar-list .calendar-day-number { line-height: 1.25; margin: 4px 0; }
  #page .pm-calendar-list .google-event { padding: 2px 6px; }
  #page .pm-calendar-list .google-event-title { min-height: 36px; }
}

/* Period controls stay visible. Lookup and the source key share a real, keyboard-accessible disclosure. */
#page .pm-calendar-period { display:flex; align-items:center; flex:1 1 auto; gap:4px; min-width:0; }
#page .pm-calendar-period h2 { flex:1; margin:0; text-align:start; }
#page :is(.pm-calendar-period,.pm-week-toolbar) h2 { color:#f4f6f9; }
#page .pm-calendar-tools { margin:0 0 9px; }
#page .pm-calendar-tools summary {
  display:list-item; cursor:pointer; min-height:44px; box-sizing:border-box;
  padding:10px 9px; border:1px solid #a4afb9; border-radius:8px;
  background:#e1e7ed; color:#273542; font-weight:700; line-height:1.35;
}
#page .pm-calendar-tools summary .pm-calendar-tool-hint { display:inline; margin:0; color:#46576a; font-weight:600; }
#page .pm-calendar-active { margin-inline-start:6px; font-size:.73rem; white-space:nowrap; color:#722138; }
#page .pm-calendar-tools[open] .pm-calendar-filters { margin-block:9px 0; }
#page .pm-calendar-tools .pm-calendar-filters .pm-calendar-jump input { margin:0; }
#page .pm-calendar-tools .calendarlegend { margin-bottom:6px; }
#page .pm-week-toolbar { flex-wrap:nowrap; gap:4px; margin-block:8px; }
#page .pm-week-toolbar h2 { order:0; width:auto; flex:1; min-width:0; text-align:start; }
#page .pm-week-toolbar button { flex:0 0 auto; min-width:44px; min-height:44px; padding:4px 8px; }
@media (min-width:1080px) {
  #page .pm-calendar-tools { position:relative; }
  #page .pm-calendar-tools[open] summary { position:absolute; right:0; top:15px; width:auto; min-height:38px; }
  #page .pm-calendar-tools[open] .pm-calendar-filters { padding-inline-end:300px; }
}
@media (max-width:820px) {
  body[data-area] #page .pm-calendar-heading { display:flex; flex-direction:row; align-items:center; justify-content:space-between; flex-wrap:nowrap; margin-bottom:8px; }
  #page .pm-calendar-heading button { min-height:44px; width:auto; }
  #page .pm-calendar-period { flex:1 0 100%; }
  #page .pm-calendar-period h2 { order:0; flex:1 1 auto; font-size:1rem; line-height:1.2; }
  #page .pm-calendar-period button { min-width:44px; min-height:44px; padding:4px 6px; flex:0 0 auto; }
  #page .pm-calendar-navigation { gap:4px; margin-bottom:6px; }
  #page .pm-calendar-navigation .pm-calendar-modes {
    display:grid; grid-template-columns:minmax(0,1.45fr) minmax(0,.72fr) minmax(0,1.10fr) minmax(0,.83fr);
    width:100%; margin:0; box-sizing:border-box;
  }
  #page .pm-calendar-navigation .pm-calendar-modes button { min-width:0; min-height:44px; padding-inline:3px; }
  #page .pm-calendar-navigation .pm-calendar-zoom { margin-inline-start:auto; }
  #page .pm-calendar-navigation .pm-calendar-zoom button { min-height:44px; }
  #page .pm-calendar-tools .pm-calendar-filters .pm-calendar-jump { grid-column:1/-1; }
}

/* Tiny phone widths: keep every authorized header action reachable without
   shrinking its hit area or changing wider phone/desktop layout. */
@media (max-width: 375px) {
 #app .shell>header {
  flex-wrap: wrap; justify-content: space-between; gap: 4px;
  padding-inline: 8px!important;
 }
 #app .shell>header>:is(#navback,.pm-notification-bell,#quickadd,#menutoggle):not([hidden]) {
  flex: none;
  min-inline-size: 44px; min-block-size: 44px; max-inline-size: 100%;
  margin: 0; padding: .3rem .36rem; font-size: .75rem; line-height: 1.16;
  white-space: nowrap;
 }
 #app .shell>header>:is(#navback,.pm-notification-bell,#quickadd,#menutoggle):focus-visible {
  outline: 2px solid #fff; outline-offset: 1px;
 }
}
