* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: #f0ebe5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 14px 40px;
}

/* ── Language Switcher (top-right) ── */
.language-switcher {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    gap: 4px;
}

.lang-btn {
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    opacity: 0.55;
    transition: opacity 0.2s;
    overflow: hidden;
}

.lang-btn:hover, .lang-btn.active {
    opacity: 1;
}

.flag {
    display: inline-block;
    width: 24px;
    height: 24px;
    background-image: url('https://safer-nightlife.berlin/wp-content/plugins/weglot/dist/images/circular_flag.png');
    background-size: auto 24px;
    background-repeat: no-repeat;
    border-radius: 50%;
}

.flag-de { background-position: -1488px 0; }
.flag-en { background-position: -2520px 0; }

.page-wrapper {
    display: flex;
    flex-direction: column;
}

.table-page-header {
    text-align: center;
    padding: 6px 0 4px;
}

.table-page-title {
    font-family: 'Poppins', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    color: #1a1a1a;
    margin: 0 0 2px;
    text-transform: uppercase;
}

.table-page-notice {
    font-family: 'Poppins', sans-serif;
    font-size: 0.75rem;
    color: #555;
    margin: 0;
    font-style: italic;
    letter-spacing: 0.1px;
}

.logo-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    /* width & margin-left set dynamically by JS to align with data cells */
}

.logo-tripsit-link {
    display: block;
    transition: opacity 0.2s;
}

.logo-tripsit-link:hover {
    opacity: 0.75;
}

.logo-tripsit {
    height: 50px;
    width: auto;
    opacity: 0.85;
}

.logo-sonar-link {
    display: block;
    transition: opacity 0.2s;
}

.logo-sonar-link:hover {
    opacity: 0.75;
}

.logo-sonar {
    height: 50px;
    width: auto;
}

.logo-berlin-link {
    display: block;
    transition: opacity 0.2s;
}

.logo-berlin-link:hover {
    opacity: 0.75;
}

.logo-berlin {
    height: 42px;
    width: auto;
    opacity: 0.85;
}

body.edit-mode-active {
    padding-bottom: 80px;
}

.container {
    display: flex;
    gap: 28px;
    align-items: stretch;
    position: relative;
    z-index: 1;
}

.table-wrapper {
    position: relative;
    overflow: visible;
}

table {
    border-collapse: separate;
    border-spacing: 4px;
}

/* Column headers (rotated) */
thead th {
    height: 105px;
    width: 46px;
    vertical-align: bottom;
    padding-bottom: 8px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    position: relative;
}

thead th .col-label {
    display: block;
    transform: rotate(-50deg);
    transform-origin: bottom left;
    white-space: nowrap;
    position: absolute;
    bottom: 10px;
    left: 50%;
}

