/*
 * Base styling for TEI elements
 * Design & Copyright by Tobias Holstein, Darmstadt
*/
article {
    display: block;
    background-color: #ffffff;

    padding: 20px;
}

article .tei {
	display: block;
}

article .tei .text {
    display: block;
    line-height: 1.6;
    overflow: auto;
}


/**
 * TODO
 */
article .tei .text::selection,
article .tei .text p::selection {
  background: #FFE500;
  color: #121212;
}



/* Schriftart: Latein */
article .tei .text hi[rend="latintype"] {
    font-family: "Times New Roman", serif;
}

/* Schriftart: Maschinenschrift */
article .tei .text hi[rend="printtype"] {
    font-family: "Courier New", "Monaco", monospace;
}

/* Schriftart: Kurrent */
article .tei .text hi[rend="kurrenttype"] {
    font-family: "Arial", "Helvetica", sans-serif;
}



/* Schriftbild: Fett */
article .tei .text hi[rend="bold"] {
    font-weight: bolder;
}

/* Schriftbild: Kursiv */
article .tei .text hi[rend="italic"] {
    font-style: italic;
}

/* Schriftbild: Kursiv */
article .tei .text hi[rend="spaced_out"] {
    letter-spacing: 0.5em;
}

/* Schriftbild: Unterstrichen */
article .tei .text hi[rend="underline"] {
    text-decoration-line: underline;
    text-decoration-style: solid;
}

/* Schriftbild: Doppelt Unterstrichen */
article .tei .text hi[rend="double_underline"] {
    text-decoration-line: underline;
    text-decoration-style: double;
}

/* Schriftbild: Durchgestrichen */
article .tei .text hi[rend="strikethrough"] {
    text-decoration-line: line-through;
}

/* Schriftbild: Doppelt Durchgestrichen */
article .tei .text hi[rend="double_strikethrough"] {
    text-decoration: line-through;
    text-decoration-style: double;
}

/* Schriftbild: Hochgestellt */
article .tei .text hi[rend="superscript"] {
    vertical-align: super;
}

/* Schriftbild: Tiefgestellt */
article .tei .text hi[rend="subscript"] {
    vertical-align: sub;
}



/* Styling for different entities in the text */
article .tei .text persName {
    color: #FF6347;
    cursor: pointer;
}

article .tei .text placeName[type="site"],
article .tei .text placeName[type="city"] {
    color: #4682B4;
    cursor: pointer;
}

article .tei .text title {
    color: #4682B4;
    cursor: pointer;
}

article .tei .text event {
    color: #4682B4;
    cursor: pointer;
}


/* Einfügung */
article .tei .text add[placement] {
    color: #6a1b9a; /* Dark purple text */
    cursor: pointer;

    padding: 0 4px; /* top and bottom | left and right */

    background-color: #eee;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;

    border-radius: 3px;
    display: inline-block;
    position: relative;
}

article .tei .text add[placement]:hover::after {
    content: "Einfügung: " attr(placement);

    position: absolute;
    bottom: -100%;
    left: 50%;
    transform: translateX(-50%);

    background-color: #6a1b9a;
    color: #fff;
    padding: 4px 8px;
    border-radius: 3px;
    white-space: nowrap;
    font-size: 0.8rem;
    opacity: 1;
    visibility: visible;
}




/*
 * Ergänzung im Text
 * <supplied>Ergänzung</supplied>
 */
article .tei .text supplied {
    cursor: pointer;

    background-color: #eee;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
}
article .tei .text supplied:before {
    content: "<";
}
article .tei .text supplied:after {
    content: ">";
}





/*
 * Damage
 * <damage agent="other"><unclear>Schade<supplied>n</supplied></unclear></damage>
 */
article .tei .text damage {
    cursor: pointer;
}
article .tei .text damage unclear {
    display: inline;
}

article .tei .text damage unclear supplied {
    text-decoration: underline;
    font-style: italic; /* Italics for supplied content */
}

article .tei .text damage unclear supplied:before,
article .tei .text damage unclear supplied:after {
    content: "";
}


/**
 * Abkürzung
 * <choice><expan>von</expan><abbr>v.</abbr></choice>
 */
article .tei .text choice {
    position: relative; /* Needed for positioning the tooltip */
    cursor: pointer;
}

article .tei .text choice expan {
    display: none;

    max-width: 300px;
    width: max-content;

    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);

    border-radius: 3px;

    background-color: #eee;
    border: 1px solid #ccc;
    padding: 5px;
    z-index: 1;
}

article .tei .text choice abbr {
    background-color: #eee;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
}

