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

:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-hover: #fff0f3;
    --border: #f0c0cc;
    --border-light: #fce4ec;
    --text: #d63384;
    --text-secondary: #e06a9e;
    --text-muted: #f0a0bf;
    --primary: #e91e8c;
    --primary-hover: #c2185b;
    --primary-light: #fce4ec;
    --danger: #e03131;
    --danger-light: #fff5f5;
    --success: #2f9e44;
    --success-light: #ebfbee;
    --warning: #f08c00;
    --warning-light: #fff9db;
    --star: #e91e8c;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(233,30,140,0.08), 0 1px 2px rgba(233,30,140,0.06);
    --shadow-lg: 0 4px 12px rgba(233,30,140,0.12);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'SF Mono', 'Fira Code', monospace;
    --sidebar-w: 260px;
    --transition: 0.15s ease;
}

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

#app { min-height: 100vh; }

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

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border: none; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500; cursor: pointer;
    transition: all var(--transition);
    text-decoration: none !important;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c92a2a; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-lg { padding: 12px 32px; font-size: 16px; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: none; border-radius: var(--radius-sm);
    background: transparent; color: var(--text-secondary); cursor: pointer;
    transition: all var(--transition);
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn:disabled, .btn-icon:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); font-size: 13px; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px; font-family: var(--font);
    transition: border-color var(--transition);
    background: var(--surface);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: 13px; margin-bottom: 12px;
}
.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #ffc9c9; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #b2f2bb; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #ffe066; }

/* ── Landing ────────────────────────────────────────────────────────────── */
.landing {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #fce4ec 0%, #f8bbd0 50%, #f48fb1 100%);
}
.landing-card {
    text-align: center; background: white; padding: 48px 40px;
    border-radius: 16px; box-shadow: var(--shadow-lg);
}
.landing-logo { color: var(--primary); margin-bottom: 16px; }
.landing-card h1 { font-size: 28px; margin-bottom: 8px; }
.landing-sub { color: var(--text-secondary); margin-bottom: 28px; }

/* ── Auth ───────────────────────────────────────────────────────────────── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: #ffffff;
}
.auth-card {
    width: 100%; max-width: 420px; background: #ffffff;
    padding: 40px 36px; border-radius: 16px;
    box-shadow: 0 8px 32px rgba(233,30,140,0.10), 0 2px 8px rgba(233,30,140,0.06);
    border: 1px solid #fce4ec;
}
.auth-logo { color: var(--primary); margin-bottom: 16px; text-align: center; }
.auth-card h2 { text-align: center; margin-bottom: 24px; font-size: 22px; color: #d63384; font-weight: 700; }

/* ── Mail Layout ────────────────────────────────────────────────────────── */
.mail-layout {
    display: flex; height: 100vh; overflow: hidden;
}
.sidebar {
    width: var(--sidebar-w); min-width: var(--sidebar-w);
    background: var(--surface); border-right: 1px solid var(--border-light);
    display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--border-light); }
.user-email { display: block; font-weight: 600; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--primary-light); color: var(--primary); margin-top: 4px; }
.btn-compose { margin: 12px 16px; justify-content: center; }
.mailbox-list { flex: 1; padding: 4px 8px; }
.mailbox-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer;
    font-size: 13px; transition: all var(--transition); color: var(--text);
    text-decoration: none !important;
}
.mailbox-item:hover { background: var(--surface-hover); }
.mailbox-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.mailbox-name { flex: 1; }
.mailbox-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--primary); color: white; font-size: 11px; font-weight: 600;
}
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border-light); }
.sidebar-link {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px;
    color: var(--text-secondary); cursor: pointer; width: 100%;
    background: none; border: none; text-align: left; font-family: var(--font);
    text-decoration: none !important; transition: all var(--transition);
}
.sidebar-link:hover { background: var(--surface-hover); color: var(--text); }

/* ── Mail Main ──────────────────────────────────────────────────────────── */
.mail-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; background: var(--surface);
    border-bottom: 1px solid var(--border-light);
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-left h2 { font-size: 16px; font-weight: 600; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.search-box {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-secondary);
}
.search-box input {
    border: none; background: none; outline: none; width: 200px;
    font-size: 13px; padding: 0;
}
.search-box input:focus { box-shadow: none; }