/* Row headers */
tbody th {
    text-align: right;
    padding-right: 10px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* Data cells */
td {
    width: 46px;
    height: 46px;
    text-align: center;
    vertical-align: middle;
    border-radius: 6px;
    font-size: 22px;
    line-height: 46px;
    transition: transform 0.1s ease;
}

td:hover {
    transform: scale(1.15);
    z-index: 10;
    position: relative;
}

td.cell-active {
    background: #00c9b7;
    color: #000;
    cursor: default;
}

td.cell-double-warn {
    font-size: 22px;
    letter-spacing: -2px;
}

td.cell-same {
    background: #e0dad4;
    color: #999;
    font-size: 18px;
}

td.cell-unknown {
    background: #d4cfca;
    color: #666;
    font-size: 14px;
}

/* Legend */
.legend {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-top: 0;
    max-width: 263px;
}

/* Sonar logo above legend */
.deco-sonar-link {
    align-self: flex-end;
    width: 70%;
    cursor: pointer;
    transition: opacity 0.2s;
    display: block;
}

.deco-sonar-link:hover {
    opacity: 0.75;
}

.deco-sonar {
    width: 100%;
    display: block;
}

.legend-item {
    display: flex;
    flex-direction: column;
    gap: 0px;
}

.legend-item .legend-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-item .legend-icon {
    font-size: 26px;
    width: 34px;
    text-align: center;
    flex-shrink: 0;
}

.legend-item .legend-icon-double {
    font-size: 26px;
    letter-spacing: -4px;
}

.legend-item .legend-title {
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.legend-item .legend-description {
    font-size: 10px;
    font-weight: 400;
    color: #333;
    line-height: 1.45;
    padding-left: 42px;
    max-width: 253px;
    margin-top: -4px;
}

.legend-footer {
    font-weight: 700;
    font-size: 10.5px;
    text-transform: uppercase;
    color: #c0392b;
    margin-top: 7px;
    letter-spacing: 0.3px;
    text-align: center;
}

/* Decorative overlays */
.deco-title-link {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}

.deco-title-link:hover {
    opacity: 0.85;
}

.deco-title {
    pointer-events: none;
}

.deco-title img {
    width: 300px;
    display: block;
}

.deco-title h1 {
    position: absolute;
    top: 18px;
    left: 22px;
    font-family: 'Poppins', sans-serif;
    font-weight: 900;
    font-size: 52px;
    line-height: 1.0;
    text-transform: uppercase;
    color: #111;
    letter-spacing: -1px;
}

.deco-drug1 {
    position: absolute;
    right: calc(100% - 80px);
    bottom: 2%;
    width: 360px;
    opacity: 0.85;
    pointer-events: none;
}

.deco-drug2 {
    position: absolute;
    right: calc(100% - 80px);
    top: 22%;
    width: 300px;
    opacity: 0.8;
    pointer-events: none;
}

/* QR code bottom-left */
.deco-qr-link {
    position: fixed;
    bottom: 18px;
    left: 22px;
    z-index: 2;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.2s;
}

.deco-qr-link:hover {
    opacity: 0.75;
}

.deco-qr {
}

.deco-qr img {
    width: 90px;
    display: block;
}

.legend-entries {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    width: 100%;
    gap: 8px;
}

@media screen and (max-width: 900px) {
    .deco-title, .deco-title-link, .deco-qr, .deco-qr-link, .deco-sonar, .deco-sonar-link, .deco-drug1, .deco-drug2 {
        display: none;
    }
}

/* Loading state */
.loading {
    font-size: 18px;
    color: #666;
    text-align: center;
    padding: 60px;
}

/* ── Custom Tooltip ── */
.custom-tooltip {
    position: fixed;
    z-index: 9999;
    background: #2c3e50;
    color: #fff;
    font-family: 'Poppins', sans-serif;
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.5;
    padding: 8px 14px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    max-width: 260px;
    white-space: normal;
    text-align: center;
}

.custom-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Rich combo tooltip ── */
.custom-tooltip.combo-tooltip {
    max-width: 360px;
    padding: 0;
    background: #fff;
    color: #333;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.22);
    text-align: left;
    overflow: hidden;
}

.tt-title {
    background: #2c3e50;
    color: #fff;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.3px;
}

.tt-name {
    font-weight: 700;
}

.tt-sep {
    margin: 0 6px;
    opacity: 0.6;
    font-weight: 300;
}

.tt-badges {
    display: flex;
    gap: 6px;
    padding: 10px 14px 4px;
}

.tt-badge {
    flex: 1;
    padding: 5px 8px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.tt-desc {
    padding: 8px 14px 12px;
    font-size: 0.75rem;
    line-height: 1.55;
    color: #444;
}

.tt-nodata {
    padding: 12px 16px;
    font-size: 0.8rem;
    color: #999;
    text-align: center;
    font-style: italic;
}

/* Reuse risk/interaction badge colors */
.tt-badge.risk-low { background: #e9ecef; color: #495057; }
.tt-badge.risk-caution { background: #fff3cd; color: #856404; }
.tt-badge.risk-unsafe { background: #fff4e6; color: #e65100; }
.tt-badge.risk-deadly { background: #ffcdd2; color: #b71c1c; }
.tt-badge.interaction-synergistic { background: #d4edfc; color: #0277bd; }
.tt-badge.interaction-counteracting { background: #dfe6e9; color: #2d3436; }
.tt-badge.interaction-neutral { background: #e3f2fd; color: #1565c0; }
.tt-badge.interaction-complex { background: #e1d5e7; color: #6a1b9a; }
.tt-badge.interaction-unknown { background: #f5f5f5; color: #757575; }

/* ===== MOBILE: Compact table (Approach B) ===== */
@media screen and (max-width: 900px) {
    body {
        padding: 12px 4px;
        align-items: flex-start;
    }

    .container {
        flex-direction: column;
        gap: 16px;
        width: 100%;
    }

    .table-page-header {
        padding: 0 0 0;
    }

    .table-page-title {
        font-size: 0.85rem;
        margin: 0 0 1px;
    }

    .table-page-notice {
        font-size: 0.6rem;
        margin: 0 0 2px;
    }

    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    table {
        border-spacing: 2px;
        margin: 0 auto;
    }

    thead th {
        height: 50px;
        width: 30px;
        padding-bottom: 4px;
        font-size: 9px;
    }

    thead th .col-label {
        font-size: 9px;
        bottom: 6px;
    }

    tbody th {
        font-size: 9px;
        padding-right: 6px;
        letter-spacing: 0;
    }

    td {
        width: 30px;
        height: 30px;
        font-size: 14px;
        line-height: 30px;
        border-radius: 4px;
    }

    td:hover {
        transform: none;
        z-index: auto;
        position: static;
    }

    td.cell-double-warn {
        font-size: 13px;
        letter-spacing: -3px;
    }

    td.cell-same {
        font-size: 12px;
    }

    td.cell-unknown {
        font-size: 10px;
    }

    /* Legend below table */
    .legend {
        padding-top: 0;
        max-width: 100%;
        gap: 12px;
    }

    .logo-bar {
        gap: 8px;
    }

    .logo-tripsit {
        height: 30px;
    }

    .logo-sonar {
        height: 30px;
    }

    .logo-berlin {
        height: 24px;
    }

    .legend-item .legend-icon {
        font-size: 16px;
        width: 24px;
    }

    .legend-item .legend-icon-double {
        font-size: 16px;
    }

    .legend-item .legend-title {
        font-size: 10px;
    }

    .legend-item .legend-description {
        font-size: 9px;
        padding-left: 34px;
        max-width: 100%;
    }

    .legend-footer {
        font-size: 9px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   EDIT MODE
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Bottom bar ── */
.edit-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: #2c3e50;
    color: #fff;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    animation: editBarSlideUp 0.25s ease-out;
}

@keyframes editBarSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.edit-bar-label {
    font-size: 0.9rem;
    font-weight: 600;
    margin-right: 8px;
}

.edit-bar-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Poppins', sans-serif;
}

.edit-bar-btn:hover {
    transform: translateY(-1px);
}

.edit-bar-btn-primary {
    background: #1c6f75;
    color: #fff;
}

.edit-bar-btn-primary:hover {
    background: #17595e;
}

.edit-bar-btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
}

.edit-bar-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ── Editable hint on row headers (non-edit mode) ── */
tbody th.editable-hint {
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border-radius: 4px;
}

tbody th.editable-hint:hover {
    background: rgba(28, 111, 117, 0.1);
    color: #1c6f75;
}

/* ── Row header in edit mode ── */
.edit-row-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 8px !important;
    white-space: nowrap;
    text-align: right;
    justify-content: flex-end;
}

.edit-row-name {
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}

.edit-row-name:hover {
    background: #1c6f75;
    color: #fff;
}

/* ── Delete button ── */
.edit-delete-btn {
    background: none;
    border: none;
    color: #c0392b;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

.edit-delete-btn:hover {
    background: #c0392b;
    color: #fff;
}

.edit-delete-btn.disabled {
    color: #ccc;
    cursor: not-allowed;
}

.edit-delete-btn.disabled:hover {
    background: none;
    color: #ccc;
}

/* ── Add button (bottom of table) ── */
.edit-add-row th {
    text-align: right;
    padding-right: 12px;
}

.edit-add-btn {
    background: #1c6f75;
    color: #fff;
    border: none;
    font-size: 20px;
    font-weight: 700;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    font-family: 'Poppins', sans-serif;
    padding: 0;
}

.edit-add-btn:hover {
    background: #17595e;
    transform: scale(1.1);
}

.cell-placeholder {
    background: transparent;
    border: 2px dashed #ccc;
    border-radius: 6px;
    width: 46px;
    height: 46px;
}

/* ── Inline autocomplete ── */
.edit-input-cell {
    padding: 0 !important;
    position: relative;
}

.table-autocomplete-wrapper {
    position: relative;
    width: 100%;
    min-width: 140px;
}

.table-substance-input {
    width: 100%;
    padding: 6px 10px;
    font-family: 'Poppins', sans-serif;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border: 2px solid #1c6f75;
    border-radius: 6px;
    outline: none;
    background: #fff;
    color: #111;
    box-sizing: border-box;
}

.table-substance-input:focus {
    border-color: #00c9b7;
    box-shadow: 0 0 0 3px rgba(0, 201, 183, 0.2);
}

.table-substance-input::placeholder {
    text-transform: none;
    font-weight: 400;
    color: #999;
}

.table-suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 2px solid #1c6f75;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
}

.table-suggestions-list.visible {
    display: block;
}

/* Flip dropdown upward when near bottom of viewport */
.table-suggestions-list.flip-up {
    top: auto;
    bottom: 100%;
    border-top: 2px solid #1c6f75;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
}

.table-suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.table-suggestion-item:last-child {
    border-bottom: none;
}

.table-suggestion-item:hover {
    background: #f5f0ec;
}

.table-suggestion-item.active {
    background: #1c6f75;
    color: #fff;
}

.table-suggestion-main {
    font-weight: 600;
    font-size: 0.85rem;
    color: #000;
}

.table-suggestion-item.active .table-suggestion-main {
    color: #fff;
}

.table-suggestion-alias {
    font-size: 0.75rem;
    color: #888;
}

.table-suggestion-item.active .table-suggestion-alias {
    color: rgba(255, 255, 255, 0.8);
}

.table-no-suggestions {
    padding: 10px 12px;
    color: #999;
    font-size: 0.8rem;
    text-align: center;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   EDIT MODE – Mobile
   ═══════════════════════════════════════════════════════════════════════════════ */

@media screen and (max-width: 900px) {
    body.edit-mode-active {
        padding-bottom: 100px;
    }

    .edit-bar {
        padding: 10px 12px;
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .edit-bar-label {
        font-size: 0.78rem;
        width: 100%;
        text-align: center;
        margin-right: 0;
        margin-bottom: 2px;
    }

    .edit-bar-btn {
        font-size: 0.78rem;
        padding: 6px 14px;
    }

    .edit-row-name {
        font-size: 9px;
    }

    .edit-delete-btn {
        font-size: 14px;
        width: 20px;
        height: 20px;
        line-height: 20px;
    }

    .edit-add-btn {
        width: 26px;
        height: 26px;
        line-height: 26px;
        font-size: 16px;
    }

    .cell-placeholder {
        width: 30px;
        height: 30px;
        border-width: 1px;
        border-radius: 4px;
    }

    .table-autocomplete-wrapper {
        min-width: 100px;
    }

    .table-substance-input {
        font-size: 10px;
        padding: 4px 6px;
    }

    .table-suggestion-item {
        padding: 6px 8px;
    }

    .table-suggestion-main {
        font-size: 0.75rem;
    }

    .table-suggestion-alias {
        font-size: 0.65rem;
    }
}
