@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;400;600&display=swap');

@page { 
    size: A4 landscape; 
    margin: 8mm;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --row-h: 32px;
    --row-font-size: 14px;
    --accent-color: #6b8e7f;
    --accent-light: #a8c5b8;
    --accent-dark: #567368;
    --accent-ultra-light: rgba(107, 142, 127, 0.08);
    --accent-hover-light: rgba(107, 142, 127, 0.03);
    --accent-focus-light: rgba(107, 142, 127, 0.08);
    --accent-focus-shadow: rgba(107, 142, 127, 0.15);
}

html, body {
    height: 100%;
    font-family: 'Cormorant Garamond', serif;
    background: #030303;
    color: #2c2c2c;
}

/* ========== COLOR PICKER ========== */
.color-picker {
    position: fixed;
    left: 20px;
    bottom: 20px;
    z-index: 9999;
    display: flex;
    gap: 10px;
    background: rgba(0,0,0,0.85);
    padding: 12px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.color-picker:hover {
    transform: translateY(-4px);
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

.color-option::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.color-option:hover {
    transform: scale(1.2) rotate(5deg);
    border-color: rgba(255,255,255,0.3);
}

.color-option.active {
    border-color: white;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.2);
    transform: scale(1.1);
}

.color-option.active::after {
    border-color: rgba(255,255,255,0.4);
}

/* ========== CONTROLS ========== */
.controls {
    position: fixed;
    right: 20px;
    top: 20px;
    z-index: 9999;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.controls button {
    background: #030303;
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 10px 18px;
    text-transform: uppercase;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Cormorant Garamond', serif;
    letter-spacing: 1.5px;
    font-size: 13px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    gap: 8px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.controls button:hover {
    background: #1a1a1a;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.5);
}

.controls button:active {
    transform: translateY(-1px);
}

.controls button svg {
    width: 14px;
    height: 14px;
    fill: white;
    transition: transform 0.3s ease;
}

.controls button:hover svg {
    transform: scale(1.1);
}

/* History buttons */
.history-controls {
    position: fixed;
    left: 180px;
    top: 20px;
    z-index: 9999;
    display: flex;
    gap: 10px;
}

.history-controls button {
    background: #030303;
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Cormorant Garamond', serif;
    letter-spacing: 1px;
    font-size: 13px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.history-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: scale(0.95);
}

.history-controls button:not(:disabled):hover {
    background: #1a1a1a;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.5);
}

/* Row controls */
.row-controls {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 20px;
    z-index: 9999;
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.row-controls button {
    background: #030303;
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Cormorant Garamond', serif;
    letter-spacing: 0.5px;
    font-size: 11px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-transform: uppercase;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    white-space: nowrap;
}

.row-controls button:hover {
    background: #1a1a1a;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.5);
}

.row-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

/* ========== PAGE LAYOUT ========== */
.frame-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 40px 30px;
}

.page {
    width: 297mm;
    max-width: 1260px;
    height: 210mm;
    background: #faf8f5;
    padding: 8mm 12mm;
    position: relative;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    transition: width 0.3s ease, height 0.3s ease, max-width 0.3s ease;
}

/* Portrait mode */
body.portrait-mode .page {
    width: 210mm;
    max-width: 890px;
    height: 297mm;
}

body.portrait-mode @page {
    size: A4 portrait;
}

/* Hide footer */
body.hide-footer .meta-section {
    display: none !important;
}

body.hide-footer .section {
    flex: 1;
}

/* ========== HEADER ========== */
.card-header {
    text-align: center;
    padding: 0 0 2px 0;
    border-bottom: none;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.title-input {
    font-size: 24px;
    font-weight: 600;
    color: #5d4a36;
    /* text-transform: uppercase; - desactivat per permetre minúscules */
    letter-spacing: 2px;
    outline: none;
    border: none;
    background: transparent;
    width: 100%;
    text-align: center;
    font-family: 'Cormorant Garamond', serif;
    line-height: 0.95;
    border-radius: 6px;
    padding: 3px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.title-input:hover {
    background: var(--accent-hover-light);
}

.title-input:focus {
    background: var(--accent-focus-light);
    transform: scale(1.01);
    box-shadow: 0 0 0 2px var(--accent-focus-shadow);
}

.subtitle-helper {
    font-size: 14px;
    color: var(--accent-color);
    letter-spacing: 0.8px;
    margin-top: 0px;
    margin-bottom: 4px;
    outline: none;
    border: none;
    background: transparent;
    width: 100%;
    text-align: center;
    font-family: 'Cormorant Garamond', serif;
    border-radius: 4px;
    padding: 1px;
    transition: all 0.3s ease;
}

.subtitle-helper:hover {
    background: var(--accent-hover-light);
}

.subtitle-helper:focus {
    background: var(--accent-focus-light);
    box-shadow: 0 0 0 2px var(--accent-focus-shadow);
}

/* ========== TABLE SECTION ========== */
.section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    font-family: 'Cormorant Garamond', serif;
    border-radius: 8px;
    height: 100%;
    max-height: 100%;
    border: 1px solid rgba(107, 142, 127, 0.2);
    overflow: hidden;
}

tbody {
    display: table-row-group;
    overflow: hidden;
}

thead th {
    background: var(--accent-color);
    color: white;
    padding: 7px 5px;
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 1px;
    /* text-transform: uppercase; - desactivat per permetre minúscules */
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    height: auto;
}

thead th:first-child {
    border-top-left-radius: 8px;
}

thead th:last-child {
    border-right: none;
}

thead th.day {
    width: 9%;
    font-family: "Libre Franklin", Arial, sans-serif;
    font-size: 8px;
}

thead th.time {
    width: 7%;
    font-family: "Libre Franklin", Arial, sans-serif;
    font-size: 8px;
}

thead th.editable-header {
    /* width gestionat dinàmicament per adjustColumnWidths() */
}

thead th.cell-actions {
    width: 100px;
    max-width: 100px;
    min-width: 100px;
    border-top-right-radius: 8px;
}

/* Hide DAY */
body.hide-day thead th.day,
body.hide-day tbody td:nth-child(1) {
    display: none;
}

body.hide-day:not(.hide-time) thead th.time:first-of-type {
    border-top-left-radius: 8px;
}

body.hide-day:not(.hide-time) tbody tr:first-child td:nth-child(2) {
    border-top-left-radius: 8px;
}

body.hide-day:not(.hide-time) tbody tr:last-child td:nth-child(2) {
    border-bottom-left-radius: 8px;
}

/* Hide TIME */
body.hide-time thead th.time,
body.hide-time tbody td:nth-child(2) {
    display: none;
}

body.hide-time:not(.hide-day) thead th.day:first-of-type {
    border-top-left-radius: 8px;
}

body.hide-time:not(.hide-day) tbody tr:first-child td:nth-child(1) {
    border-top-left-radius: 8px;
}

body.hide-time:not(.hide-day) tbody tr:last-child td:nth-child(1) {
    border-bottom-left-radius: 8px;
}

/* Hide BOTH DAY and TIME */
body.hide-day.hide-time thead th.editable-header:first-of-type {
    border-top-left-radius: 8px;
}

body.hide-day.hide-time tbody tr:first-child td:nth-child(3) {
    border-top-left-radius: 8px;
}

body.hide-day.hide-time tbody tr:last-child td:nth-child(3) {
    border-bottom-left-radius: 8px;
}

thead th.editable-header {
    cursor: text;
    transition: all 0.3s ease;
}

thead th.editable-header:hover {
    background: var(--accent-dark);
    transform: scale(1.02);
}

thead th.editable-header:focus {
    outline: none;
    background: var(--accent-dark);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.3);
}

thead th.editable-header:empty::before {
    content: 'Click to edit';
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
}

tbody tr {
    animation: fadeIn 0.4s ease;
    transition: all 0.2s ease;
    height: var(--row-h, 32px);
    max-height: var(--row-h, 32px);
    overflow: hidden;
}

tbody tr:nth-child(even) {
    background: var(--accent-ultra-light);
}

tbody tr:nth-child(odd) {
    background: white;
}

tbody tr:hover {
    background: rgba(107, 142, 127, 0.12);
    transform: scale(1.002);
}

tbody tr.removing {
    animation: fadeOut 0.3s ease forwards;
}

tbody td {
    padding: 2px 4px;
    text-align: center;
    border-bottom: 1px solid rgba(180, 170, 160, 0.15);
    border-right: 1px solid rgba(107, 142, 127, 0.2);
    vertical-align: middle;
    font-size: var(--row-font-size, 14px);
    transition: all 0.2s ease;
    height: inherit;
    max-height: inherit;
    overflow: hidden;
    box-sizing: border-box;
}

tbody tr:last-child td {
    border-bottom: 1px solid rgba(107, 142, 127, 0.2);
}

tbody tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}

tbody tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

tbody td:last-child {
    border-right: none;
}

tbody td:nth-child(2) {
    border-right: 1px solid rgba(107, 142, 127, 0.2);
}

tbody td:nth-child(3) {
    border-right: 1px solid rgba(107, 142, 127, 0.2);
}

select {
    width: 100%;
    border: none;
    background: transparent;
    font-family: "Libre Franklin", Arial, sans-serif;
    font-size: 9px;
    font-weight: 400;
    padding: 4px;
    cursor: pointer;
    letter-spacing: 0.2px;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 4px;
    transition: all 0.3s ease;
    text-align: center;
}

select:hover {
    background: rgba(107, 142, 127, 0.08);
}

select:focus {
    background: rgba(107, 142, 127, 0.15);
    box-shadow: 0 0 0 2px rgba(107, 142, 127, 0.3);
    transform: scale(1.02);
}

select::-ms-expand {
    display: none;
}

span[contenteditable="true"] {
    display: block;
    width: 100%;
    min-height: 1em;
    font-weight: 600;
    outline: none;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

span[contenteditable="true"]:hover {
    background: rgba(107, 142, 127, 0.08);
}

span[contenteditable="true"]:focus {
    background: rgba(107, 142, 127, 0.15);
    box-shadow: 0 0 0 2px rgba(107, 142, 127, 0.25);
    transform: scale(1.01);
}

/* ========== ACTION BUTTONS ========== */
.cell-actions {
    white-space: nowrap;
    max-width: 100px;
    width: 100px;
    min-width: 100px;
    overflow: visible;
    text-align: center;
}

.action-btn {
    background: white;
    border: 1px solid rgba(107, 142, 127, 0.3);
    color: var(--accent-color);
    padding: 2px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    margin: 0 1px;
    display: inline-block;
    vertical-align: middle;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.action-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 12px rgba(107, 142, 127, 0.3);
}

.action-btn:active {
    transform: translateY(0) scale(0.98);
}

/* ========== FOOTER ========== */
.meta-section {
    padding: 4px 0 2px 0;
    margin-top: 6px;
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-start;
    font-size: 12px;
    flex-wrap: nowrap;
    flex-shrink: 0;
    width: 100%;
    border-top: 1px solid rgba(107, 142, 127, 0.15);
}

.meta-field {
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.meta-field label {
    color: var(--accent-color);
    font-size: 11px;
    letter-spacing: 0.5px;
    font-weight: 600;
    font-family: 'Cormorant Garamond', serif;
    text-transform: uppercase;
}

.meta-field input {
    padding: 3px 6px;
    border: 1px solid rgba(107, 142, 127, 0.2);
    background: rgba(255, 255, 255, 0.8);
    font-family: 'Cormorant Garamond', serif;
    font-size: 12px;
    border-radius: 4px;
    outline: none;
    min-width: 80px;
    max-width: 110px;
    transition: all 0.2s ease;
}

/* Retreat name field - more compact */
.meta-field input#retreat-name {
    min-width: 60px;
    max-width: 80px;
}

.meta-field input:hover {
    border-color: var(--accent-color);
    background: white;
}

.meta-field input:focus {
    border-color: var(--accent-color);
    background: white;
    box-shadow: 0 0 0 2px rgba(107, 142, 127, 0.1);
}

.meta-field input[type="date"] {
    font-family: "Libre Franklin", Arial, sans-serif;
    font-size: 11px;
    min-width: 100px;
    max-width: 100px;
}

.meta-field span {
    color: #5d4a36;
    font-weight: 500;
    font-size: 12px;
}

.meta-days {
    min-width: auto;
}

.meta-days span {
    font-size: 11px;
    color: var(--accent-color);
    font-style: italic;
}

.meta-separator {
    color: rgba(107, 142, 127, 0.3);
    font-size: 14px;
    padding: 0 2px;
}

.meta-editable {
    padding: 2px 5px;
    border-radius: 3px;
    outline: none;
    transition: all 0.2s ease;
    cursor: text;
    min-width: 45px;
    display: inline-block;
}

.meta-editable:hover {
    background: rgba(107, 142, 127, 0.08);
}

.meta-editable:focus {
    background: rgba(107, 142, 127, 0.12);
    box-shadow: 0 0 0 1px rgba(107, 142, 127, 0.2);
}

.meta-disclaimer {
    font-size: 11px;
    color: #888;
    font-style: italic;
    white-space: nowrap;
    margin-left: auto;
    padding: 2px 5px;
    border-radius: 3px;
    outline: none;
    transition: all 0.2s ease;
    cursor: text;
}

.meta-disclaimer:hover {
    background: rgba(107, 142, 127, 0.08);
}

.meta-disclaimer:focus {
    background: rgba(107, 142, 127, 0.12);
    box-shadow: 0 0 0 1px rgba(107, 142, 127, 0.2);
}

/* Hide disclaimer class */
body.hide-disclaimer .meta-disclaimer {
    display: none !important;
}

/* ========== WATERMARK ========== */
.watermark {
    position: absolute;
    bottom: 30px;
    right: 40px;
    font-size: 80px;
    color: rgba(201, 169, 97, 0.06);
    pointer-events: none;
    user-select: none;
    z-index: 0;
}

/* ========== TOAST ========== */
.toast {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
    color: white;
    padding: 14px 22px;
    border-radius: 12px;
    font-size: 14px;
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10000;
    pointer-events: none;
    display: none;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    backdrop-filter: blur(10px);
}

.toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    display: block;
}

/* ========== ANIMATIONS ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(-20px);
    }
}

/* ========== FEWER THAN 16 ROWS ========== */
body:not(.has-16-rows):not(.has-18-rows):not(.has-20-rows):not(.has-21-rows):not(.has-23-rows):not(.has-24-rows):not(.has-25-rows) tbody td {
    padding: 0.5px 5px;
    font-size: 16px;
    line-height: 1.3;
}

body:not(.has-16-rows):not(.has-18-rows):not(.has-20-rows):not(.has-21-rows):not(.has-23-rows):not(.has-24-rows):not(.has-25-rows) thead th {
    padding: 3px 5px;
    font-size: 16px;
}

/* ========== 16 ROWS MODE ========== */
body.has-16-rows tbody td {
    padding: 1px 5px;
    font-size: 16px;
    line-height: 1.3;
}

body.has-16-rows thead th {
    padding: 3px 5px;
    font-size: 16px;
}

/* ========== 18 ROWS MODE ========== */
body.has-18-rows tbody td {
    padding: 0px 4px;
    font-size: 16px;
    line-height: 1.2;
}

body.has-18-rows thead th {
    padding: 2px 4px;
    font-size: 16px;
}

/* ========== 20 ROWS MODE ========== */
body.has-20-rows tbody td {
    padding: 0px 4px;
    font-size: 16px;
    line-height: 1.2;
}

body.has-20-rows thead th {
    padding: 2px 4px;
    font-size: 16px;
}

/* ========== 21 ROWS MODE (ULTRA COMPACT) ========== */
body.has-21-rows tbody td {
    padding: 0px 3px;
    font-size: 16px;
    line-height: 1.1;
}

body.has-21-rows thead th {
    padding: 1px 3px;
    font-size: 16px;
}

/* ========== 23 ROWS MODE (SUPER COMPACT) ========== */
body.has-23-rows tbody td {
    padding: 0px 3px;
    font-size: 16px;
    line-height: 1.0;
}

body.has-23-rows thead th {
    padding: 0px 3px;
    font-size: 16px;
}

/* ========== 24 ROWS MODE ========== */
body.has-24-rows tbody td {
    padding: 0px 3px;
    font-size: 16px;
    line-height: 0.95;
}

body.has-24-rows thead th {
    padding: 2px 3px;
    font-size: 16px;
    line-height: 0.95;
}

/* ========== 25 ROWS MODE ========== */
body.has-25-rows tbody td {
    padding: 0px 2px;
    font-size: 14px;
    line-height: 0.85;
}

body.has-25-rows thead th {
    padding: 1px 2px;
    font-size: 14px;
    line-height: 0.85;
}

body.has-25-rows tbody tr {
    height: var(--row-h, 20px);
    max-height: var(--row-h, 20px);
}

body.has-25-rows select {
    padding: 1px;
    font-size: 8px;
}

body.has-25-rows span[contenteditable="true"] {
    padding: 1px;
    min-height: 0.8em;
}

/* ========== 30 ROWS MODE (PORTRAIT) ========== */
body.has-30-rows tbody td {
    padding: 0px 2px;
    font-size: 13px;
    line-height: 0.9;
}

body.has-30-rows thead th {
    padding: 1px 2px;
    font-size: 12px;
}

/* ========== 35 ROWS MODE (PORTRAIT) ========== */
body.has-35-rows tbody td {
    padding: 0px 2px;
    font-size: 12px;
    line-height: 0.85;
}

body.has-35-rows thead th {
    padding: 1px 2px;
    font-size: 11px;
}

/* ========== 40 ROWS MODE (PORTRAIT) ========== */
body.has-40-rows tbody td {
    padding: 0px 1px;
    font-size: 11px;
    line-height: 0.8;
}

body.has-40-rows thead th {
    padding: 0px 1px;
    font-size: 10px;
}

/* ========== 45 ROWS MODE (PORTRAIT) ========== */
body.has-45-rows tbody td {
    padding: 0px 1px;
    font-size: 10px;
    line-height: 0.75;
}

body.has-45-rows thead th {
    padding: 0px 1px;
    font-size: 9px;
}

/* ========== GRID VIEW ========== */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 300px));
    gap: 20px;
    padding: 20px;
    height: 100%;
    overflow-y: auto;
    max-width: 100%;
    justify-content: start;
}

