/* OGAH Webmail — mobile-first, dark theme.
   Variable names/values mirror admin/assets/admin-unified.css so this app
   reads as part of the same OGAH toolset family. */
:root {
    --primary: #3b82f6;
    --primary-dark: #1e3a8a;
    --primary-light: #60a5fa;
    --glass-bg: rgba(30, 41, 59, 0.95);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-color: #e2e8f0;
    --text-muted: #94a3b8;
    --dark-bg: #0f172a;
    --card-bg: #1e293b;
    --sidebar-bg: #1a2332;
    --border-color: rgba(255, 255, 255, 0.1);
    --silver: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0; height: 100%;
    background: var(--dark-bg); color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}
button, input, textarea { font-family: inherit; font-size: 1rem; color: inherit; }
a { color: var(--primary-light); }

/* ---------- Login ---------- */
.login-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1.5rem;
    background: radial-gradient(circle at top, #16213e 0%, var(--dark-bg) 60%);
}
.login-card {
    width: 100%; max-width: 380px;
    background: var(--card-bg); border: 1px solid var(--glass-border);
    border-radius: 16px; padding: 2rem 1.5rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-logo {
    width: 56px; height: 56px; margin: 0 auto 0.75rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 14px; display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem;
}
.login-brand h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-brand p { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.8rem; color: var(--text-muted); }
.login-form input {
    background: var(--dark-bg); border: 1px solid var(--border-color); border-radius: 8px;
    padding: 0.7rem 0.8rem; color: var(--text-color);
}
.login-form input:focus { outline: none; border-color: var(--primary); }
.input-with-suffix { display: flex; align-items: center; background: var(--dark-bg); border: 1px solid var(--border-color); border-radius: 8px; }
.input-with-suffix input { border: none; background: transparent; flex: 1; min-width: 0; }
.input-with-suffix .suffix { padding: 0 0.8rem; color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }
.login-footnote { margin: 1.25rem 0 0; text-align: center; font-size: 0.75rem; color: var(--text-muted); }
.alert { padding: 0.65rem 0.85rem; border-radius: 8px; font-size: 0.85rem; margin-bottom: 1rem; }
.alert-danger { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.35); color: #fca5a5; }

/* ---------- Buttons ---------- */
.btn { border: none; border-radius: 8px; padding: 0.65rem 1rem; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary { background: var(--card-bg); color: var(--text-color); border: 1px solid var(--border-color); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.link-btn { background: none; border: none; color: var(--primary-light); padding: 0; cursor: pointer; font-size: 0.85rem; }
.icon-btn {
    background: none; border: none; color: var(--text-color); font-size: 1.25rem;
    width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,0.08); }

/* ---------- App shell ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 0.5rem;
    padding: calc(var(--safe-top) + 0.5rem) 0.5rem 0.5rem;
    background: var(--card-bg); border-bottom: 1px solid var(--border-color);
    position: sticky; top: 0; z-index: 20;
}
.topbar-title { flex: 1; font-weight: 700; font-size: 1.05rem; }

.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 82vw);
    background: var(--sidebar-bg); border-right: 1px solid var(--border-color);
    transform: translateX(-100%); transition: transform 0.2s ease;
    z-index: 40; display: flex; flex-direction: column;
    padding: calc(var(--safe-top) + 1rem) 1rem 1rem;
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar-account { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; word-break: break-all; }
.sidebar-compose { margin-bottom: 1rem; }
.sidebar-nav { list-style: none; margin: 0; padding: 0; }
.nav-item {
    display: flex; align-items: center; gap: 0.5rem; width: 100%;
    background: none; border: none; color: var(--text-color); text-decoration: none;
    text-align: left; padding: 0.65rem 0.5rem; border-radius: 8px; cursor: pointer; font-size: 0.95rem;
}
.nav-item:hover, .nav-item.active { background: rgba(59,130,246,0.15); color: var(--primary-light); }
.nav-item .badge {
    margin-left: auto; background: var(--primary); color: #fff; border-radius: 999px;
    font-size: 0.7rem; padding: 0.1rem 0.5rem; min-width: 1.2rem; text-align: center;
}
.nav-item .badge:empty { display: none; }
.sidebar-divider { height: 1px; background: var(--border-color); margin: 0.75rem 0; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; }
.nav-item.logout { color: var(--danger); }
.sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 30;
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

/* ---------- Message list ---------- */
.search-bar { padding: 0.6rem; border-bottom: 1px solid var(--border-color); }
.search-bar input {
    width: 100%; background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 999px; padding: 0.55rem 1rem;
}
.message-list { flex: 1; overflow-y: auto; }
.message-row {
    display: flex; gap: 0.75rem; padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color);
    cursor: pointer; align-items: flex-start;
}
.message-row:active { background: rgba(255,255,255,0.04); }
.message-row.unread { background: rgba(59,130,246,0.06); }
.message-row.unread .msg-from, .message-row.unread .msg-subject { font-weight: 700; }
.msg-avatar {
    width: 38px; height: 38px; border-radius: 50%; background: var(--primary-dark);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
    flex-shrink: 0; font-size: 0.9rem;
}
.msg-main { flex: 1; min-width: 0; }
.msg-top-row { display: flex; justify-content: space-between; gap: 0.5rem; }
.msg-from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.msg-date { flex-shrink: 0; font-size: 0.75rem; color: var(--text-muted); }
.msg-subject { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 0.15rem; }
.msg-star { color: var(--warning); margin-left: 0.35rem; }
.empty-state { text-align: center; color: var(--text-muted); padding: 3rem 1rem; }
.hidden { display: none !important; }
.load-more { text-align: center; padding: 1rem; }

/* ---------- Detail / Compose / Contacts (always full-page) ---------- */
.detail-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.5rem; border-bottom: 1px solid var(--border-color); background: var(--card-bg);
}
.detail-toolbar-actions { display: flex; gap: 0.25rem; }
.detail-content { flex: 1; overflow-y: auto; padding: 1rem; }
.detail-subject { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.75rem; }
.detail-meta { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.detail-meta strong { color: var(--text-color); }
.detail-body { margin-top: 1rem; line-height: 1.55; word-wrap: break-word; }
.detail-body img { max-width: 100%; height: auto; }
.detail-attachments { margin-top: 1.5rem; border-top: 1px solid var(--border-color); padding-top: 1rem; }
.attachment-item {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem;
    background: var(--card-bg); border-radius: 8px; margin-bottom: 0.5rem; text-decoration: none; color: var(--text-color);
}
.detail-reply-bar { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--border-color); background: var(--card-bg); }
.detail-reply-bar .btn { flex: 1; }

