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

body {
    font-family: Arial, sans-serif;
    display: flex;
    height: 100vh;
    background: #f5f5f5;
}

#sidebar {
    width: 350px;
    background: #f5f5f5;
    color: #2d3748;
    border-right: 1px solid #e2e0e5;
    padding: 25px 20px;
    overflow-y: auto;
    position: relative;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

#sidebar.collapsed {
    width: 0;
    padding: 0;
    overflow: hidden;
}

#sidebar-toggle {
    position: absolute;
    top: 20px;
    right: 25px;
    background: transparent;
    border: none;
    color: #4a5568;
    cursor: pointer;
    z-index: 10;
    padding: 5px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

#sidebar-toggle:hover {
    transform: scale(1.2);
}

#sidebar.collapsed #sidebar-toggle {
    display: none;
}

#expand-button {
    position: fixed;
    top: 20px;
    left: 20px;
    background: #7b2d8e;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    z-index: 100;
    display: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#expand-button:hover {
    background: #5c1a6e;

    transform: scale(1.1);
}

#expand-button.visible {
    display: block;
}

#home-button {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    color: #7b2d8e;
    border: 1px solid #7b2d8e;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    z-index: 100;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#home-button:hover {
    background: rgba(123, 45, 142, 0.08);
    transform: scale(1.1);
}

/* Oculta el home-button quan el sidebar està obert */
body:has(#sidebar:not(.collapsed)) #home-button {
    display: none;
}

h2 {
    font-weight:normal;
}

#sidebar h2 {
    margin-bottom: 25px;
    flex-shrink: 0;
    font-size: 1.1rem;
    font-weight: 300;
    letter-spacing: 1px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e2e0e5;
}

.sep{
    font-weight: lighter;
    line-height: 0;
    vertical-align: -0.1em;
    margin: 0 0.2em;
}

#sidebar ul {
    list-style: none;
}

#sidebar > ul#documents-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 0;
}

#sidebar .document-item {
    margin-bottom: 2px;
}

#sidebar .document-header {
    padding: 11px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
    border-left: 3px solid transparent;
}

#sidebar .document-header:hover {
    background: rgba(123, 45, 142, 0.15);
    border-left-color: rgba(123, 45, 142, 0.4);
}

#sidebar .document-item.active-document > .document-header {
    background: rgba(123, 45, 142, 0.2);
    border-left-color: #7b2d8e;
}

#sidebar .document-icon {
    width: 20px;
    color: #7b2d8e;
    font-size: 0.85rem;
    opacity: 0.5;
}

#sidebar .document-name {
    flex: 1;
    font-weight: 400;
    font-size: 0.95rem;
    letter-spacing: 0.3px;
}

#sidebar .toggle-icon {
    transition: transform 0.3s;
}

#sidebar .document-item.expanded .toggle-icon {
    transform: rotate(180deg);
}

#sidebar .pages-list {
    list-style: none;
    margin-left: 15px;
    margin-top: 5px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    border-left: 1px solid #e2e0e5;
    padding-left: 10px;
}

#sidebar .document-item.expanded .pages-list {
    max-height: 2000px;
    transition: max-height 0.5s ease-in;
}

#sidebar .page-item {
    margin-bottom: 2px;
    padding: 7px 10px;
    border-radius: 5px;
    transition: all 0.25s ease;
}

#sidebar .page-item:hover {
    background: rgba(123, 45, 142, 0.08);
}

#sidebar .page-item.active {
    background: rgba(123, 45, 142, 0.18);
}

#sidebar .file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #4a5568;
    font-size: 0.9rem;
}

#sidebar .file-name {
    flex: 1;
}

#sidebar .file-icons {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

#sidebar .file-icons i {
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.3s;
    padding: 4px;
}

#sidebar .file-icons i:hover {
    opacity: 1;
    transform: scale(1.2);
}

#sidebar .file-icons .fa-file-lines {
    color: #7b2d8e;
    opacity: 0.5;
}

#sidebar .file-icons .fa-scroll {
    color: #7b2d8e;
    opacity: 0.4;
}

