:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #d9e0ea;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #275f8e;
    --success-bg: #e9f9ec;
    --success-br: #9ed3aa;
    --error-bg: #fdeaea;
    --error-br: #efaaaa;
    --warn-bg: #fff7dc;
    --warn-br: #ebcf68;
  }
  
  * { box-sizing: border-box; }
  
  body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
  }
  
  a {
    color: var(--primary);
    text-decoration: none;
  }
  
  .topbar {
    background: white;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 14px 18px;
  }
  
  .brand {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 10px;
  }
  
  .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  
  .nav a {
    background: white;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 8px;
  }
  
  .page {
    padding: 18px;
  }
  
  .card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
  }
  
  .form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 12px;
  }
  
  label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
  }
  
  input[type="text"],
  input[type="number"],
  textarea,
  select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
  }
  
  textarea {
    min-height: 260px;
    resize: vertical;
  }
  
  button,
  .button-link {
    display: inline-block;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    color: var(--text);
  }
  
  button.primary,
  .button-link.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
  }
  
  .row-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 14px 0;
  }
  
  .flash {
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 14px;
  }
  
  .flash.ok {
    background: var(--success-bg);
    border: 1px solid var(--success-br);
  }
  
  .flash.err {
    background: var(--error-bg);
    border: 1px solid var(--error-br);
  }
  
  .flash.warn {
    background: var(--warn-bg);
    border: 1px solid var(--warn-br);
  }
  
  .table-wrap {
    overflow: auto;
    max-width: 100%;
    max-height: 78vh;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
  }
  
  table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
  }
  
  th, td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    font-size: 13px;
    white-space: nowrap;
    vertical-align: top;
  }
  
  thead th {
    background: #eef3f8;
    position: sticky;
    top: 0;
    z-index: 4;
  }
  
  .sticky {
    position: sticky;
    left: 0;
    background: white;
    z-index: 3;
  }
  
  thead .sticky {
    z-index: 5;
    background: #e4eaf2;
  }
  
  .day-sat { background: #d9ecff !important; }
  .day-sun { background: #ffdede !important; }
  .day-hol { background: #ffe699 !important; }
  
  .center { text-align: center; }
  .small-select { min-width: 82px; }
  .tag {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 9px;
    background: #eef2f7;
    margin-right: 7px;
    font-size: 12px;
  }
  .muted { color: var(--muted); }
  
  .htmx-indicator {
    display: none;
    margin-left: 12px;
    color: var(--muted);
  }
  
  .htmx-request .htmx-indicator,
  .htmx-request.htmx-indicator {
    display: inline;
  }
  
  pre {
    white-space: pre-wrap;
    word-break: break-word;
  }


  .day-sat .ag-header-cell-label {
    background: #d9ecff;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  
  .day-sun .ag-header-cell-label {
    background: #ffdede;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  
  .day-hol .ag-header-cell-label {
    background: #ffe699;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  
  #form2-grid .ag-cell {
    padding-left: 4px;
    padding-right: 4px;
  }
  
  #form2-grid .ag-cell-value,
  #form2-grid .ag-header-cell-label {
    font-size: 13px;
  }

  .day-sat .ag-header-cell-label {
    background: #d9ecff;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  
  .day-sun .ag-header-cell-label {
    background: #ffdede;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  
  .day-hol .ag-header-cell-label {
    background: #ffe699;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  
  #form2-grid .ag-cell {
    padding-left: 4px;
    padding-right: 4px;
  }
  
  #form2-grid .ag-cell-value,
  #form2-grid .ag-header-cell-label {
    font-size: 13px;
  }
  
  #form2-grid .cell-fixed {
    background: #e8dffb;
  }
  
  #form2-grid .cell-desired {
    background: #d9f7e8;
  }
  
  #form2-grid .cell-rest {
    background: #eef2f7;
  }
  
  #form2-grid .cell-prefilled-lock {
    background: #f3f4f6 !important;
    color: #6b7280;
    font-style: italic;
  }
  
  .legend-box {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 1px solid #b8c2cc;
    margin-right: 6px;
    vertical-align: middle;
  }
  
  .legend-text {
    margin-right: 16px;
    vertical-align: middle;
    font-size: 13px;
  }
  
  .legend-fixed {
    background: #e8dffb;
  }
  
  .legend-desired {
    background: #d9f7e8;
  }
  
  .legend-rest {
    background: #eef2f7;
  }
  
  .legend-prefilled {
    background: #f3f4f6;
  }

  input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    margin-bottom: 12px;
  }
  
  .preferences-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
  }
  
  .preference-day {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  
  .nav form {
    margin: 0;
  }
  
  @media (max-width: 700px) {
    .form-grid {
      grid-template-columns: 1fr;
    }
  
    .page {
      padding: 10px;
    }
  }

/* =========================================================
   Tema Turni — versione 2
   ========================================================= */

   :root {
    --bg: #f3f6f8;
    --card: #ffffff;
    --border: #dde5ea;
    --text: #243742;
    --muted: #596b78;
    --primary: #176c69;
    --sidebar: #173b45;
    --sidebar-text: #e8f1f3;
  }
  
  body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.55;
    background: var(--bg);
  }
  
  button, input, select, textarea {
    font: inherit;
  }
  
  a, button, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
  }
  
  :focus-visible {
    outline: 3px solid #338bba;
    outline-offset: 3px;
  }
  
  .skip-link {
    position: fixed;
    top: 10px;
    left: 10px;
    transform: translateY(-150%);
    z-index: 1000;
    background: white;
    padding: 12px 18px;
    border-radius: 8px;
  }
  
  .skip-link:focus {
    transform: translateY(0);
  }
  
  .app-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
  }
  
  .app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 28px 16px 18px;
    background: var(--sidebar);
    color: var(--sidebar-text);
  }
  
  .app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 10px;
    color: white;
  }
  
  .brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 14px;
    background: #c9eee5;
    color: #173b45;
    font-size: 25px;
    font-weight: 800;
  }
  
  .app-brand strong {
    display: block;
    font-size: 25px;
    letter-spacing: -0.8px;
  }
  
  .app-brand small {
    display: block;
    color: #c3d7dd;
    font-size: 11px;
  }
  
  .sidebar-caption {
    margin: 30px 12px 12px;
    color: #b7ced5;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
  }
  
  .app-nav {
    display: grid;
    gap: 5px;
  }
  
  .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-size: 13px;
    transition: background-color 150ms ease;
  }
  
  .nav-item:hover {
    background: #254b56;
  }
  
  .nav-item.active {
    background: #c9eee5;
    color: #163c3b;
    font-weight: 700;
  }
  
  .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 18px;
  }
  
  .sidebar-user {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: auto;
    padding-top: 24px;
  }
  
  .user-avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #315966;
    font-weight: 700;
  }
  
  .user-details {
    flex: 1;
    min-width: 0;
  }
  
  .user-details strong {
    display: block;
    overflow-wrap: anywhere;
    font-size: 12px;
  }
  
  .user-details small {
    display: block;
    font-size: 10px;
    color: #bfd2d8;
  }
  
  .sidebar-user form {
    margin: 0;
  }
  
  .logout-button {
    min-height: 40px;
    padding: 6px 10px;
    border-color: #78959e;
    background: transparent;
    color: white;
    font-size: 12px;
  }
  
  .logout-button:hover {
    background: #315966;
    color: white;
  }
  
  .sidebar-welcome {
    margin-top: 70px;
    padding: 0 12px;
  }
  
  .sidebar-welcome .sidebar-caption {
    margin-left: 0;
  }
  
  .sidebar-welcome h2 {
    color: white;
    font-size: 28px;
    line-height: 1.25;
  }
  
  .sidebar-welcome p:not(.sidebar-caption) {
    color: #c3d7dd;
    font-size: 14px;
  }
  
  .app-main {
    min-width: 0;
  }
  
  .page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 30px 32px 12px;
  }
  
  .eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.3px;
  }
  
  .page-heading h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 32px);
    letter-spacing: -0.8px;
  }
  
  .session-badge {
    padding: 7px 12px;
    border: 1px solid #c7ded7;
    border-radius: 999px;
    background: #e8f5ef;
    color: #28654f;
    font-size: 12px;
    white-space: nowrap;
  }
  
  .page {
    padding: 18px 32px 28px;
  }
  
  .card {
    padding: 24px;
    margin-bottom: 22px;
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 5px 20px rgb(25 50 65 / 4%);
  }
  
  .card h2, .card h3 {
    margin-top: 0;
    margin-bottom: 16px;
    letter-spacing: -0.4px;
  }
  
  .card h2 {
    font-size: 21px;
  }
  
  .card h3 {
    font-size: 17px;
  }
  
  label {
    color: #465b68;
    font-size: 13px;
    font-weight: 600;
  }
  
  input[type="text"],
  input[type="number"],
  input[type="password"],
  textarea,
  select {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 10px;
    border-color: #ccd8df;
    color: var(--text);
    background: #fbfcfd;
  }
  
  input[type="password"] {
    margin-bottom: 16px;
  }
  
  input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    background: white;
  }
  
  input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    vertical-align: middle;
  }
  
  select:disabled, input:disabled {
    cursor: not-allowed;
    background: #edf1f4;
    color: #596b78;
  }
  
  textarea {
    line-height: 1.6;
  }
  
  button, .button-link {
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    transition: background-color 150ms ease, border-color 150ms ease;
  }
  
  button:hover, .button-link:hover {
    border-color: #a6bcc7;
    background: #eef4f6;
  }
  
  button.primary, .button-link.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
  }
  
  button.primary:hover, .button-link.primary:hover {
    background: #125653;
    border-color: #125653;
  }
  
  button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
  }
  
  .row-actions {
    align-items: center;
    gap: 10px;
    margin: 20px 0;
  }
  
  .row-actions > form {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    min-width: min(100%, 260px);
  }
  
  .row-actions > form button {
    margin-top: 12px;
  }
  
  .flash {
    padding: 14px 18px;
    border-radius: 12px;
    border-left-width: 4px !important;
    overflow-wrap: anywhere;
  }
  
  .flash.ok {
    color: #245d35;
  }
  
  .flash.err {
    color: #8e3030;
  }
  
  .flash.warn {
    color: #715315;
  }
  
  .table-wrap {
    border-radius: 12px;
  }
  
  th, td {
    padding: 10px 12px;
    font-size: 13px;
    vertical-align: middle;
  }
  
  thead th {
    color: #405865;
    background: #edf3f6;
    font-weight: 700;
  }
  
  tbody tr:nth-child(even) {
    background: #f8fafb;
  }
  
  tbody tr:hover {
    background: #edf5f6;
  }
  
  tbody tr:hover > .sticky {
    background: #edf5f6;
  }
  
  td.center {
    font-weight: 700;
  }
  
  .tag {
    padding: 6px 11px;
    background: #edf3f6;
    color: #3b5563;
    font-weight: 600;
  }
  
  .preferences-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
  }
  
  .preference-day {
    padding: 16px;
    border-radius: 14px;
    background: #f8fbfc;
    border: 1px solid #dbe6eb;
  }
  
  .preference-day label {
    margin-bottom: 12px;
    color: #314f5e;
  }
  
  .preference-day:focus-within {
    border-color: var(--primary);
    background: #eff8f5;
  }
  
  #form2-grid {
    --ag-font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    --ag-font-size: 13px;
    --ag-border-color: #dde5ea;
    --ag-header-background-color: #edf3f6;
    --ag-row-hover-color: #edf5f6;
    --ag-selected-row-background-color: #e4f2ee;
  }
  
  #form2-grid .ag-root-wrapper {
    border-radius: 0;
  }
  
  .app-footer {
    padding: 0 32px 24px;
    color: var(--muted);
    font-size: 11px;
  }
  
  .signed-out .page > .card {
    width: 100%;
  }
  
  @media (max-width: 1100px) {
    .form-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  
    .app-layout {
      grid-template-columns: 220px minmax(0, 1fr);
    }
  
    .page-heading {
      padding: 24px 20px 10px;
    }
  
    .page {
      padding: 16px 20px;
    }
  }
  
  @media (max-width: 760px) {
    .app-layout {
      display: block;
    }
  
    .app-sidebar {
      position: static;
      height: auto;
      padding: 16px;
    }
  
    .app-brand strong {
      font-size: 22px;
    }
  
    .sidebar-caption {
      margin-top: 18px;
    }
  
    .app-nav {
      display: flex;
      overflow-x: auto;
      padding-bottom: 8px;
      gap: 7px;
    }
  
    .nav-item {
      flex-shrink: 0;
      white-space: nowrap;
      background: #254b56;
    }
  
    .sidebar-user {
      padding-top: 12px;
    }
  
    .sidebar-welcome {
      display: none;
    }
  
    .page-heading {
      padding: 22px 16px 8px;
    }
  
    .session-badge {
      display: none;
    }
  
    .page {
      padding: 12px;
    }
  
    .card {
      padding: 18px;
      border-radius: 14px;
    }
  
    .form-grid {
      grid-template-columns: 1fr;
    }
  
    .preferences-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }
  
    .preference-day {
      padding: 12px;
    }
  
    .preference-day select {
      font-size: 16px;
      padding: 8px;
    }
  
    .app-footer {
      padding: 12px 16px 24px;
    }
  }
  
  @media (max-width: 380px) {
    .preferences-grid {
      grid-template-columns: 1fr;
    }
  }
  
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      transition: none !important;
      animation: none !important;
    }
  }