/* Show expan on hover */
article .tei .text choice:hover > expan {
    display: block;
}





/* Einzelstellenkommentar */
article .tei .text ref[target] {
    color: #007BFF;
    text-decoration: none;
    cursor: pointer;
}

article .tei .text ref[target]:focus,
article .tei .text ref[target]:hover {
    background-color: #f1f1f1;
}

article .tei .text note {
    display: none;
    background-color: #f8f8f8;
    border-top: 1px solid #007BFF;
    border-bottom: 1px solid #007BFF;
    padding: 10px;
    margin: 2px 0 10px;
    font-size: 1rem;
    color: #111;
	float: inline-start;
    clear: both;
    width: 100%;
    box-sizing: border-box;
}

article .tei .text note.visible {
    display: block;
}

/* Apply border-left to the ref if its following note is visible */
article .tei .text ref[target]:has(+ note.visible) {
    text-decoration: underline;
    text-decoration-thickness: 4px;
    text-underline-position: under;
    text-underline-offset: 3px;
    text-decoration-color: #007BFF;
}



/* Add a space after certain inline tags */
article .tei .text ref[target]::after,
article .tei .text note::after,
article .tei .text persName::after,
article .tei .text placeName::after {
    content: " "; /* Adds a space after the element */
}





/* Styling for additional information area */
.additional-info {
    margin-top: 20px;
    padding: 10px;
    border-top: 2px solid #ddd;
    font-size: 0.9rem;
    color: #333;
    display: none; /* Hidden by default */
}


/* Tooltip box for additional information */
.info-box {
    position: absolute;
    background-color: #f8f8f8;
    padding: 10px;
    border: 1px solid #ddd;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    display: none;
    z-index: 1000;
    max-width: 200px;
}


/* ========== Entity Interactions ========== */

/* Clickable entity elements */
article .tei .text persName[key],
article .tei .text placeName[key],
article .tei .text title[key],
article .tei .text event[key] {
    cursor: pointer;
    position: relative;
}

/* Hover state for entities */
article .tei .text persName[key]:hover,
article .tei .text placeName[key]:hover,
article .tei .text title[key]:hover,
article .tei .text event[key]:hover {
    text-decoration: underline;
    background-color: rgba(255, 255, 0, 0.2);
}

/* Active/selected entity state */
.entity-active {
    outline: 2px solid #007BFF;
    outline-offset: 2px;
    background-color: rgba(0, 123, 255, 0.1);
}

/* Nested entity indicator */
.entity-nested {
    position: relative;
}

.entity-nested::before {
    content: "";
    position: absolute;
    left: -3px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: currentColor;
    opacity: 0.3;
}

/* ========== Entity Sidebar ========== */

.tei-viewer__entity-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: 320px;
    height: 100%;
    background: #ffffff;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 1001;
    overflow-y: auto;
}

.tei-viewer__entity-sidebar.visible {
    transform: translateX(0);
}

.sidebar__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #f5f5f5;
    position: sticky;
    top: 0;
    z-index: 10;
}

.sidebar__title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.sidebar__close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.sidebar__close:hover {
    background-color: #e0e0e0;
    color: #333;
}

.sidebar__content {
    padding: 16px;
}

/* Entity sections in sidebar */
.entity-section {
    margin: 12px 0;
    padding: 12px;
    border-left: 3px solid;
    background: #fafafa;
    border-radius: 4px;
}

.entity-section__header {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    color: #555;
}

.entity-section__content {
    font-size: 14px;
    line-height: 1.5;
}

/* Entity type colors */
.entity-section--person {
    border-color: #FF6347;
}

.entity-section--siteCity,
.entity-section--site,
.entity-section--work,
.entity-section--event {
    border-color: #4682B4;
}

/* Entity states */
.entity-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
}

.entity-loading::after {
    content: "⟳";
    display: inline-block;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.entity-error {
    border-color: #d32f2f !important;
    background: #ffebee !important;
}

.entity-error__message {
    margin: 0 0 8px 0;
    color: #c62828;
    font-size: 13px;
}

.entity-retry {
    padding: 6px 12px;
    background: #d32f2f;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.entity-retry:hover {
    background: #b71c1c;
}

.entity-label {
    margin: 0;
    font-weight: 500;
    color: #333;
}

.entity-no-data {
    margin: 0;
    color: #999;
    font-style: italic;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .tei-viewer__entity-sidebar {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 50vh;
        transform: translateY(100%);
    }

    .tei-viewer__entity-sidebar.visible {
        transform: translateY(0);
    }
}