#sidebar .share-button {
    display: block;
    background: rgba(123, 45, 142, 0.06);
    color: #4a5568;
    padding: 12px 20px;
    margin: 20px 0 0 0;
    margin-top: auto;
    border-radius: 8px;
    text-decoration: none;
    text-align: center;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    border: 1px solid #e2e0e5;
    flex-shrink: 0;
}

#sidebar .share-button:hover {
    background: rgba(123, 45, 142, 0.1);
    color: #2d3748;
    border-color: rgba(123, 45, 142, 0.3);
}

#sidebar .share-button i {
    margin-right: 8px;
    font-size: 1.1rem;
}

#main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

#content {
    background: #fff;
    position: relative;
    padding: 50px;
    width: 794px;
    max-width: 100%;
    min-height: 1000px;
    margin: 20px auto;
    border-radius: 10px;
    flex-shrink: 0;
    box-sizing: border-box;
}

#content:has(.cover-container) {
    min-height: auto;
    height: calc(100vh - 140px);
    max-height: calc(100vh - 140px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
}

#editor-frame {
    width: 100%;
    min-height: 100%;
}

#editor-frame:has(.cover-container) {
    min-height: auto;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#editor-frame body,
#editor-frame {
    font-family: Georgia, serif;
    line-height: 1.8;
}

#editor-frame h1 {
    text-align: center;
    margin-bottom: 30px;
}

#editor-frame .correction {
    background-color: #ffcccc;
    padding: 2px 4px;
    border-radius: 3px;
}

body.edit-mode #editor-frame .correction {
    cursor: pointer;
}

#editor-frame .unclear {
    background-color: #cce5ff;
    padding: 2px 4px;
    border-radius: 3px;
}

body.edit-mode #editor-frame .unclear {
    cursor: pointer;
}

#editor-frame .page-number {
    text-align: right;
    font-style: italic;
}

#editor-frame .section-title {
    text-align: center;
    font-weight: bold;
    margin: 20px 0;
}

#editor-frame .circled {
    border: 2px solid #000;
    padding: 5px 10px;
    display: table;
    margin: 10px auto;
}

body.edit-mode #editor-frame p,
body.edit-mode #editor-frame h1,
body.edit-mode #editor-frame h2,
body.edit-mode #editor-frame h3,
body.edit-mode #editor-frame li {
    position: relative;
    padding: 5px;
    border-radius: 3px;
    transition: background-color 0.2s;
}

body.edit-mode #editor-frame p:hover,
body.edit-mode #editor-frame h1:hover,
body.edit-mode #editor-frame h2:hover,
body.edit-mode #editor-frame h3:hover,
body.edit-mode #editor-frame li:hover {
    background-color: #f0f0f0;
    cursor: text;
}

body.edit-mode #editor-frame .correction:hover {
    background-color: #ff9999 !important;
}

body.edit-mode #editor-frame .unclear:hover {
    background-color: #99ccff !important;
}

