/* ═══════════════════════════════════════════════════════════════════════════
   trash mail — mail.squirrel.church
   Dark mode palette: black + deep purple
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Custom properties ──────────────────────────────────────────────────── */
:root {
    --bg:           #0a0a0f;
    --bg-card:      #111118;
    --bg-input:     #1a1a24;
    --bg-hover:     #1e1e2e;
    --bg-selected:  #1e1830;
    --border:       #2a2a3e;
    --border-focus: #7c3aed;

    --purple-dim:   #4c1d95;
    --purple:       #7c3aed;
    --purple-light: #a78bfa;
    --purple-glow:  rgba(124, 58, 237, 0.25);

    --text:         #e2e0f0;
    --text-muted:   #8b879e;
    --text-dim:     #5a5670;

    --red:          #ef4444;
    --red-dark:     #991b1b;
    --green:        #10b981;
    --yellow:       #f59e0b;

    --radius:       8px;
    --radius-sm:    4px;
    --shadow:       0 4px 24px rgba(0, 0, 0, 0.6);
    --transition:   160ms ease;

    --font: 'SF Mono', 'Fira Code', 'Consolas', 'Liberation Mono', monospace;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
    height: 100%;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--purple-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App shell ──────────────────────────────────────────────────────────── */
#app { height: 100%; }

.view { display: none; height: 100%; flex-direction: column; }
.view.active { display: flex; }

/* ─── Loading spinner ────────────────────────────────────────────────────── */
#view-loading {
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.spinner {
    width: 32px; height: 32px;
    border: 2px solid var(--border);
    border-top-color: var(--purple);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Auth views (login / register) ─────────────────────────────────────── */
#view-login,
#view-register {
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--bg);
}

.card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 36px;
    box-shadow: var(--shadow);
}

/* Register needs more horizontal space for username + suffix + button */
#view-register .card { max-width: 580px; }

.logo {
    font-size: 28px;
    font-weight: 700;
    color: var(--purple-light);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.tagline {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 28px;
}

/* ─── Form elements ──────────────────────────────────────────────────────── */
.field {
    margin-bottom: 18px;
}

label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    padding: 9px 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    appearance: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--purple-glow);
}

textarea { resize: vertical; min-height: 80px; }

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b879e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

select option { background: var(--bg-input); }

.input-suffix {
    display: flex;
    align-items: stretch;
}
.input-suffix input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; }
.suffix {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-muted);
    font-size: 13px;
    padding: 9px 10px;
    white-space: nowrap;
    display: flex;
    align-items: center;
}

.input-group { display: flex; gap: 8px; align-items: flex-start; }
.input-group .input-suffix { flex: 1; }

.field-hint {
    font-size: 12px;
    margin-top: 5px;
    min-height: 16px;
}
.field-hint.ok    { color: var(--green); }
.field-hint.err   { color: var(--red); }
.field-hint.check { color: var(--text-muted); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: var(--purple);
    color: #fff;
    border-color: var(--purple);
    width: 100%;
    margin-top: 4px;
}
.btn-primary:hover:not(:disabled) {
    background: #6d28d9;
    border-color: #6d28d9;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-focus);
}

.btn-danger {
    background: var(--red-dark);
    color: #fff;
    border-color: var(--red-dark);
}
.btn-danger:hover:not(:disabled) {
    background: var(--red);
    border-color: var(--red);
}

.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ─── Error / success messages ───────────────────────────────────────────── */
.error-msg {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    color: #fca5a5;
    font-size: 13px;
    margin: 10px 0 8px;
    padding: 10px 14px;
}
.success-msg {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius-sm);
    color: #6ee7b7;
    font-size: 13px;
    margin: 10px 0 8px;
    padding: 10px 14px;
}