/* ── Message List ───────────────────────────────────────────────────────── */
.messages-list { flex: 1; overflow-y: auto; }
.msg-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px; border-bottom: 1px solid var(--border-light);
    cursor: pointer; transition: background var(--transition);
    text-decoration: none !important; color: inherit;
}
.msg-row:hover { background: var(--surface); }
.msg-row.unread { background: var(--surface); font-weight: 600; }
.msg-row.unread .msg-row-from, .msg-row.unread .msg-row-subject { font-weight: 600; }
.msg-row-star { flex-shrink: 0; color: var(--text-muted); cursor: pointer; }
.msg-row-star.starred { color: var(--star); }
.msg-row-content { flex: 1; min-width: 0; }
.msg-row-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-row-from { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.msg-row-subject { font-size: 13px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400 !important; }
.msg-row-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.msg-row-attachment { color: var(--text-muted); }
.msg-row-date { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }

.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex: 1; gap: 12px; color: var(--text-muted);
}
.loading { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--text-secondary); padding: 40px; }

/* ── Compose ────────────────────────────────────────────────────────────── */
.compose-page { max-width: 800px; margin: 0 auto; padding: 20px; }
.compose-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.compose-header h2 { font-size: 20px; }
.compose-form { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.compose-field {
    display: flex; align-items: center; border-bottom: 1px solid var(--border-light);
}
.compose-field label { padding: 10px 16px; font-weight: 500; color: var(--text-secondary); font-size: 13px; min-width: 70px; }
.compose-field input { border: none; border-radius: 0; padding: 10px 16px 10px 0; }
.compose-field input:focus { box-shadow: none; }

.editor-toolbar {
    display: flex; align-items: center; gap: 2px; padding: 6px 12px;
    border-bottom: 1px solid var(--border-light); background: var(--bg);
}
.toolbar-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; border-radius: 4px;
    background: transparent; cursor: pointer; color: var(--text-secondary);
    font-size: 14px; transition: all var(--transition);
}
.toolbar-btn:hover { background: var(--surface-hover); color: var(--text); }
.toolbar-sep { width: 1px; height: 20px; background: var(--border-light); margin: 0 4px; }

.compose-editor {
    min-height: 300px; max-height: 500px; padding: 16px; overflow-y: auto;
    font-size: 14px; line-height: 1.6; outline: none;
}
.compose-editor:focus { background: #fefefe; }

.attachments-area { padding: 12px 16px; border-top: 1px solid var(--border-light); }
.attachments-header { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.attachments-list { display: flex; flex-wrap: wrap; gap: 8px; }
.att-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 16px; font-size: 12px;
    background: var(--bg); border: 1px solid var(--border);
}
.att-chip-remove { cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1; }
.att-chip-remove:hover { color: var(--danger); }

.compose-actions { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border-light); }

/* ── Read Message ───────────────────────────────────────────────────────── */
.read-page { max-width: 800px; margin: 0 auto; padding: 20px; }
.read-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.read-actions { display: flex; gap: 4px; }

.message-view { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.message-meta { padding: 20px 24px; border-bottom: 1px solid var(--border-light); }
.msg-subject { font-size: 20px; margin-bottom: 12px; line-height: 1.3; }
.msg-info { font-size: 13px; color: var(--text-secondary); }
.msg-info > div { margin-bottom: 4px; }
.msg-date { color: var(--text-muted); }

.msg-attachments { padding: 12px 24px; border-bottom: 1px solid var(--border-light); background: var(--bg); }
.msg-attachments .attachments-header { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; }
.attachment-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.att-download {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: var(--radius-sm); font-size: 13px;
    background: var(--surface); border: 1px solid var(--border);
    text-decoration: none !important; color: var(--text);
    transition: all var(--transition);
}
.att-download:hover { border-color: var(--primary); color: var(--primary); }
.att-size { color: var(--text-muted); font-size: 11px; }

.msg-body-container { padding: 24px; }
.msg-body { font-size: 14px; line-height: 1.7; word-wrap: break-word; overflow-wrap: break-word; }
.msg-body img { max-width: 100%; height: auto; }
.msg-body blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }
.msg-body pre { background: var(--bg); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; font-family: var(--mono); font-size: 13px; }

/* ── Admin ──────────────────────────────────────────────────────────────── */
.admin-page { max-width: 1000px; margin: 0 auto; padding: 20px; }
.admin-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.admin-header h2 { font-size: 20px; }

.admin-grid { display: grid; gap: 20px; }
.admin-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px;
}
.admin-card h3 { font-size: 15px; margin-bottom: 16px; color: var(--text); }

.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px;
}
.stat-item { padding: 12px; border-radius: var(--radius-sm); background: var(--bg); text-align: center; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }

.inline-form {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border-light);
}
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 100px; padding: 7px 10px; font-size: 13px; }
.at-symbol { color: var(--text-secondary); font-size: 13px; white-space: nowrap; }

