:root {
    color-scheme: dark;
    --dside-dark: #1a1a2e;
    --dside-blue: #16213e;
    --dside-accent: #0f3460;
    --dside-highlight: #e94560;
    --dside-success: #2ecc71;
    --dside-text: #f0f0f0;
    --dside-muted: #8892b0;
    --panel-bg: #0d1117;
    --panel-border: #30363d;
    --markdown-subheading: #c9d1d9;
    --markdown-strong: #ffffff;
    --markdown-em: #c9d1d9;
    --code-bg: rgba(0, 0, 0, 0.25);
    --table-th-bg: rgba(15, 52, 96, 0.5);
    --table-row-alt: rgba(255, 255, 255, 0.03);
    --blockquote-bg: rgba(233, 69, 96, 0.06);
    --toggle-track: #30363d;
    --toggle-thumb: #f0f0f0;
}

[data-theme="light"] {
    color-scheme: light;
    --dside-dark: #eef1f6;
    --dside-blue: #ffffff;
    --dside-accent: #d6e4f5;
    --dside-highlight: #c73652;
    --dside-success: #1e8f4a;
    --dside-text: #1a1a2e;
    --dside-muted: #5c6578;
    --panel-bg: #ffffff;
    --panel-border: #d0d7e2;
    --markdown-subheading: #3d4556;
    --markdown-strong: #0d1117;
    --markdown-em: #4a5568;
    --code-bg: rgba(0, 0, 0, 0.06);
    --table-th-bg: rgba(15, 52, 96, 0.1);
    --table-row-alt: rgba(0, 0, 0, 0.03);
    --blockquote-bg: rgba(199, 54, 82, 0.08);
    --toggle-track: #c8d0dc;
    --toggle-thumb: #ffffff;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--dside-dark);
    color: var(--dside-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--dside-blue);
    border-bottom: 1px solid var(--panel-border);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.logo {
    height: 36px;
    width: auto;
    flex-shrink: 0;
}

.logo-light {
    display: none;
}

[data-theme="light"] .logo-dark {
    display: none;
}

[data-theme="light"] .logo-light {
    display: block;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--dside-muted);
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
    color: var(--dside-muted);
    transition: border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
    color: var(--dside-text);
    border-color: var(--dside-muted);
}

.theme-toggle-icon {
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.45;
    transition: opacity 0.2s;
}

[data-theme="dark"] .theme-toggle-icon:last-child,
[data-theme="light"] .theme-toggle-icon:first-child {
    opacity: 1;
}

.theme-toggle-track {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--toggle-track);
    border-radius: 11px;
    transition: background 0.2s;
}

.theme-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--toggle-thumb);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
}

[data-theme="light"] .theme-toggle-thumb {
    transform: translateX(18px);
}

.main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: 0;
}

.panel {
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    min-height: 0;
}

.panel h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--dside-muted);
    margin-bottom: 0;
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.new-chat-btn {
    background: transparent;
    color: var(--dside-muted);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
}

.new-chat-btn:hover {
    color: var(--dside-text);
    border-color: var(--dside-muted);
}

.panel > h2 {
    margin-bottom: 1rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    min-height: 300px;
}

.message {
    max-width: 90%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
}

.message-user {
    align-self: flex-end;
    background: var(--dside-accent);
    border-bottom-right-radius: 4px;
}

.message-assistant {
    align-self: flex-start;
    background: var(--dside-blue);
    border-bottom-left-radius: 4px;
    max-width: 95%;
}

.message-markdown {
    line-height: 1.6;
}

.message-markdown h1,
.message-markdown h2,
.message-markdown h3 {
    color: var(--dside-text);
    font-weight: 600;
    margin: 1rem 0 0.5rem;
    line-height: 1.3;
}

.message-markdown h1 { font-size: 1.15rem; }
.message-markdown h2 { font-size: 1.05rem; border-bottom: 1px solid var(--panel-border); padding-bottom: 0.35rem; }
.message-markdown h3 { font-size: 0.98rem; color: var(--markdown-subheading); }

.message-markdown p {
    margin: 0.5rem 0;
}

.message-markdown p:first-child,
.message-markdown h1:first-child,
.message-markdown h2:first-child,
.message-markdown h3:first-child {
    margin-top: 0;
}

.message-markdown ul,
.message-markdown ol {
    margin: 0.5rem 0 0.5rem 1.25rem;
    padding: 0;
}

.message-markdown li {
    margin: 0.35rem 0;
}

.message-markdown li::marker {
    color: var(--dside-muted);
}

.message-markdown strong {
    color: var(--markdown-strong);
    font-weight: 600;
}

.message-markdown em {
    color: var(--markdown-em);
}

.message-markdown code {
    background: var(--code-bg);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.88em;
}

.message-markdown hr {
    border: none;
    border-top: 1px solid var(--panel-border);
    margin: 1rem 0;
}

.message-markdown blockquote {
    border-left: 3px solid var(--dside-highlight);
    margin: 0.75rem 0;
    padding: 0.5rem 0 0.5rem 1rem;
    color: var(--dside-muted);
    background: var(--blockquote-bg);
    border-radius: 0 6px 6px 0;
}

