:root {
    --bg-card: #ffffff;
    --bg-primary: #f8f9fa;
    --border-color: #1b1b1b;
    --accent-subtle: rgba(15, 98, 254, 0.2);
    --radius-sm: 0.4rem;
    --radius-md: 0.6rem;
    --radius-lg: 0.9rem;
    --radius-xl: 1.15rem;
    --text-primary: #111111;
    --text-secondary: #4d4d4d;
    --text-muted: #6b6b6b;
    --accent-primary: #ff0039;
    --accent-secondary: #0f62fe;
    --success: #0c9f4f;
    --error: #cb1e2d;
    --warning: #ffb400;
    --font-sans: "Inter", "Segoe UI", Arial, sans-serif;
    --font-mono: "JetBrains Mono", "Consolas", monospace;
}

[data-theme="dark"] {
    --bg-card: #1f1f1f;
    --bg-primary: #121212;
    --border-color: #f4f4f4;
    --text-primary: #f1f1f1;
    --text-secondary: #d0d0d0;
    --text-muted: #9a9a9a;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    position: relative;
}

/* Keep text readable when custom dark mode is enabled on top of Bootswatch Brite */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6,
[data-theme="dark"] .form-label,
[data-theme="dark"] .lead {
    color: var(--text-primary) !important;
}

[data-theme="dark"] p,
[data-theme="dark"] .text-body-secondary,
[data-theme="dark"] .email-item-subject,
[data-theme="dark"] .email-item-snippet,
[data-theme="dark"] .myemail-date,
[data-theme="dark"] .auto-refresh-text {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .domain-dropdown,
[data-theme="dark"] textarea {
    background: #1a1a1a !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .form-control::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: var(--text-muted) !important;
}

.bg-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, rgba(0, 0, 0, 0.05) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 32px 32px;
    z-index: -1;
}

[data-theme="dark"] .bg-grid {
    background-image:
        linear-gradient(to right, rgba(255, 255, 255, 0.06) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
}

#site-header {
    position: sticky;
    top: 0;
    z-index: 99;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(6px);
}

[data-theme="dark"] #site-header {
    background: rgba(18, 18, 18, 0.9);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    user-select: none;
}

.logo-icon {
    width: 2.4rem;
    height: 2.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #fffa8b;
    color: #000000;
}

[data-theme="dark"] .logo-icon {
    background: #22d2ed;
}

.logo-text {
    font-weight: 800;
    letter-spacing: 0.02em;
}

.header-nav {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: #111;
    padding: 0.45rem 0.75rem;
    font-weight: 700;
    line-height: 1;
}

[data-theme="dark"] .nav-btn {
    background: #262626;
    color: #fff;
}

.nav-btn.active {
    background: #ff0039;
    color: #fff;
}

.nav-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 2px 2px 0 #111;
}

#main-content {
    max-width: 860px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.hero {
    text-align: center;
}

.hero-telegram-wrap {
    display: flex;
    justify-content: center;
}

.hero-telegram-btn {
    min-width: 280px;
}

.hero-badge {
    border: 2px solid #111;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
}

.card,
.generate-card,
.result-card,
.detail-content,
.email-item,
.myemail-item,
.admin-card,
.modal-content.popup-card {
    background: var(--bg-card);
    border: 2px solid var(--border-color) !important;
    border-radius: var(--radius-md);
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.85);
}

[data-theme="dark"] .card,
[data-theme="dark"] .generate-card,
[data-theme="dark"] .result-card,
[data-theme="dark"] .detail-content,
[data-theme="dark"] .email-item,
[data-theme="dark"] .myemail-item,
[data-theme="dark"] .admin-card,
[data-theme="dark"] .modal-content.popup-card {
    box-shadow: 5px 5px 0 rgba(255, 255, 255, 0.85);
}

.generate-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.custom-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.custom-input-group input {
    min-width: 0;
}

.domain-preview {
    padding: 0.55rem 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #f3f3f3;
    font-weight: 700;
    white-space: nowrap;
}

[data-theme="dark"] .domain-preview {
    background: #333;
}

.btn {
    border-width: 2px;
    border-style: solid;
    border-color: #111;
    border-radius: var(--radius-sm);
    font-weight: 700;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.85);
}

[data-theme="dark"] .btn {
    border-color: #f4f4f4;
    box-shadow: 3px 3px 0 rgba(255, 255, 255, 0.85);
}

.btn:hover {
    transform: translate(-2px, -2px);
}

.btn:active {
    transform: translate(0, 0);
}

.btn-primary {
    background: #ff0039;
    color: #fff;
}

.btn-secondary {
    background: #f2f2f2;
    color: #111;
}

[data-theme="dark"] .btn-secondary {
    background: #3a3a3a;
    color: #f1f1f1;
}

.btn-accent {
    background: #0f62fe;
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: inherit;
}

[data-theme="dark"] .btn-ghost {
    color: #f1f1f1;
}

.btn-danger {
    background: #ffe9ed;
    color: #b5072b;
}

.form-control,
.form-select,
.domain-dropdown,
textarea {
    border: 2px solid var(--border-color) !important;
    border-radius: var(--radius-sm) !important;
}

.form-control:focus,
.form-select:focus,
textarea:focus {
    box-shadow: 0 0 0 0.2rem rgba(15, 98, 254, 0.25) !important;
}