.editing {
    outline: 2px solid #7b2d8e !important;
    background-color: #f6f0f8 !important;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 30px;
    border-radius: 8px;
    width: 80%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-content h3 {
    margin-bottom: 20px;
}

.modal-content input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.modal-content button {
    padding: 10px 20px;
    margin: 5px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.btn-primary {
    background: #7b2d8e;
    color: white;
}

.btn-primary:hover {
    background: #5c1a6e;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 4px;
    color: white;
    display: none;
    z-index: 2000;
}

.notification.success {
    background: #27ae60;
}

.notification.error {
    background: #e74c3c;
}

.page-navigation {
    text-align: center;
    padding: 30px 0;
    border-top: 1px solid #ddd;
    margin: 0 auto 30px auto;
    width: 794px;
    max-width: 100%;
}

/* Page navigation visible en desktop, només s'oculta en mòbil quan el sidebar està desplegat */
@media (max-width: 768px) {
    body:has(#sidebar:not(.collapsed)) .page-navigation {
        display: none;
    }
}

.page-navigation a {
    display: inline-block;
    padding: 10px 20px;
    margin: 0 10px;
    background: #7b2d8e;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.3s;
    border: 1px solid #7b2d8e;
}

.page-navigation a:first-child:not(:last-child) {
    background: white;
    color: #7b2d8e;
    border: 1px solid #7b2d8e;
}

.page-navigation a:first-child:not(:last-child):hover {
    background: rgba(123, 45, 142, 0.08);
}

.page-navigation a:hover {
    background: #5c1a6e;
}

.page-navigation span {
    display: inline-block;
    padding: 10px 20px;
    margin: 0 10px;
    background: #bdc3c7;
    color: white;
    border-radius: 4px;
    opacity: 0.5;
    cursor: not-allowed;
}

.underline {
    text-decoration: underline;
}

hr { margin:15px 0px;}
ul#documents-list { margin:0px;}
ul {
    margin: 7px 0 7px 25px;
}

/* ===========================
   CLASSES SEMÀNTIQUES
   (substitueixen classes de Google Docs)
   =========================== */

/* Text estil */
.italic-text {
    font-style: italic;
}

.bold-text {
    font-weight: bold;
}

.underline-text {
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
}

.box-text {
    border: 1.5px solid #2d3748;
    padding: 7px;
    display: inline-block;
}

/* Alineació de text */
#editor-frame .centered,
#editor-frame .text-center {
    text-align: center;
}

#editor-frame .text-right {
    text-align: right;
}

#editor-frame .text-left {
    text-align: left;
}

#editor-frame .text-justify {
    text-align: justify;
}

/* Taula dues columnes */
#editor-frame .two-col-table {
    width: 100%;
    margin: 20px 0;
    border-collapse: collapse;
}

#editor-frame .two-col-table td {
    width: 50%;
    padding: 15px;
    vertical-align: top;
    text-align: justify;
    line-height: 1.8;
    font-size: 1.1rem;
    color: #2d3748;
}

/* Paràgrafs especials */
.empty-paragraph {
    height: 11pt;
    line-height: 1.3;
}

/* Container del document */
.document-container {
    background-color: transparent;
    max-width: 100%;
    padding: 0;
}

/* Taules */
.simple-table {
    border-spacing: 0;
    border-collapse: collapse;
    margin-right: auto;
    border: none !important;
}

.table-cell {
    border: none !important;
    padding: 5pt;
    vertical-align: top;
}

/* ===========================
   CLASSES LEGACY DE GOOGLE DOCS
   (mantingudes per compatibilitat)
   =========================== */