.message-markdown .md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.88rem;
}

.message-markdown .md-table th,
.message-markdown .md-table td {
    border: 1px solid var(--panel-border);
    padding: 0.45rem 0.6rem;
    text-align: left;
}

.message-markdown .md-table th {
    background: var(--table-th-bg);
    font-weight: 600;
}

.message-markdown .md-table tbody tr:nth-child(even) {
    background: var(--table-row-alt);
}

.message-loading {
    align-self: flex-start;
    color: var(--dside-muted);
    font-style: italic;
}

.message-error {
    align-self: center;
    background: rgba(233, 69, 96, 0.2);
    border: 1px solid var(--dside-highlight);
    color: var(--dside-highlight);
}

.chat-input-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.demo-scenario {
    background: var(--dside-blue);
    color: var(--dside-text);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 0.85rem;
}

#message-input {
    width: 100%;
    background: var(--dside-blue);
    color: var(--dside-text);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.95rem;
    resize: none;
    overflow-y: hidden;
    min-height: 5.5rem;
    max-height: 40vh;
    line-height: 1.5;
    font-family: inherit;
    box-sizing: border-box;
}

#message-input:focus {
    outline: none;
    border-color: var(--dside-highlight);
}

#send-btn {
    align-self: flex-end;
    background: var(--dside-highlight);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 500;
}

#send-btn:hover:not(:disabled) {
    opacity: 0.9;
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.transparency-label {
    font-size: 0.85rem;
    color: var(--dside-muted);
    margin-bottom: 0.5rem;
}

.detected-language {
    font-size: 0.85rem;
    color: var(--dside-muted);
    margin-bottom: 0.75rem;
}

.detected-language span {
    color: var(--dside-text);
    font-weight: 500;
}

.anonymized-text {
    background: var(--dside-blue);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 120px;
    margin-bottom: 1rem;
    font-family: inherit;
}

.entity-summary {
    font-size: 0.85rem;
    color: var(--dside-muted);
    margin-bottom: 0.5rem;
}

.entity-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--dside-accent);
    color: var(--dside-text);
}

.badge-person,
.badge-avs_number {
    background: #2d4a7a;
}

.badge-iban_code {
    background: #3d2d5a;
}

.badge-case_number {
    background: #5a3d2d;
}

.badge-email_address {
    background: #2d5a4a;
}

.badge-location {
    background: #4a4a2d;
}

.badge-organization,
.badge-swiss_ide {
    background: #3d4a5a;
}

.indicator-success,
.indicator-neutral {
    font-size: 0.9rem;
    padding: 0.75rem;
    border-radius: 8px;
    margin-top: auto;
}

.indicator-success {
    background: rgba(46, 204, 113, 0.15);
    color: var(--dside-success);
    border: 1px solid rgba(46, 204, 113, 0.3);
}

.indicator-neutral {
    background: rgba(136, 146, 176, 0.1);
    color: var(--dside-muted);
    border: 1px solid var(--panel-border);
}

.header-brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.user-name {
    font-size: 0.9rem;
    color: var(--dside-muted);
    max-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-btn {
    background: transparent;
    color: var(--dside-text);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    flex-shrink: 0;
}

.logout-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.logout-btn:hover {
    border-color: var(--dside-highlight);
    color: var(--dside-highlight);
}

.login-page {
    --dside-dark: #121212;
    --dside-blue: #1a1a1a;
    --dside-accent: #2a2a2a;
    --dside-highlight: #e53935;
    --dside-text: #f5f5f5;
    --dside-muted: #9e9e9e;
    --panel-bg: #1e1e1e;
    --panel-border: #333333;
    justify-content: center;
    align-items: center;
    background: var(--dside-dark);
    color: var(--dside-text);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 1.5rem;
}

.login-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
}

.login-logo {
    width: 120px;
    height: auto;
    display: block;
}

.login-brand .login-logo.logo-light {
    display: none;
}

.login-brand .login-logo.logo-dark {
    display: block;
}

[data-theme="light"] .login-brand .login-logo.logo-dark {
    display: none;
}

[data-theme="light"] .login-brand .login-logo.logo-light {
    display: block;
}

.login-subtitle {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--dside-muted);
    letter-spacing: 0.02em;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.login-form label {
    font-size: 0.9rem;
    color: var(--dside-muted);
    margin-top: 0.5rem;
}

.login-form input {
    width: 100%;
    padding: 0.75rem;
    background: var(--dside-blue);
    color: var(--dside-text);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    font-size: 1rem;
}

.login-form input:focus {
    outline: 2px solid var(--dside-highlight);
    outline-offset: 1px;
}

.login-form button {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--dside-highlight);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.login-form button:hover:not(:disabled) {
    background: #c62828;
}

.login-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-error {
    color: var(--dside-highlight);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.login-help {
    font-size: 0.85rem;
    color: var(--dside-muted);
    text-align: center;
}

@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }

    .chat-messages {
        min-height: 200px;
    }
}