.email-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border: 2px dashed #111;
    border-radius: var(--radius-sm);
    padding: 0.9rem;
    cursor: pointer;
}

[data-theme="dark"] .email-display {
    border-color: #f4f4f4;
}

.email-text {
    font-family: monospace;
    font-size: 1rem;
    font-weight: 700;
    word-break: break-all;
}

[data-theme="dark"] .email-text {
    color: var(--text-primary);
}

.copy-btn {
    border: 2px solid #111;
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.55rem;
    font-weight: 700;
}

[data-theme="dark"] .copy-btn {
    background: #222;
    color: #fff;
    border-color: #fff;
}

.result-actions {
    display: flex;
    gap: 0.65rem;
    justify-content: center;
}

.inbox-email-addr {
    font-family: monospace;
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.auto-refresh-bar {
    position: relative;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    overflow: hidden;
    background: #fff;
}

[data-theme="dark"] .auto-refresh-bar {
    background: #202020;
}

.auto-refresh-progress {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: rgba(255, 0, 57, 0.25);
    transition: width 1s linear;
}

.auto-refresh-text {
    position: relative;
    z-index: 1;
    font-weight: 700;
    font-size: 0.85rem;
}

.inbox-list,
.myemails-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.loading-state,
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
}

.loading-spinner {
    width: 2.2rem;
    height: 2.2rem;
    border: 3px solid rgba(0, 0, 0, 0.2);
    border-top-color: #ff0039;
    border-radius: 50%;
    margin: 0 auto 0.75rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.email-item,
.myemail-item {
    padding: 0.95rem;
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
}

.email-item {
    cursor: pointer;
}

.email-item-icon,
.myemail-icon {
    min-width: 2.2rem;
    height: 2.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #111;
    border-radius: var(--radius-sm);
    background: #fffa8b;
    font-weight: 800;
    color: #000000;
}

[data-theme="dark"] .email-item-icon,
[data-theme="dark"] .myemail-icon {
    background: #22d2ed;
}

.myemail-info,
.email-item-content {
    min-width: 0;
    flex: 1;
}

.myemail-address,
.email-item-from,
.email-item-subject,
.email-item-snippet,
.myemail-date {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-item-time {
    font-size: 0.78rem;
    font-weight: 700;
}

.myemail-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.myemail-actions .btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
}

.active-badge {
    margin-left: 0.4rem;
    padding: 0.15rem 0.4rem;
    border: 2px solid #111;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    background: #c3ffd7;
}

[data-theme="dark"] .active-badge {
    color: #000000 !important;
}

.detail-meta {
    border-bottom: 2px solid var(--border-color);
    padding: 1rem;
}

.detail-subject {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
}

.detail-info {
    display: grid;
    gap: 0.4rem;
}

.detail-info-row {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 0.5rem;
}

.detail-info-row .label {
    font-weight: 800;
}

.detail-body {
    padding: 1rem;
}

.detail-body pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.detail-body .email-html-content {
    background: #ffffff;
    color: #000000 !important;
    border: 2px solid #111;
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    overflow-x: auto;
}

[data-theme="dark"] .detail-body .email-html-content,
[data-theme="dark"] .detail-body .email-html-content * {
    color: #000000 !important;
}

.detail-body .email-html-content a {
    color: #0f62fe !important;
}

.detail-body .email-html-content img {
    max-width: 100%;
    height: auto;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1050;
    padding: 1rem;
}

.popup-card {
    width: 100%;
    max-width: 420px;
}

.donate-card {
    max-width: 460px;
}

.popup-header {
    border-bottom: 2px solid var(--border-color);
    padding: 0.95rem 1rem;
    background: #22d2ed;
}

.popup-header h3 {
    color: #000000 !important;
    font-weight: 800;
}

.popup-body {
    padding: 1rem;
}

[data-theme="dark"] .popup-body {
    color: var(--text-primary) !important;
}

.popup-footer {
    padding: 0 1rem 1rem;
}

.qris-wrap {
    border: 2px solid #111;
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 0.5rem;
}

.modal-close {
    position: absolute;
    right: 0.7rem;
    top: 0.6rem;
    border: 2px solid #111;
    border-radius: 0.35rem;
    background: #fff;
    width: 2rem;
    height: 2rem;
    font-weight: 900;
    line-height: 1;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translate(-50%, 120%);
    z-index: 1100;
    background: #111;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 999px;
    padding: 0.55rem 1rem;
    font-weight: 700;
    transition: transform 0.2s ease;
}

.toast.show {
    transform: translate(-50%, 0);
}

.btn-spinner {
    display: inline-block;
    width: 0.95rem;
    height: 0.95rem;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@media (max-width: 768px) {
    .generate-actions {
        grid-template-columns: 1fr;
    }

    .result-actions {
        flex-direction: column;
    }

    .result-actions .btn {
        width: 100%;
    }

    .header-inner {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-nav {
        width: 100%;
    }

    .nav-btn {
        flex: 1;
        justify-content: center;
    }

    .nav-text-hide {
        display: none;
    }

    .hero-telegram-btn {
        width: 100%;
        min-width: 0;
    }

    .myemail-actions {
        width: 100%;
    }

    .myemail-actions .btn {
        flex: 1;
    }

    .inbox-header .card-body {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-refresh {
        width: 100%;
    }

    .detail-info-row {
        grid-template-columns: 1fr;
    }
}
