:root {
  color-scheme: light;
  --ink: #152033;
  --muted: #647184;
  --line: #dde4ed;
  --panel: #ffffff;
  --surface: #f5f7fa;
  --surface-strong: #ecf1f6;
  --teal: #178f84;
  --teal-soft: #dff5f2;
  --blue: #315fba;
  --blue-soft: #e3ecff;
  --amber: #b56b11;
  --amber-soft: #fff0d2;
  --coral: #c64236;
  --coral-soft: #ffe5e1;
  --green: #28754e;
  --green-soft: #e3f4e9;
  --shadow: 0 14px 34px rgba(21, 32, 51, .09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--surface);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 3vw, 32px);
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.history-actions {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  color: #ffffff;
  background: var(--ink);
  font-weight: 850;
  letter-spacing: 0;
}

.history-button:disabled {
  opacity: .38;
  cursor: not-allowed;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.masthead-image {
  display: block;
  width: min(620px, 100%);
  height: 42px;
  object-fit: contain;
  object-position: left center;
  flex: 0 1 auto;
}

.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;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(21px, 3vw, 28px);
  line-height: 1.05;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
}

h3 {
  margin: 9px 0 7px;
  font-size: 14px;
  line-height: 1.18;
}

.role-switch,
.tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.role-button,
.tab {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 720;
}

.role-button.is-active,
.tab.is-active {
  color: var(--ink);
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(21, 32, 51, .09);
}

main {
  padding: 20px clamp(12px, 3vw, 32px) 36px;
}

.control-band {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.week-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 800;
}

.week-jump-target.is-week-drop-target {
  border-color: var(--teal);
  color: #ffffff;
  background: var(--teal);
  box-shadow: 0 0 0 4px var(--teal-soft);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.filter-row {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
}

.search-field,
.select-field,
form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 740;
}

.search-field input,
.select-field select,
form input,
form select,
form textarea {
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: #ffffff;
}

form textarea {
  min-height: 96px;
  padding: 10px 11px;
  line-height: 1.35;
  resize: vertical;
}

.search-field {
  min-width: min(260px, 42vw);
}

.primary-button,
.secondary-button,
.mini-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 780;
}

.primary-button {
  color: #ffffff;
  background: var(--ink);
}