.grid-item {
    background: white;
    border: 1px solid var(--accent-color);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    height: fit-content;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 300px;
}

.grid-item:hover {
    background: var(--accent-ultra-light);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(107, 142, 127, 0.2);
    border-color: var(--accent-dark);
}

.grid-item .day {
    font-weight: 600;
    color: var(--accent-color);
    font-size: 11px;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.grid-item .time {
    font-weight: 600;
    color: #5d4a36;
    font-size: 14px;
    margin-bottom: 8px;
}

.grid-item .therapist {
    font-size: 13px;
    color: #2c2c2c;
    margin: 4px 0;
    font-weight: 600;
}

/* ========== RESPONSIVE MOBILE ========== */
@media (max-width: 768px) {
    /* Fons negre eliminat - document ocupa tota la pantalla */
    html, body {
        background: white;
        margin: 0;
        padding: 0;
    }
    
    .frame-wrap {
        padding: 0;
        min-height: 100vh;
        background: white;
    }
    
    .page {
        box-shadow: none;
        border-radius: 0;
        margin: 0;
        padding: 15px;
        min-height: 100vh;
    }
    
    /* Amagar controls desktop */
    .controls,
    .history-controls,
    .row-controls,
    .color-picker {
        display: none !important;
    }
    
    /* Amagar els mobile toggles que ja existien */
    .mobile-menu-toggle,
    .mobile-edit-toggle,
    .mobile-color-toggle {
        display: none !important;
    }
    
    /* Tres botons rodons a baix dreta */
    body::after {
        content: '';
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 10000;
        pointer-events: none;
    }
    
    /* Botó 1: General (arxius) - el més a baix */
    .controls {
        display: flex !important;
        position: fixed !important;
        bottom: 20px;
        right: 20px;
        z-index: 10001;
        flex-direction: column;
        gap: 8px;
        background: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(10px);
        border-radius: 50%;
        width: 56px;
        height: 56px;
        padding: 0;
        transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
        overflow: hidden;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
    
    .controls::before {
        content: '📁';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 24px;
        pointer-events: none;
        z-index: 1;
        transition: opacity 0.3s ease;
    }
    
    .controls.mobile-open {
        width: auto;
        height: auto;
        border-radius: 16px;
        padding: 12px;
        min-width: 200px;
    }
    
    .controls.mobile-open::before {
        opacity: 0;
    }
    
    .controls button {
        opacity: 0;
        transform: scale(0.5);
        pointer-events: none;
        transition: all 0.3s ease;
        margin: 0;
        width: 100%;
        justify-content: flex-start;
    }
    
    .controls.mobile-open button {
        opacity: 1;
        transform: scale(1);
        pointer-events: all;
    }
    
    /* Botó 2: Accions (edició) - al mig */
    .row-controls,
    .history-controls {
        display: flex !important;
        position: fixed !important;
        bottom: 90px;
        right: 20px;
        z-index: 10001;
        flex-direction: column;
        gap: 8px;
        background: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(10px);
        border-radius: 50%;
        width: 56px;
        height: 56px;
        padding: 0;
        transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
        overflow: hidden;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }
    
    .row-controls::before {
        content: '✏️';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 24px;
        pointer-events: none;
        z-index: 1;
        transition: opacity 0.3s ease;
    }
    
    .row-controls.mobile-open,
    .history-controls.mobile-open {
        width: auto;
        height: auto;
        border-radius: 16px;
        padding: 12px;
        min-width: 200px;
    }
    
    .row-controls.mobile-open::before {
        opacity: 0;
    }
    
    .row-controls button,
    .history-controls button {
        opacity: 0;
        transform: scale(0.5);
        pointer-events: none;
        transition: all 0.3s ease;
        margin: 0;
        width: 100%;
        justify-content: flex-start;
        font-size: 14px;
        padding: 10px 16px;
    }
    
    .row-controls.mobile-open button,
    .history-controls.mobile-open button {
        opacity: 1;
        transform: scale(1);
        pointer-events: all;
    }
    
    /* History controls ocults en mobile (els afegim via JS dins de rowControls) */
    .history-controls {
        display: none !important;
    }
    
    /* Botó 3: Colors - el més a dalt */
    .color-picker {
        display: flex !important;
        position: fixed !important;
        bottom: 160px;
        right: 20px;
        z-index: 10001;
        flex-direction: column;
        gap: 8px;
        background: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(10px);
        border-radius: 50%;
        width: 56px;
        height: 56px;
        padding: 0;
        left: auto;
        transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
        overflow: hidden;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
        justify-content: center;
        align-items: center;
    }
    
    .color-picker::before {
        content: '🎨';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-size: 24px;
        pointer-events: none;
        z-index: 1;
        transition: opacity 0.3s ease;
    }
    
    .color-picker.mobile-open {
        width: auto;
        height: auto;
        border-radius: 16px;
        padding: 12px;
        flex-direction: row;
        gap: 10px;
    }
    
    .color-picker.mobile-open::before {
        opacity: 0;
    }
    
    .color-option {
        opacity: 0;
        transform: scale(0.5);
        pointer-events: none;
        transition: all 0.3s ease;
    }
    
    .color-picker.mobile-open .color-option {
        opacity: 1;
        transform: scale(1);
        pointer-events: all;
    }
    
    /* Fer que els botons es puguin clicar per obrir/tancar */
    .controls,
    .row-controls,
    .color-picker {
        cursor: pointer;
    }
    
    /* Ajustar mida de taula */
    table {
        font-size: 14px;
    }
    
    thead th {
        padding: 8px 4px;
        font-size: 13px;
    }
    
    tbody td {
        padding: 6px 4px;
        font-size: 14px;
    }
    
    /* Meta section responsive */
    .meta-section {
        flex-direction: column;
        gap: 10px;
    }
    
    .meta-field {
        width: 100%;
    }
    
    .meta-field label {
        font-size: 12px;
    }
    
    .meta-field input {
        font-size: 14px;
        padding: 6px 10px;
    }
    
    /* Toast responsive */
    .toast {
        bottom: 100px;
        font-size: 14px;
        padding: 10px 16px;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    @page { 
        size: A4 landscape; 
        margin: 8mm;
    }
    
    body.hide-footer .meta-section {
        display: none !important;
    }
    
    @page :first {
        margin-top: 8mm;
    }
    
    title {
        display: none !important;
    }
    
    html, body {
        background: white !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .controls, .history-controls, .row-controls, .toast, .color-picker, .btn-templates, .template-modal {
        display: none !important;
    }
    
    .back-button {
        display: none !important;
    }
    
    .cell-actions {
        display: none !important;
    }
    
    .frame-wrap {
        padding: 0 !important;
        min-height: 0 !important;
        height: auto !important;
        display: block !important;
        margin: 0 !important;
    }
    
    .page {
        box-shadow: none !important;
        margin: 0 !important;
        padding: 4mm 6mm !important;
        width: 100% !important;
        height: 100vh !important;
        min-height: 100vh !important;
        max-height: 100vh !important;
        overflow: hidden !important;
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        background: transparent !important;
    }
    
    .card-header {
        padding: 0 0 2px 0 !important;
        flex-shrink: 0 !important;
    }
    
    .section {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }
    
    #table-therapies {
        flex: 1 !important;
        margin-bottom: 0 !important;
    }
    
    .footer {
        margin-top: auto !important;
        padding-top: 4px !important;
        flex-shrink: 0 !important;
        page-break-before: avoid !important;
        page-break-inside: avoid !important;
    }
    
    table {
        border-radius: 8px !important;
        overflow: hidden !important;
        max-height: 100% !important;
    }
    
    tbody {
        overflow: hidden !important;
    }
    
    thead th {
        background-color: var(--accent-color) !important;
        border-radius: 0 !important;
        padding: 10px 8px !important;
        flex-shrink: 0 !important;
    }
    
    thead th:first-child {
        border-radius: 8px 0 0 0 !important;
    }
    
    thead th:last-child {
        border-radius: 0 8px 0 0 !important;
    }
    
    tbody td {
        border-radius: 0 !important;
        padding: 6px !important;
        height: var(--row-h, auto) !important;
        max-height: var(--row-h, auto) !important;
        overflow: hidden !important;
    }
    
    tbody tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        height: var(--row-h, auto) !important;
        max-height: var(--row-h, auto) !important;
    }
    
    tbody tr:last-child td:first-child {
        border-radius: 0 0 0 8px !important;
    }
    
    tbody tr:last-child td:last-child {
        border-radius: 0 0 8px 0 !important;
    }
    
    tbody tr:nth-child(even) {
        background: var(--accent-ultra-light) !important;
    }
    
    tbody tr:nth-child(odd) {
        background: white !important;
    }
    
    .meta-section {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 10px !important;
        width: 100% !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        padding: 6px 0 4px 0 !important;
        margin-top: 6px !important;
        font-size: 11px !important;
    }
    
    .meta-section .meta-field {
        gap: 3px !important;
    }
    
    .meta-section .meta-field label {
        font-size: 10px !important;
    }
    
    .meta-section .meta-field input {
        font-size: 11px !important;
        padding: 2px 4px !important;
        min-width: 70px !important;
        max-width: 100px !important;
    }
    
    .meta-section .meta-field input[type="date"] {
        font-size: 10px !important;
        min-width: 85px !important;
        max-width: 85px !important;
    }
    
    .meta-section .meta-editable {
        font-size: 11px !important;
        padding: 1px 3px !important;
    }
    
    .meta-section .meta-separator {
        font-size: 12px !important;
    }
    
    .meta-section .meta-days span {
        font-size: 10px !important;
    }
    
    .meta-section .meta-disclaimer {
        font-size: 10px !important;
        margin-left: auto !important;
    }
    
    /* Al print: els elements amagats NO es mostren */
    /* Els altres elements es redistribueixen */
    body.hide-dates .meta-field-dates,
    body.hide-dates .meta-sep-dates {
        display: none !important;
    }
    
    body.hide-wifi .meta-field-wifi {
        display: none !important;
    }
    
    body.hide-sunrise .meta-field-sunrise {
        display: none !important;
    }
    
    body.hide-sunset .meta-field-sunset {
        display: none !important;
    }
    
    body.hide-moon .meta-field-moon {
        display: none !important;
    }
    
    body.hide-disclaimer .meta-field-disclaimer,
    body.hide-disclaimer .meta-sep-disclaimer {
        display: none !important;
    }
    
    /* Default for fewer rows */
    tbody td {
        padding: 1px 5px !important;
        font-size: 16px !important;
        line-height: 1.3 !important;
    }
    
    body.has-16-rows tbody td {
        padding: 1px 5px !important;
        font-size: 16px !important;
        line-height: 1.3 !important;
    }
    
    body.has-18-rows tbody td {
        padding: 0px 4px !important;
        font-size: 16px !important;
        line-height: 1.2 !important;
    }
    
    body.has-18-rows thead th {
        padding: 2px 4px !important;
        font-size: 16px !important;
    }
    
    body.has-20-rows tbody td {
        padding: 0px 4px !important;
        font-size: 16px !important;
        line-height: 1.2 !important;
    }
    
    body.has-20-rows thead th {
        padding: 2px 4px !important;
        font-size: 16px !important;
    }
    
    body.has-21-rows tbody td {
        padding: 0px 3px !important;
        font-size: 16px !important;
        line-height: 1.1 !important;
    }
    
    body.has-21-rows thead th {
        padding: 1px 3px !important;
        font-size: 16px !important;
    }
    
    body.has-23-rows tbody td {
        padding: 0px 3px !important;
        font-size: 16px !important;
        line-height: 1.0 !important;
    }
    
    body.has-23-rows thead th {
        padding: 0px 3px !important;
        font-size: 16px !important;
    }
    
    body.has-24-rows tbody td {
        padding: 0px 3px !important;
        font-size: 16px !important;
        line-height: 0.95 !important;
    }
    
    body.has-24-rows thead th {
        padding: 2px 3px !important;
        font-size: 16px !important;
        line-height: 0.95 !important;
    }
    
    body.has-25-rows tbody td {
        padding: 0px 3px !important;
        font-size: 15px !important;
        line-height: 0.85 !important;
    }
    
    body.has-25-rows thead th {
        padding: 3px 3px !important;
        font-size: 15px !important;
        line-height: 0.85 !important;
    }
    
    /* Portrait mode - many rows */
    body.portrait-mode.has-30-rows tbody td {
        padding: 0px 2px !important;
        font-size: 13px !important;
        line-height: 0.9 !important;
    }
    
    body.portrait-mode.has-30-rows thead th {
        padding: 2px 2px !important;
        font-size: 12px !important;
    }
    
    body.portrait-mode.has-35-rows tbody td {
        padding: 0px 2px !important;
        font-size: 12px !important;
        line-height: 0.85 !important;
    }
    
    body.portrait-mode.has-35-rows thead th {
        padding: 2px 2px !important;
        font-size: 11px !important;
    }
    
    body.portrait-mode.has-40-rows tbody td {
        padding: 0px 1px !important;
        font-size: 11px !important;
        line-height: 0.8 !important;
    }
    
    body.portrait-mode.has-40-rows thead th {
        padding: 2px 1px !important;
        font-size: 10px !important;
    }
    
    body.portrait-mode.has-45-rows tbody td {
        padding: 0px 1px !important;
        font-size: 10px !important;
        line-height: 0.75 !important;
    }
    
    body.portrait-mode.has-45-rows thead th {
        padding: 2px 1px !important;
        font-size: 9px !important;
    }
    
    thead th {
        font-size: 16px !important;
    }
    
    /* Print: Hide DAY */
    body.hide-day thead th.day,
    body.hide-day tbody td:nth-child(1) {
        display: none !important;
    }
    
    /* Print: Hide TIME */
    body.hide-time thead th.time,
    body.hide-time tbody td:nth-child(2) {
        display: none !important;
    }
    
    /* Print: Hide BOTH */
    body.hide-day.hide-time thead th.editable-header:first-of-type {
        border-top-left-radius: 8px !important;
    }
}

/* Libre Franklin font */
@font-face {
    font-family: "Libre Franklin";
    font-style: normal;
    font-weight: 400;
    src: local("Libre Franklin"), local("LibreFranklin-Regular"),
         url("https://fonts.gstatic.com/s/librefranklin/v14/jizYRExUiTo99u79D0KEx0hS.ttf") format("truetype");
}

/* Portrait mode print */
@media print {
    body.portrait-mode {
        width: 210mm;
        height: 297mm;
    }
    
    body.portrait-mode .page {
        width: 210mm !important;
        height: 297mm !important;
    }
}

@page portrait {
    size: A4 portrait;
    margin: 8mm;
}

/* ========== FOOTER OPTIONS DROPDOWN ========== */
.dropdown-container {
    position: relative;
    display: inline-block;
}

.dropdown-toggle {
    background: #030303;
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Cormorant Garamond', serif;
    letter-spacing: 0.5px;
    font-size: 11px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-transform: uppercase;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    white-space: nowrap;
}

.dropdown-toggle:hover {
    background: #1a1a1a;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    border-color: rgba(255,255,255,0.5);
}

.dropdown-menu {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    padding: 8px 0;
    min-width: 160px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 10000;
    margin-bottom: 8px;
    backdrop-filter: blur(10px);
}

.dropdown-menu.show {
    display: block;
    animation: dropdownFadeIn 0.2s ease;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: background 0.2s ease;
    color: white;
    font-family: 'Cormorant Garamond', serif;
    font-size: 12px;
    letter-spacing: 0.5px;
}

.dropdown-item:hover {
    background: rgba(255,255,255,0.1);
}

.dropdown-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.dropdown-item span {
    flex: 1;
}

/* ========== AMAGAR ELEMENTS DEL FOOTER (mantenen espai) ========== */
/* Usem visibility:hidden per mantenir proporcions i mides */

body.hide-dates .meta-field-dates,
body.hide-dates .meta-sep-dates {
    visibility: hidden;
}

body.hide-wifi .meta-field-wifi {
    visibility: hidden;
}

body.hide-sunrise .meta-field-sunrise {
    visibility: hidden;
}

body.hide-sunset .meta-field-sunset {
    visibility: hidden;
}

body.hide-moon .meta-field-moon {
    visibility: hidden;
}

body.hide-disclaimer .meta-field-disclaimer,
body.hide-disclaimer .meta-sep-disclaimer {
    visibility: hidden;
}
===========================================
AFEGIR AL FITXER styles.css
===========================================

🔴 SECCIÓ 1: DESPRÉS DE "/* ========== 25 ROWS MODE ========== */" (línia ~580)

AFEGIR AQUEST BLOC:

/* ========== 26 ROWS MODE ========== */
body.has-26-rows tbody td {
    padding: 0px 2px;
    font-size: 13px;
    line-height: 0.82;
}

body.has-26-rows thead th {
    padding: 1px 2px;
    font-size: 13px;
    line-height: 0.82;
}

body.has-26-rows tbody tr {
    height: var(--row-h, 19px);
    max-height: var(--row-h, 19px);
}

body.has-26-rows select {
    padding: 1px;
    font-size: 8px;
}

body.has-26-rows span[contenteditable="true"] {
    padding: 1px;
    min-height: 0.75em;
}

/* ========== 27 ROWS MODE ========== */
body.has-27-rows tbody td {
    padding: 0px 2px;
    font-size: 12px;
    line-height: 0.80;
}

body.has-27-rows thead th {
    padding: 1px 2px;
    font-size: 12px;
    line-height: 0.80;
}

body.has-27-rows tbody tr {
    height: var(--row-h, 18px);
    max-height: var(--row-h, 18px);
}

body.has-27-rows select {
    padding: 1px;
    font-size: 7px;
}

body.has-27-rows span[contenteditable="true"] {
    padding: 1px;
    min-height: 0.7em;
}

/* ========== 28 ROWS MODE ========== */
body.has-28-rows tbody td {
    padding: 0px 1px;
    font-size: 11px;
    line-height: 0.78;
}

body.has-28-rows thead th {
    padding: 1px 1px;
    font-size: 11px;
    line-height: 0.78;
}

body.has-28-rows tbody tr {
    height: var(--row-h, 17px);
    max-height: var(--row-h, 17px);
}

body.has-28-rows select {
    padding: 1px;
    font-size: 7px;
}

body.has-28-rows span[contenteditable="true"] {
    padding: 0px;
    min-height: 0.65em;
}

===========================================

🔴 SECCIÓ 2: DINS DE "@media print" DESPRÉS DE "body.has-25-rows" (línia ~1050)

AFEGIR AQUEST BLOC DINS DEL @media print:

    body.has-26-rows tbody td {
        padding: 0px 2px !important;
        font-size: 13px !important;
        line-height: 0.82 !important;
    }
    
    body.has-26-rows thead th {
        padding: 2px 2px !important;
        font-size: 13px !important;
        line-height: 0.82 !important;
    }
    
    body.has-27-rows tbody td {
        padding: 0px 2px !important;
        font-size: 12px !important;
        line-height: 0.80 !important;
    }
    
    body.has-27-rows thead th {
        padding: 2px 2px !important;
        font-size: 12px !important;
        line-height: 0.80 !important;
    }
    
    body.has-28-rows tbody td {
        padding: 0px 1px !important;
        font-size: 11px !important;
        line-height: 0.78 !important;
    }
    
    body.has-28-rows thead th {
        padding: 2px 1px !important;
        font-size: 11px !important;
        line-height: 0.78 !important;
    }

===========================================