.admin-list { font-size: 13px; }
.admin-list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.admin-list-item:hover { background: var(--surface-hover); }
.admin-list-item + .admin-list-item { border-top: 1px solid var(--border-light); }
.admin-item-info { flex: 1; min-width: 0; }
.admin-item-main { font-weight: 500; }
.admin-item-sub { font-size: 12px; color: var(--text-secondary); }
.admin-item-badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.admin-item-badge.admin { background: var(--primary-light); color: var(--primary); }
.admin-item-badge.user { background: var(--bg); color: var(--text-secondary); }
.admin-item-badge.online { background: var(--success-light); color: var(--success); }
.admin-item-badge.offline { background: var(--danger-light); color: var(--danger); }

.config-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.config-table td { padding: 6px 0; }
.config-table td:first-child { font-weight: 500; color: var(--text-secondary); width: 180px; }
.config-table td:last-child { color: var(--text); }

/* ── Setup Guide ───────────────────────────────────────────────────────── */
.setup-checklist { display: flex; flex-direction: column; gap: 12px; }
.setup-step { border: 1px solid var(--border-light); border-radius: var(--radius-sm); overflow: hidden; }
.step-header {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; background: var(--surface-hover); cursor: pointer;
}
.step-header:hover { background: var(--bg); }
.step-num {
    display: flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: 12px; font-weight: 700;
    flex-shrink: 0;
}
.step-title { flex: 1; font-size: 13px; font-weight: 600; }
.step-badge {
    font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500;
}
.step-badge.pending { background: var(--warning-light); color: var(--warning); }
.step-badge.done { background: var(--success-light); color: var(--success); }
.step-body {
    padding: 12px 14px; font-size: 13px; color: var(--text-secondary);
    border-top: 1px solid var(--border-light);
}
.step-body ol { padding-left: 20px; line-height: 1.8; margin: 4px 0; }
.step-body p { margin: 4px 0 8px; }
.dns-table { width: 100%; font-size: 12px; border-collapse: collapse; margin: 8px 0; }
.dns-table th { text-align: left; padding: 6px 8px; background: var(--bg); font-weight: 600; border-bottom: 2px solid var(--border); }
.dns-table td { padding: 6px 8px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
.dns-table code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 11px; word-break: break-all; }

/* ── Integration / Code Blocks ──────────────────────────────────────────── */
.integration-method h4 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.integration-method p { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.code-block {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 12px; overflow: hidden;
}
.code-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 12px; background: var(--surface-hover);
    font-size: 12px; font-weight: 600; color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
}
.btn-copy {
    font-size: 11px; padding: 2px 8px; border-radius: 4px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text-secondary);
    cursor: pointer;
}
.btn-copy:hover { background: var(--primary-light); color: var(--primary); }
.code-block pre {
    margin: 0; padding: 12px; font-size: 12px; line-height: 1.6;
    background: #1e1e2e; color: #cdd6f4; overflow-x: auto;
    font-family: var(--mono); white-space: pre-wrap; word-break: break-word;
}

/* ── Relay Config Form ──────────────────────────────────────────────────── */
.relay-grid {
    display: grid; grid-template-columns: 1fr 120px; gap: 12px;
    margin-bottom: 12px;
}
.relay-grid .form-group { margin-bottom: 0; }
.relay-grid input { font-size: 13px; padding: 8px 10px; }
.relay-grid label { font-size: 12px; }
.relay-current-info {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-radius: var(--radius-sm);
    background: var(--success-light); border: 1px solid #b2f2bb;
    font-size: 13px; color: var(--success);
}
.relay-current-info.not-configured {
    background: var(--warning-light); border-color: #ffe066; color: var(--warning);
}
details summary { outline: none; }
details[open] summary { margin-bottom: 4px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; font-family: var(--mono); }

/* ── Auth Tabs ──────────────────────────────────────────────────────────── */
.auth-tabs {
    display: flex; gap: 0; margin-bottom: 20px;
    border-bottom: 2px solid var(--border);
}
.auth-tab {
    flex: 1; padding: 10px 16px; border: none; background: none;
    font-size: 14px; font-weight: 500; color: var(--text-muted);
    cursor: pointer; transition: all 0.15s;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Registration Badges ───────────────────────────────────────────────── */
.admin-item-badge.pending { background: #fff3cd; color: #856404; }
.admin-item-badge.rejected { background: #f8d7da; color: #721c24; }
.admin-item-badge.approved, .admin-item-badge.admin { background: #d4edda; color: #155724; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -100%; z-index: 100; height: 100vh; transition: left 0.2s; }
    .sidebar.open { left: 0; }
    .search-box input { width: 120px; }
    .compose-field { flex-direction: column; align-items: stretch; }
    .compose-field label { padding: 8px 16px 0; }
    .compose-field input { padding: 8px 16px; }
    .inline-form { flex-direction: column; }
    .inline-form input, .inline-form select { width: 100%; }
}