.c0{padding-top:0pt;padding-bottom:0pt;line-height:1.3;orphans:2;widows:2;text-align:justify;height:11pt}
.c1{color:#000000;font-weight:700;text-decoration:none;vertical-align:baseline;font-style:normal}
.c2{color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-style:italic}
.c3{font-weight:400}
.c4{color:#000000;text-decoration:none;vertical-align:baseline;font-style:normal}
.c5{padding-top:0pt;padding-bottom:0pt;line-height:1.3;orphans:2;widows:2;text-align:justify;margin-right:13.2pt}
.c6{text-decoration-skip-ink:none;-webkit-text-decoration-skip:none;text-decoration:underline}
.c7{border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:0pt;border-right-width:0pt;border-left-color:#000000;vertical-align:top;border-right-color:#000000;border-left-width:0pt;border-top-style:solid;border-left-style:solid;border-bottom-width:0pt;width:159pt;border-top-color:#000000;border-bottom-style:solid}
.c8{padding-top:0pt;padding-bottom:0pt;line-height:1.3;orphans:2;widows:2;text-align:center;margin-right:13.2pt}
.c9{padding-top:0pt;padding-bottom:0pt;line-height:1.5;text-align:left;margin-right:-1pt}
.c10{font-style:italic}
.c11{color:#000000;text-decoration:none;vertical-align:baseline;font-style:normal}
.c12{height:11pt}
.c13{padding-top:0pt;padding-bottom:0pt;line-height:1.3;orphans:2;widows:2;text-align:center;margin-right:13.2pt}
.c14{orphans:2;widows:2}
.c15{padding-top:0pt;padding-bottom:0pt;line-height:1.3;text-align:right;margin-right:13.2pt}
.c18{color:#000000;text-decoration:none;vertical-align:baseline;font-style:normal}
.c20{border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:0pt;border-right-width:0pt;border-left-color:#000000;vertical-align:top;border-right-color:#000000;border-left-width:0pt;border-top-style:solid;border-left-style:solid;border-bottom-width:0pt;width:52pt;border-top-color:#000000;border-bottom-style:solid}
.c22{padding-top:0pt;padding-bottom:0pt;line-height:1.3;text-align:left;margin-right:13.2pt}
.c26{border-spacing:0;border-collapse:collapse;margin-right:auto}
.c27{border-spacing:0;border-collapse:collapse;margin-right:auto}
.c30{padding-top:0pt;padding-bottom:0pt;line-height:1.3;text-align:left;margin-right:-1pt}
.c36{padding-top:0pt;padding-bottom:0pt;line-height:1.3;text-align:center;margin-right:12.7pt}
.c37{background-color:#ffffff;max-width:275.5pt;padding:72pt 72pt 72pt 72pt}
.c38{padding-top:0pt;padding-bottom:0pt;line-height:1.3;text-align:left;margin-right:13.2pt}
.c39{border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#000000;border-top-width:0pt;border-right-width:0pt;border-left-color:#000000;vertical-align:top;border-right-color:#000000;border-left-width:0pt;border-top-style:solid;border-left-style:solid;border-bottom-width:0pt;width:267.5pt;border-top-color:#000000;border-bottom-style:solid}
.c40{border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#ffffff;border-top-width:1pt;border-right-width:1pt;border-left-color:#ffffff;vertical-align:top;border-right-color:#ffffff;border-left-width:1pt;border-top-style:solid;border-left-style:solid;border-bottom-width:1pt;width:156pt;border-top-color:#ffffff;border-bottom-style:solid}
.c41{border-right-style:solid;padding:5pt 5pt 5pt 5pt;border-bottom-color:#ffffff;border-top-width:1pt;border-right-width:1pt;border-left-color:#ffffff;vertical-align:top;border-right-color:#ffffff;border-left-width:1pt;border-top-style:solid;border-left-style:solid;border-bottom-width:1pt;width:154.5pt;border-top-color:#ffffff;border-bottom-style:solid}

#editor-frame .c37 {
    background-color: transparent;
    max-width: 100%;
    padding: 0;
}

/* Oculta elements sense transcripció */
#sidebar .page-item.no-html {
    display: none;
}

/* Estils per a les portades dels documents */
.cover-container {
    text-align: center;
    max-width: 800px;
    min-height: auto;
    padding: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.cover-container h1 {
    font-size: 2.5rem;
    font-weight: 300;
    color: #2d3748;
    margin-bottom: 40px;
    line-height: 1.4;
}

.cover-container img {
    display: none;
}

/* Estils per a les pàgines de contingut */
#editor-frame {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    line-height: 1.8;
}

#editor-frame .page-number {
    position: absolute;
    top: 20px;
    right: 40px;
    font-size: 0.9rem;
    color: #718096;
    font-weight: 500;
}

#editor-frame h1 {
    font-size: 1.4rem;
    font-weight: 300;
    color: #2d3748;
    margin-bottom: 40px;
    margin-top: 0;
    line-height: 1.3;
    text-align: center;
    border-bottom: 2px solid #000;
    padding-bottom: 20px;
}

#editor-frame h2 {
    font-size: 1.4rem;
    font-weight: 400;
    color: #4a5568;
    margin-top: 40px;
    margin-bottom: 20px;
}

#editor-frame p {
    margin-bottom: 10px;
    color: #2d3748;
    font-size: 1.1rem;
    line-height: 1.8;
    text-align: justify;
}

#editor-frame u,
#editor-frame .underline,
#editor-frame .c6 {
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
}

#editor-frame ul {
    list-style: none;
    padding-left: 1.2em;
}

#editor-frame ul li::before {
    content: "–";
    position: absolute;
    left: -1.2em;
}

#editor-frame li {
    color: #2d3748;
    font-size: 1.1rem;
    line-height: 1.5;
    position: relative;
}

