/* Login Overlay */
#login-overlay {
    position: fixed;
    inset: 0;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 1rem 0;
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.login-slogan {
    width: 100%;
    text-align: center;
    color: white;
    font-size: 1.8rem;
    font-weight: 300;
    margin-bottom: 2rem;
    padding: 0 1rem;
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 500px;
    position: relative;
}

.login-box h2 {
    color: var(--primary);
    margin-top: 0;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leitbild-link {
    font-size: 0.9rem;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    font-weight: normal;
}

.login-flex {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    margin-top: 1rem;
}

.login-logo {
    flex: 0 0 72px;
    width: 72px;
    max-width: 72px;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    border-right: 1px solid #eee;
    padding-right: 0.85rem;
    box-sizing: border-box;
}

.login-logo img {
    display: block;
    width: 100%;
    max-width: 72px;
    height: auto;
    object-fit: contain;
}

.login-fields {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.login-fields input {
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.login-instance-hint {
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.65rem;
    background: #f5f7fa;
    border-radius: 4px;
}

.login-instance-change {
    margin-left: 0.5rem;
    font-size: 0.8rem;
    color: var(--accent);
}

#instance-overlay {
    position: fixed;
    inset: 0;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

#instance-overlay.hidden {
    display: none;
}

#instance-url {
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.login-password-group {
    margin-bottom: 0.5rem;
    max-width: none;
}

.login-password-group input {
    margin-bottom: 0;
    padding-right: 2.5rem;
}

.login-fields button {
    width: 100%;
    padding: 0.8rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

#login-error {
  margin-top: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: left;
  white-space: pre-line;
}

#login-error.status-error {
  background: #fdecea;
  color: #5d4345;
  border: 1px solid #f5c2c0;
}

#login-error a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

/* Phones + tablets (iPad portrait ~768–834px): stack logo above fields.
   Side-by-side left too little room for demo <select>s in Safari. */
@media (max-width: 900px) {
    #login-overlay {
        justify-content: flex-start;
        padding-top: 0.5rem;
    }

    .login-slogan {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
    }
    
    .login-box {
        width: 92%;
        max-width: 520px;
        padding: 1rem 1rem 1.15rem;
        margin-bottom: 0.5rem;
        flex: 0 0 auto;
    }
    
    .login-flex {
        flex-direction: column;
        align-items: stretch;
        margin-top: 0.35rem;
        gap: 0.5rem;
    }
    
    .login-logo {
        border-right: none;
        border-bottom: 1px solid #eee;
        padding-right: 0;
        padding-bottom: 0.5rem;
        margin-bottom: 0.35rem;
        flex: 0 0 auto;
        width: 100%;
        max-width: none;
        justify-content: center;
    }
    
    .login-logo img {
        width: auto;
        max-width: 64px;
        margin: 0 auto;
    }
    
    .login-box h2 {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.2rem;
        margin-bottom: 0.35rem;
        font-size: 1.25rem;
    }
    
    .leitbild-link {
        font-size: 0.8rem;
    }

    .login-instance-hint {
        margin-bottom: 0.5rem;
        padding: 0.4rem 0.55rem;
        font-size: 0.8rem;
    }
}

/* Short viewports (phones) — keep demo login reachable */
@media (max-height: 820px) {
    #login-overlay {
        justify-content: flex-start;
    }

    .login-slogan {
        display: none;
    }

    .login-logo img {
        max-width: 56px;
    }

    .login-logo {
        padding-bottom: 0.35rem;
        margin-bottom: 0.25rem;
    }
}

.instance-registry-section {
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

.instance-registry-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
}

.instance-registry-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    text-align: left;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 0.65rem 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.instance-registry-item:hover {
    background: #e3f2fd;
    border-color: #90caf9;
}

.instance-registry-item strong {
    font-size: 0.95rem;
}

.instance-registry-item-demo {
    border-color: #f0d78c;
    background: #fff8e6;
}

.instance-demo-badge {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.1rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    background: #5c4b00;
    color: #fff8e6;
    border-radius: 3px;
    vertical-align: middle;
}