.compose-form { display: flex; flex-direction: column; gap: 0.85rem; padding: 1rem; flex: 1; overflow-y: auto; }
.compose-field { display: flex; flex-direction: column; gap: 0.3rem; }
.compose-field label { font-size: 0.78rem; color: var(--text-muted); }
.compose-field input, .compose-field textarea {
    background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px; padding: 0.6rem 0.75rem;
}
.compose-cc-row { flex-direction: row; }
.compose-body-field { flex: 1; }
.compose-body-field textarea { flex: 1; min-height: 200px; resize: vertical; }
.attach-label { display: inline-block; cursor: pointer; color: var(--primary-light); font-size: 0.9rem; }
.attachment-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.attachment-chip { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.78rem; display: flex; gap: 0.4rem; align-items: center; }
.attachment-chip button { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; }

.contacts-list { flex: 1; overflow-y: auto; }
.contact-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border-color); cursor: pointer; }
.contact-row:active { background: rgba(255,255,255,0.04); }
.contact-row .msg-avatar { background: var(--primary); }
.contact-name { font-weight: 600; }
.contact-email { font-size: 0.82rem; color: var(--text-muted); }
.contact-form-wrap { position: fixed; inset: 0; background: var(--dark-bg); z-index: 50; display: flex; flex-direction: column; }
.contact-form-wrap.hidden { display: none; }
.contact-form-actions { flex-direction: row; gap: 0.5rem; }

.toast {
    position: fixed; bottom: calc(var(--safe-bottom) + 1rem); left: 50%; transform: translateX(-50%);
    background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 999px;
    padding: 0.6rem 1.2rem; font-size: 0.85rem; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* ---------- Wider screens: cap width, still full-page swaps (never split) ---------- */
@media (min-width: 720px) {
    #app { max-width: 720px; margin: 0 auto; border-left: 1px solid var(--border-color); border-right: 1px solid var(--border-color); }
    .sidebar { position: absolute; }
}