/* ─── Warning box ────────────────────────────────────────────────────────── */
.warning-box {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: var(--radius-sm);
    color: #fcd34d;
    font-size: 12px;
    line-height: 1.6;
    margin-bottom: 18px;
    padding: 12px 14px;
}
.warning-box strong { color: #fde68a; }

/* ─── reCAPTCHA ──────────────────────────────────────────────────────────── */
.recaptcha-field { display: flex; justify-content: center; }

/* ─── Switch link ────────────────────────────────────────────────────────── */
.switch-link {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 20px;
    text-align: center;
}

/* ─── App header ─────────────────────────────────────────────────────────── */
.app-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    gap: 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.header-left  { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.logo-sm {
    color: var(--purple-light);
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
}
.header-address {
    color: var(--text-muted);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Countdown ──────────────────────────────────────────────────────────── */
.countdown-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(76, 29, 149, 0.2);
    border: 1px solid var(--purple-dim);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
}
.countdown-label { color: var(--text-muted); font-size: 11px; letter-spacing: 0.05em; }
.countdown-timer {
    color: var(--purple-light);
    font-size: 14px;
    font-weight: 700;
    min-width: 72px;
    text-align: right;
}
.countdown-timer.urgent { color: var(--red); }

/* ─── Inbox ──────────────────────────────────────────────────────────────── */
.inbox-main {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.inbox-toolbar { display: flex; align-items: center; gap: 10px; }

.email-list { display: flex; flex-direction: column; gap: 2px; }

.email-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    transition: background var(--transition), border-color var(--transition);
}
.email-item:hover { background: var(--bg-hover); border-color: var(--border-focus); }
.email-item.unread .email-subject { color: var(--text); font-weight: 700; }
.email-item.unread::before {
    content: '';
    display: block;
    width: 6px; height: 6px;
    background: var(--purple);
    border-radius: 50%;
}
.email-item:not(.unread)::before {
    content: '';
    display: block;
    width: 6px; height: 6px;
}

.email-meta { min-width: 0; overflow: hidden; }
.email-from {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.email-subject {
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-date {
    color: var(--text-dim);
    font-size: 11px;
    white-space: nowrap;
}

.direction-badge {
    font-size: 10px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border: 1px solid;
    border-radius: 3px;
    padding: 1px 5px;
}
.direction-badge.out { border-color: var(--purple-dim); color: var(--purple-light); }
.direction-badge.in  { border-color: #1e40af; color: #93c5fd; }

.empty-state {
    color: var(--text-dim);
    font-size: 13px;
    padding: 40px 0;
    text-align: center;
}

/* ─── Email view ─────────────────────────────────────────────────────────── */
.email-view-main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.email-detail {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.email-header-detail { margin-bottom: 20px; }
.email-subject-detail {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.3;
}
.email-meta-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.email-meta-label { color: var(--text-dim); min-width: 36px; }
.email-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.email-body-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
}

.email-body-html-frame {
    width: 100%;
    min-height: 200px;
    border: none;
    background: #fff;
    border-radius: var(--radius-sm);
}

.email-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Compose ────────────────────────────────────────────────────────────── */
.compose-main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.compose-title { color: var(--text-muted); font-size: 14px; }

#form-compose .field { margin-bottom: 14px; }
#form-compose textarea { min-height: 260px; }

.compose-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    gap: 10px;
    flex-wrap: wrap;
}
.compose-footer .btn-primary { width: auto; margin-top: 0; }
.from-label { color: var(--text-dim); font-size: 12px; }

/* ─── Settings ───────────────────────────────────────────────────────────── */
.settings-main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
}
.settings-main .card { margin-top: 0; }
.settings-main h2 { font-size: 16px; margin-bottom: 6px; }
.hint { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}
.modal-overlay[hidden] { display: none !important; }

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 380px;
    width: 100%;
    padding: 28px 32px;
    box-shadow: var(--shadow);
}
#modal-message {
    margin-bottom: 24px;
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
}
.modal-buttons { display: flex; gap: 10px; }
.modal-buttons .btn { flex: 1; margin-top: 0; }

/* ─── Scrollbar styling ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
    .card { padding: 28px 20px; }
    .app-header { padding: 8px 12px; }
    .inbox-main, .email-view-main, .compose-main, .settings-main { padding: 12px; }
    .countdown-box { padding: 4px 8px; }
    .countdown-timer { font-size: 12px; min-width: 62px; }
}