/* Connect landing (/app/connect/) */
body.connect-page {
    min-height: 100vh;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.connect-box {
    max-width: 420px;
    width: 100%;
}

.connect-status {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted, #666);
}

.connect-header {
    text-align: center;
    margin-bottom: 1.25rem;
}

.connect-logo {
    max-height: 64px;
    max-width: 180px;
    margin-bottom: 0.75rem;
    object-fit: contain;
}

.connect-qr-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 1rem 0 1.25rem;
}

.connect-qr-wrap canvas {
    border: 8px solid #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.connect-qr-hint {
    text-align: center;
    margin-top: 0.75rem;
    max-width: 280px;
}

.connect-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.connect-actions .btn,
.connect-actions .btn-secondary {
    text-align: center;
    text-decoration: none;
    display: block;
}

.connect-footnote {
    text-align: center;
    margin-top: 1rem;
    word-break: break-all;
}

/* Demo one-click roles (demo.nexedu.de) */
.demo-banner {
    background: #fff8e6;
    border: 1px solid #f0d78c;
    color: #5c4b00;
    padding: 0.65rem 0.85rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    line-height: 1.35;
}

.demo-login-intro {
    margin: 0 0 0.5rem;
}

.demo-link-hint {
    margin: 0 0 0.35rem;
    line-height: 1.35;
}

.demo-reset-link {
    border: 0;
    background: none;
    padding: 0;
    color: var(--accent, #2a6fdb);
    text-decoration: underline;
    font: inherit;
    font-size: inherit;
    cursor: pointer;
}

.demo-role-pickers,
.demo-role-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.demo-role-picker {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.35rem 0.45rem;
    border-radius: 6px;
    border: 1px solid transparent;
}

.demo-role-picker.is-focus {
    border-color: #c5d4e8;
    background: #f7faff;
}

.demo-role-picker-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

.demo-role-picker-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #333;
}

.demo-role-count {
    font-size: 0.75rem;
    color: #777;
    font-variant-numeric: tabular-nums;
}

.demo-user-select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.5rem 0.6rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
    line-height: 1.3;
    background: #fff;
    /* Safari: avoid native select blowing out flex row width */
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23666' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    background-size: 12px 8px;
    padding-right: 1.75rem;
}

.demo-role-btn,
.demo-login-submit {
    width: 100%;
    text-align: center;
    padding: 0.7rem 1rem;
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

/* Compact demo login on phones / tablets / short screens */
@media (max-width: 900px), (max-height: 820px) {
    .demo-banner {
        padding: 0.4rem 0.55rem;
        font-size: 0.75rem;
        margin-bottom: 0.45rem;
        line-height: 1.25;
    }

    .demo-login-intro {
        display: none;
    }

    .demo-link-hint {
        margin: 0 0 0.2rem;
        font-size: 0.75rem;
    }

    .demo-role-pickers,
    .demo-role-buttons {
        gap: 0.3rem;
    }

    .demo-role-picker {
        padding: 0.15rem 0.2rem;
        gap: 0.1rem;
    }

    .demo-role-picker-label {
        font-size: 0.72rem;
    }

    .demo-role-count {
        font-size: 0.68rem;
    }

    .demo-user-select {
        padding: 0.4rem 0.5rem;
        font-size: 0.88rem;
        min-height: 2.4rem;
    }

    .demo-login-submit {
        position: sticky;
        bottom: 0;
        z-index: 3;
        margin-top: 0.45rem;
        margin-bottom: 0;
        padding: 0.75rem 1rem;
        box-shadow: 0 -6px 14px rgba(255, 255, 255, 0.92);
        background: var(--accent);
    }
}

/* Inside .main-container (column flex) — must NOT be a body-level flex sibling,
   or it becomes a full-height column between sidebar and content. */
.demo-environment-banner {
    flex: 0 0 auto;
    width: 100%;
    background: #5c4b00;
    color: #fff8e6;
    text-align: center;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    line-height: 1.35;
    z-index: 1100;
}

@media print {
    body.connect-page {
        background: #fff;
    }

    .connect-actions,
    .login-slogan,
    .demo-environment-banner {
        display: none;
    }
}