#editor-frame p.c0,
#editor-frame p.c5,
#editor-frame p.c8 {
    font-size: 1.1rem;
    line-height: 1.8;
}

#editor-frame span.c6,
#editor-frame span.c10 {
    font-weight: 600;
    color: #2d3748;
}

#editor-frame span.c1 {
    font-weight: 600;
    color: #2d3748;
}

#editor-frame span.c2,
#editor-frame span.c3,
#editor-frame span.c4 {
    color: #2d3748;
}

/* Taules */
#editor-frame table {
    width: 100%;
    margin: 30px 0;
    border-collapse: collapse;
    border: none !important;
}

#editor-frame table td {
    padding: 0px;
    vertical-align: top;
    border: none !important;
}

#editor-frame table tr {
    border: none !important;
}

#editor-frame table th {
    border: none !important;
}

#editor-frame table p {
    margin-bottom: 10px;
    font-size: 1.1rem;
    line-height: 1.8;
}

#editor-frame table p:last-child {
    margin-bottom: 0;
}

/* Cites i fragments destacats */
#editor-frame blockquote {
    border-left: 4px solid #000;
    padding-left: 20px;
    margin: 30px 0;
    font-style: italic;
    color: #4a5568;
}

#editor-frame .c8 {
    margin: 30px 0;
    font-style: italic;
    color: #4a5568;
}

/* Millores generals de llegibilitat */
#editor-frame strong,
#editor-frame b {
    font-weight: 600;
    color: #2d3748;
}

#editor-frame em,
#editor-frame i {
    font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
    }

    #content {
        padding: 10px 20px 80px 20px;
        margin: 0px auto;
        min-height: 100vh;
    }

    div#editor-frame table td p { font-size: inherit !important; text-align: justify}

    #editor-frame {
        padding: 60px 00px;
    }

    #editor-frame h1 {
        font-size: 2rem;
    }

    #editor-frame h2 {
        font-size: 1.5rem;
    }

    #editor-frame p {
        font-size: 1rem;
    }

    #editor-frame .page-number {
        top: 10px;
        right: 20px;
    }

    .cover-container {
        min-height: auto;
        justify-content: center;
        padding: 20px;
    }

    #content:has(.cover-container) {
        min-height: auto;
        height: calc(100vh);
        max-height: calc(100vh);
        margin: 0 auto;
        padding: 10px 20px;
    }

    .page-navigation {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        margin: 0;
        padding: 12px 15px;
        background: rgba(255, 255, 255, 0.98);
        border-top: 1px solid #ddd;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 50;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .page-navigation a,
    .page-navigation span {
        padding: 8px 15px;
        margin: 0;
        font-size: 0.9rem;
    }

    .page-navigation a:first-child:not(:last-child) {
        background: white;
        color: #7b2d8e;
        border: 1px solid #7b2d8e;
    }

    .page-navigation a:first-child:not(:last-child):hover {
        background: rgba(123, 45, 142, 0.08);
    }

    .page-navigation a:only-child {
        margin-left: auto;
    }
}

/* Mòbil apaisat */
@media (max-width: 768px) and (orientation: landscape) {
    .page-navigation {
        padding: 4px 10px;
        padding-bottom: max(4px, env(safe-area-inset-bottom));
        box-shadow: none;
        border-top: 1px solid #e0e0e0;
    }

    .page-navigation a,
    .page-navigation span {
        padding: 7px 18px;
        font-size: 0.8rem;
    }

    #content {
        padding-bottom: 40px;
    }
}

/* Forçar eliminació de borders en totes les taules */
table, table * {
    border: none !important;
}

#editor-frame table,
#editor-frame table *,
.simple-table,
.simple-table *,
table.c26,
table.c26 *,
table.c27,
table.c27 * {
    border: none !important;
    border-width: 0 !important;
    border-style: none !important;
}
