html, body {
    margin: 0;
    min-height: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: #ececec;
    color: #111;
}

h1:focus {
    outline: none;
}

#blazor-error-ui {
    background: #fff3cd;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-top-color: #8031A8;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.app-bar {
    background: #8031A8;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.app-bar-title {
    font-weight: 700;
}

.app-bar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.app-bar-env {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    opacity: 0.9;
}

.app-bar-logout {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
}

.app-bar-logout:disabled,
.app-bar-logout.disabled {
    opacity: 0.55;
    cursor: default;
    pointer-events: none;
}

.app-bar-backup {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.app-bar-backup .app-bar-logout {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    text-decoration: none;
    color: #fff;
}

.app-bar-status {
    font-size: 12px;
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.95;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.env-picker {
    display: flex;
    overflow: hidden;
    border-radius: 4px;
}

.env-picker-btn {
    border: none;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    background: transparent;
}

.env-picker-card {
    border: 1px solid #8031A8;
    margin-bottom: 16px;
}

.env-picker-card .env-picker-btn {
    flex: 1;
    color: #8031A8;
    padding: 8px 12px;
}

.env-picker-card .env-picker-btn.active {
    background: #8031A8;
    color: #fff;
}

.env-picker-bar {
    border: 1px solid rgba(255, 255, 255, 0.7);
}

.env-picker-bar .env-picker-btn {
    color: #fff;
}

.env-picker-bar .env-picker-btn.active {
    background: #fff;
    color: #8031A8;
}

.env-picker-label {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
}

.app-body {
    padding: 0;
}

.login-page {
    min-height: 100vh;
    background: #8031A8;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.login-card {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    width: 360px;
    max-width: 100%;
    box-sizing: border-box;
}

.login-title {
    text-align: center;
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 24px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.field input,
.thread-input {
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 16px;
}

.login-error {
    color: #c62828;
    margin: 0 0 16px;
}

.login-submit {
    width: 100%;
    background: #8031A8;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 12px;
    font-size: 16px;
    cursor: pointer;
}

.login-submit:disabled {
    opacity: 0.6;
    cursor: default;
}

.login-secondary {
    width: 100%;
    margin-top: 12px;
    background: transparent;
    color: #8031A8;
    border: 1px solid #8031A8;
    border-radius: 4px;
    padding: 12px;
    font-size: 16px;
    cursor: pointer;
}

.inbox-wrap {
    max-width: 720px;
    margin: 0 auto;
    height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.inbox-search {
    flex-shrink: 0;
    padding: 12px 14px 8px;
    background: #ececec;
}

.inbox-search input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 16px;
}

.inbox-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
}

.inbox-pills + .inbox-pills {
    padding-top: 8px;
}

.inbox-pill {
    border: 1px solid #8031A8;
    background: transparent;
    color: #8031A8;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
}

.inbox-pill.active {
    background: #8031A8;
    color: #fff;
}

.inbox {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 14px 120px;
    box-sizing: border-box;
}

.inbox-empty {
    text-align: center;
    color: #666;
    padding: 32px;
}

.conv-card {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    border-radius: 20px;
    padding: 16px;
    margin: 10px 0;
    cursor: pointer;
    color: #111;
}

.conv-card.unread {
    background: #ff5252;
    font-weight: 700;
}

.conv-card.read {
    background: #448aff;
    font-weight: 200;
}

.conv-timestamp,
.conv-sender {
    margin-bottom: 4px;
}

.conv-preview {
    font-style: italic;
    white-space: pre-wrap;
    word-break: break-word;
}

.conv-preview mark {
    background: #ffe082;
    color: inherit;
    font-style: inherit;
    font-weight: 700;
    padding: 0 1px;
    border-radius: 2px;
}

.inbox-more {
    text-align: center;
    padding: 16px;
}

.thread {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
    box-sizing: border-box;
}

.thread-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.thread-back {
    color: #8031A8;
    text-decoration: none;
}

.thread-peer {
    font-weight: 700;
    word-break: break-all;
    background: transparent;
    border: none;
    padding: 0;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.thread-peer-id {
    font-size: 12px;
    color: #666;
    word-break: break-all;
}

.thread-alias-input {
    flex: 1;
    min-width: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 16px;
}

.thread-alias-save,
.thread-alias-cancel {
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
}

.thread-alias-save {
    background: #8031A8;
    color: #fff;
    border: none;
}

.thread-alias-cancel {
    background: transparent;
    color: #8031A8;
    border: 1px solid #8031A8;
}

.thread-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bubble {
    max-width: 80%;
    border-radius: 16px;
    padding: 10px 14px;
}

.bubble.mine {
    align-self: flex-end;
    background: #448aff;
}

.bubble.theirs {
    align-self: flex-start;
    background: #ff5252;
}

.bubble.focused {
    outline: 3px solid #ffe082;
    box-shadow: 0 0 0 4px rgba(255, 224, 130, 0.45);
}

.bubble-body mark {
    background: #ffe082;
    color: inherit;
    font-weight: 700;
    padding: 0 1px;
    border-radius: 2px;
}

.bubble-meta {
    font-size: 12px;
    opacity: 0.8;
    margin-bottom: 4px;
}

.bubble-delete {
    margin-left: 8px;
}

.bubble-delete-action {
    padding: 0;
    border: 0;
    color: inherit;
    background: none;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.bubble-delete-action:disabled {
    opacity: 0.6;
    cursor: default;
}

.bubble-delete-action + .bubble-delete-action {
    margin-left: 8px;
}

.bubble-body {
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble-image,
.preview-image {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin-top: 4px;
    background: rgba(255, 255, 255, 0.25);
}

.bubble-image {
    max-width: min(200px, 100%);
}

.preview-image {
    max-height: 80px;
    max-width: 120px;
}

.bubble-audio {
    display: block;
    width: 100%;
    max-width: 280px;
    margin-top: 6px;
}

.audio-message {
    display: grid;
    gap: 6px;
}

.audio-transcript,
.audio-transcription-status {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.35;
}

.audio-transcript-label {
    font-weight: 700;
}

.audio-transcription-status {
    opacity: 0.78;
}

.audio-transcription-retry {
    padding: 0;
    border: 0;
    color: inherit;
    background: none;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.media-link {
    display: inline-block;
    color: inherit;
}

.thread-compose {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 12px 16px 24px;
    align-items: center;
}

.thread-compose .thread-input {
    flex: 1;
    min-width: 0;
}

.thread-attach {
    background: #fff;
    color: #8031A8;
    border: 1px solid #8031A8;
    border-radius: 4px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.thread-attach.disabled {
    opacity: 0.6;
    cursor: default;
    pointer-events: none;
}

.thread-compose button {
    background: #8031A8;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 10px 16px;
    cursor: pointer;
}

.thread-compose button:disabled {
    opacity: 0.6;
    cursor: default;
}