.secondary-button {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.mini-button {
  flex: 1 1 64px;
  min-height: 32px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.editor-open .workspace {
  grid-template-columns: minmax(0, 1fr) minmax(310px, 370px);
}

.calendar-panel,
.editor-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.calendar-panel {
  min-width: 0;
  overflow: hidden;
}

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.day-strip.is-hidden {
  display: none;
}

.day-chip {
  min-width: 0;
  min-height: 64px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 10px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
}

.day-chip:last-child {
  border-right: 0;
}

.day-chip.is-active {
  background: var(--teal-soft);
}

.day-chip strong {
  display: block;
  font-size: 14px;
}

.day-chip span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.content-view {
  min-height: 520px;
  overflow-x: auto;
}

.week-table {
  display: grid;
  min-width: 0;
  background: var(--line);
}

.week-header,
.week-row {
  display: grid;
  grid-template-columns: minmax(112px, .72fr) repeat(7, minmax(0, 1fr));
}

.week-row[data-slot="07:00"] {
  --slot-bg: #eefaf7;
  --slot-line: #178f84;
  --slot-ink: #0d5e58;
}

.week-row[data-slot="11:00"] {
  --slot-bg: #eef4ff;
  --slot-line: #315fba;
  --slot-ink: #244886;
}

.week-row[data-slot="13:00"] {
  --slot-bg: #fff6df;
  --slot-line: #b56b11;
  --slot-ink: #79460a;
}

.week-row[data-slot="16:00"] {
  --slot-bg: #ffece9;
  --slot-line: #c64236;
  --slot-ink: #8c2d25;
}

.week-row[data-slot="18:00"] {
  --slot-bg: #edf7ed;
  --slot-line: #28754e;
  --slot-ink: #1d5739;
}

.week-row[data-slot="appuntamento"] {
  --slot-bg: #f2eefb;
  --slot-line: #6b5fb8;
  --slot-ink: #473f82;
}

.week-row[data-slot="dirette"] {
  --slot-bg: #eef7ff;
  --slot-line: #147ca8;
  --slot-ink: #0d5574;
}

.week-row[data-slot="note"] {
  --slot-bg: #f6f1e8;
  --slot-line: #8b7355;
  --slot-ink: #5c4932;
}

.week-corner,
.week-day-head,
.slot-label,
.slot-cell {
  min-width: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.week-corner,
.week-day-head {
  min-height: 62px;
  padding: 11px 10px;
  background: #ffffff;
}

.week-corner {
  display: grid;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 840;
  text-transform: uppercase;
}

.week-day-head {
  border-top: 0;
  border-left: 0;
  color: var(--ink);
  text-align: left;
}

.week-day-head.is-active {
  background: var(--teal-soft);
}

.week-day-head strong,
.week-day-head span {
  display: block;
}

.week-day-head strong {
  font-size: 14px;
}

.week-day-head span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.slot-label {
  display: grid;
  align-content: start;
  gap: 4px;
  min-height: 150px;
  padding: 12px 10px;
  color: var(--slot-ink);
  background: var(--slot-bg);
  border-left: 5px solid var(--slot-line);
}

.slot-label span {
  font-size: 11px;
  font-weight: 860;
  text-transform: uppercase;
}

.slot-label strong {
  font-size: 15px;
  line-height: 1.05;
}

.slot-cell {
  min-height: 150px;
  padding: 10px;
  background: var(--slot-bg);
  transition: background .16s ease, outline-color .16s ease;
}

.slot-cell .item-card {
  border-left-color: var(--slot-line);
}

.slot-cell.is-drop-target {
  outline: 2px solid var(--slot-line);
  outline-offset: -5px;
  background: color-mix(in srgb, var(--slot-bg) 72%, #ffffff);
}

.slot-cell.is-drop-target .empty-slot {
  border-style: solid;
  background: rgba(255, 255, 255, .72);
}

.mobile-day-label {
  display: none;
  margin: 0 0 8px;
  color: var(--slot-ink);
  font-size: 12px;
  font-weight: 840;
}

.empty-slot {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 76px;
  border: 1px dashed color-mix(in srgb, var(--slot-line) 45%, #ffffff);
  border-radius: 8px;
  color: var(--slot-ink);
  background: rgba(255, 255, 255, .48);
  font-weight: 780;
}

.empty-slot.is-readonly {
  color: var(--muted);
  font-weight: 650;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.day-column {
  min-width: 0;
  min-height: 520px;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.day-column:nth-child(even) {
  background: #fafbfd;
}

.day-column:last-child {
  border-right: 0;
}

.column-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.slot-group + .slot-group {
  margin-top: 14px;
}

.slot-title {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  text-transform: uppercase;
}

.item-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #ffffff;
  transition: opacity .16s ease, transform .16s ease, box-shadow .16s ease;
}

.item-card + .item-card {
  margin-top: 8px;
}

.item-card.is-draggable {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.item-card.is-dragging {
  cursor: grabbing;
  opacity: .48;
  transform: scale(.985);
  box-shadow: none;
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  pointer-events: none;
  max-width: 220px;
  opacity: .92;
  box-shadow: 0 18px 42px rgba(21, 32, 51, .2);
}

.is-dragging-card .slot-cell {
  cursor: copy;
}

.card-topline,
.tag-row,
.card-actions,
.check-row,
.form-actions,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-topline,
.panel-heading {
  justify-content: space-between;
}

.card-topline,
.card-actions {
  flex-wrap: wrap;
}

.time-chip,
.status-pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  border-radius: 999px;
  padding: 0 7px;
  font-size: 10px;
  font-weight: 820;
}

.time-chip {
  color: var(--blue);
  background: var(--blue-soft);
}

.status-pill[data-status="idea"] {
  color: var(--amber);
  background: var(--amber-soft);
}

.status-pill[data-status="assegnato"] {
  color: var(--blue);
  background: var(--blue-soft);
}

.status-pill[data-status="pubblicato"] {
  color: var(--green);
  background: var(--green-soft);
}

.status-pill[data-status="annullato"] {
  color: var(--coral);
  background: var(--coral-soft);
}

.item-card[data-status="idea"] {
  border-left-color: var(--amber);
}

.item-card[data-status="assegnato"] {
  border-left-color: var(--blue);
}

.item-card[data-status="pubblicato"] {
  border-left-color: var(--green);
}

.item-card[data-status="annullato"] {
  border-left-color: var(--coral);
}

.day-column .item-card h3 {
  font-size: 13px;
}

.item-card h3 {
  white-space: normal;
}

.card-title-text,
.card-title-list {
  font-size: 13px;
  line-height: 1.18;
}

.card-title-text {
  margin: 0;
  white-space: pre-line;
}

.card-title-list {
  margin: 0;
  padding-left: 15px;
}

.card-title-list + .card-title-text,
.card-title-text + .card-title-list {
  margin-top: 3px;
}

.card-title-list li + li {
  margin-top: 2px;
}

.card-piece-author {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  border-radius: 999px;
  padding: 0 6px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 10px;
  font-weight: 830;
  white-space: nowrap;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.author-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 7px;
  color: #ffffff;
  background: var(--ink);
  font-size: 10px;
  font-weight: 850;
}

.tag-row {
  flex-wrap: wrap;
}

.tag {
  color: var(--teal);
  background: var(--teal-soft);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.list-view,
.group-view {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.group-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
}

.group-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-strong);
  border-bottom: 1px solid var(--line);
  font-weight: 820;
}

.group-items {
  padding: 12px;
}

.editor-panel {
  position: sticky;
  top: 92px;
  padding: 16px;
}

.editor-panel.is-hidden {
  display: none;
}

.panel-heading {
  margin-bottom: 14px;
}

form {
  display: grid;
  gap: 14px;
}

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

.check-row {
  flex-wrap: wrap;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.form-actions {
  justify-content: flex-end;
}

.band-form,
.author-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(110px, 140px) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.band-list {
  display: grid;
  gap: 8px;
}

.author-list {
  display: grid;
  gap: 8px;
}

.band-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--slot-bg);
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: opacity .16s ease, box-shadow .16s ease, transform .16s ease;
}

.band-marker {
  width: 8px;
  height: 42px;
  border-radius: 999px;
  background: var(--slot-line);
}

.band-row-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.band-row-text strong {
  color: var(--slot-ink);
  font-size: 13px;
  line-height: 1.15;
}

.band-row-text span {
  color: var(--muted);
  font-size: 12px;
}

.band-row.is-band-dragging {
  cursor: grabbing;
  opacity: .46;
  transform: scale(.99);
}

.band-row.is-band-drop-before {
  box-shadow: inset 0 4px 0 var(--slot-line), 0 -2px 12px rgba(21, 32, 51, .08);
}

.band-row.is-band-drop-after {
  box-shadow: inset 0 -4px 0 var(--slot-line), 0 2px 12px rgba(21, 32, 51, .08);
}

.band-drag-ghost {
  max-width: 340px;
}

.band-drag-ghost .mini-button {
  display: none;
}

.is-dragging-band .band-row {
  cursor: grabbing;
}

.author-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.author-row strong {
  min-width: 0;
  font-size: 13px;
  line-height: 1.2;
}

.reader-mode .editor-panel,
.reader-mode .card-actions,
.reader-mode #newItemButton,
.reader-mode #manageAuthorsButton,
.reader-mode #manageBandsButton {
  display: none;
}

.reader-mode .item-card {
  cursor: default;
}

.reader-mode .workspace {
  grid-template-columns: minmax(0, 1fr);
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .topbar,
  .control-band,
  .toolbar,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .role-switch,
  .tabs,
  .filter-row {
    width: 100%;
  }

  .role-button,
  .tab {
    flex: 1 1 0;
  }

  .tabs {
    overflow-x: auto;
  }

  .filter-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .search-field {
    min-width: 0;
  }

  .day-strip {
    display: flex;
    overflow-x: auto;
  }

  .day-chip {
    min-width: 128px;
  }

  .week-header {
    display: none;
  }

  .week-table {
    gap: 12px;
    background: transparent;
  }

  .week-row {
    grid-template-columns: 1fr;
    overflow: hidden;
    border: 1px solid var(--slot-line);
    border-radius: 8px;
    background: var(--slot-bg);
  }

  .slot-label {
    min-height: 0;
    border: 0;
    border-bottom: 1px solid var(--slot-line);
  }

  .slot-cell {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mobile-day-label {
    display: block;
  }

  .empty-slot {
    min-height: 54px;
  }

  .week-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .day-column {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .column-title {
    font-size: 15px;
  }
}

@media (max-width: 520px) {
  main {
    padding: 12px 10px 28px;
  }

  .topbar {
    padding: 12px 10px;
  }

  .masthead-image {
    width: min(100%, 360px);
    height: 34px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .band-form,
  .author-form,
  .author-row,
  .band-row {
    grid-template-columns: 1fr;
  }

  .band-marker {
    width: 100%;
    height: 5px;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
