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

    font-size: 14px;
}

article .tei {
	display: block;
}

article .tei .text {
    display: block;
    line-height: 1.6;
    margin-bottom: 40px;
}

article .tei .text p {
    margin-top: 0;
    margin-bottom: 0;
    margin-block-start: 0;
    margin-block-end: 0;
}



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



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

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

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



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

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

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

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

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

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

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

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

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




/* Einfügung */
article .tei .text span.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 span.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 span.supplied {
    cursor: pointer;

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





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

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

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


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

article .tei .text span.choice span.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 span.choice span.abbr {
    background-color: #eee;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
}

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





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

article .tei .text span.ref[target]:focus,
article .tei .text span.ref[target]:hover {
    text-decoration: underline;
}

article .tei .text span.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 span.note.visible {
    display: block;
}

/* Ensure entity info that appears after a note has proper spacing */
article .tei .text span.note.visible + .entity-inline-info {

}

/* Apply border-left to the ref if its following note is visible */
article .tei .text span.ref[target]:has(+ span.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 span.ref[target]::after,
article .tei .text span.note::after,
article .tei .text span.persName::after,
article .tei .text span.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 span.persName,
article .tei .text span.title,
article .tei .text span.event,
article .tei .text span.placeName[type="site"],
article .tei .text span.placeName[type="city"] {
    cursor: pointer;
    position: relative;
    background-color: rgba(0, 0, 0, 0.1);
}


/* Hover state for entities */
article .tei .text span.persName[key]:hover,
article .tei .text span.placeName[key]:hover,
article .tei .text span.title[key]:hover,
article .tei .text span.event[key]:hover {
    text-decoration: underline;
}

/* Active/selected entity state */
.entity-active {
    background-color: rgba(0, 123, 255, 0.1);
}

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

.entity-nested::before {
    content: "";
    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 #2d5016;
    background: #f5f5f5;
    border-radius: 4px;
}

.entity-section__header-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.entity-section__header {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    color: #2d5016;
    flex: 1;
}

.entity-detail-btn {
    padding: 4px 8px;
    background: #2d5016;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: all 0.2s;
    margin-left: 8px;
}

.entity-detail-btn:hover {
    background: #1a2f0d;
    transform: scale(1.05);
}

.entity-detail-btn:focus {
    outline: 2px solid #2d5016;
    outline-offset: 2px;
}

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

/* Entity type colors - all use dark green */
.entity-section--person {
    border-color: #2d5016;
}

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

/* 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);
    }
}

/* ========================================
   INLINE ENTITY DISPLAY MODE
   ======================================== */

/* Hide sidebar when in inline mode */
.tei-viewer--inline .tei-viewer__entity-sidebar {
    display: none;
}

/* Inline entity information container - styled like note/comment */
.entity-inline-info {
    display: block;
    background-color: #f5f5f5;
    border-top: 1px solid #2d5016;
    border-bottom: 1px solid #2d5016;
    padding: 10px;
    font-size: 1rem;
    color: #111;
    float: inline-start;
    clear: both;
    width: 100%;
    box-sizing: border-box;
    border-radius: 0;
    position: relative;
}

/* Close button for inline entity info */
.entity-inline-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    padding: 0;
    background: #2d5016;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
    font-weight: bold;
}

.entity-inline-close:hover {
    background: #1a2f0d;
    transform: scale(1.1);
}

/* Entity list container within inline info */
.entity-inline-list {
    display: block;
    margin: 0;
    padding: 0;
}

/* Adjust entity sections in inline mode - compact inline-block layout */
.entity-inline-info .entity-section {
    display: inline-block;
    vertical-align: top;
    margin-right: 16px;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #f5f5f5;
    border-radius: 4px;
    border: 1px solid #2d5016;
    min-width: 150px;
    max-width: 100%;
}

.entity-inline-info .entity-section:last-child {
    margin-right: 0;
}

.entity-inline-info .entity-section__header-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.entity-inline-info .entity-section__header {
    font-size: 0.75rem;
    font-weight: 600;
    color: #2d5016;
    margin: 0;
    padding: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    flex: 1;
}

.entity-inline-info .entity-detail-btn {
    padding: 2px 6px;
    background: #2d5016;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    transition: all 0.2s;
    margin-left: 6px;
}

.entity-inline-info .entity-detail-btn:hover {
    background: #1a2f0d;
    transform: scale(1.05);
}

.entity-inline-info .entity-detail-btn:focus {
    outline: 2px solid #2d5016;
    outline-offset: 2px;
}

.entity-inline-info .entity-section__content {
    padding: 0;
    margin: 0;
}

/* Entity type specific styling in inline mode - all use dark green */
.entity-inline-info .entity-section--person .entity-section__header {
    color: #2d5016;
}

.entity-inline-info .entity-section--person {
    border-color: #2d5016;
}

.entity-inline-info .entity-section--siteCity .entity-section__header,
.entity-inline-info .entity-section--site .entity-section__header {
    color: #2d5016;
}

.entity-inline-info .entity-section--siteCity,
.entity-inline-info .entity-section--site {
    border-color: #2d5016;
}

.entity-inline-info .entity-section--work .entity-section__header {
    color: #2d5016;
}

.entity-inline-info .entity-section--work {
    border-color: #2d5016;
}

.entity-inline-info .entity-section--event .entity-section__header {
    color: #2d5016;
}

.entity-inline-info .entity-section--event {
    border-color: #2d5016;
}

/* Highlight clicked entity in inline mode - light gray background without border/underline */
.tei-viewer--inline .entity-active {
    background: #f5f5f5;
    cursor: pointer;
}

/* Loading and error states in inline mode */
.entity-inline-info .entity-loading {
    padding: 4px 0;
    color: #666;
    font-style: italic;
    font-size: 0.9rem;
}

.entity-inline-info .entity-error {
    background: #ffebee;
    padding: 8px;
    border-radius: 4px;
}

.entity-inline-info .entity-error__message {
    margin: 0 0 6px 0;
    color: #c62828;
    font-size: 0.85rem;
}

.entity-inline-info .entity-retry {
    padding: 4px 10px;
    background: #d32f2f;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: background-color 0.2s;
}

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

.entity-inline-info .entity-label {
    margin: 0;
    font-weight: 400;
    color: #333;
    line-height: 1.4;
    font-size: 0.9rem;
}

.entity-inline-info .entity-no-data {
    margin: 0;
    color: #999;
    font-style: italic;
    font-size: 0.85rem;
}

/* Responsive inline mode */
@media (max-width: 768px) {
    .entity-inline-info {
        margin: 3px 0 10px;
        padding: 10px 12px;
        font-size: 0.95rem;
    }

    .entity-inline-info .entity-section {
        display: block;
        margin-right: 0;
        margin-bottom: 8px;
        max-width: 100%;
    }

    .entity-inline-info .entity-section:last-child {
        margin-bottom: 0;
    }

    .entity-inline-info .entity-section__header {
        font-size: 0.7rem;
    }

    .entity-inline-close {
        width: 22px;
        height: 22px;
        font-size: 18px;
        top: 6px;
        right: 6px;
    }
}
