* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0d1117;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 16px;
}

.app { width: 100%; max-width: 820px; }

/* Header */
.header { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.header-icon {
    width: 46px; height: 46px;
    background: linear-gradient(135deg, #1a3a6e, #2558b0);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; flex-shrink: 0;
}
.header-title { font-size: 22px; font-weight: 700; color: #e6edf3; }
.header-sub { font-size: 13px; color: #8b949e; margin-top: 2px; }
.header-badge {
    margin-left: auto;
    background: #1c3555; color: #79b8ff;
    font-size: 12px; font-weight: 600;
    padding: 4px 14px; border-radius: 999px;
    border: 1px solid #2c5faa; white-space: nowrap;
}

/* Tabs */
.tabs {
    display: flex; gap: 4px;
    background: #161b22; border: 1px solid #30363d;
    border-radius: 10px; padding: 4px; margin-bottom: 20px;
}
.tab-btn {
    flex: 1; padding: 9px 10px;
    background: none; border: none; border-radius: 7px;
    color: #8b949e; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all 0.15s;
    display: flex; align-items: center; justify-content: center; gap: 5px;
    width: auto;
}
.tab-btn:hover { color: #e6edf3; background: #21262d; box-shadow: none; transform: none; }
.tab-btn.active { background: #1c2a42; color: #79b8ff; box-shadow: none; transform: none; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Card */
.card {
    background: #161b22; border: 1px solid #30363d;
    border-radius: 12px; padding: 24px; margin-bottom: 16px;
}
.card-title {
    font-size: 15px; font-weight: 700; color: #e6edf3;
    margin-bottom: 20px;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    flex-wrap: wrap;
}
.card-actions { display: flex; align-items: center; gap: 6px; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #8b949e; margin-bottom: 6px; }
.req { color: #f85149; }
.hint { display: block; font-size: 11px; color: #6e7681; margin-top: 4px; }
.form-group select,
.form-group input,
.form-group textarea {
    width: 100%; padding: 10px 14px;
    background: #0d1117; border: 1px solid #30363d;
    border-radius: 8px; color: #e6edf3; font-size: 14px;
    font-family: inherit; transition: border-color 0.15s; appearance: auto;
}
.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
    outline: none; border-color: #2c6fc4;
    box-shadow: 0 0 0 3px rgba(44,111,196,0.15);
}
.form-group textarea { resize: vertical; min-height: 160px; line-height: 1.6; }

/* Buttons */
button { cursor: pointer; }
.btn-send {
    width: 100%; padding: 13px;
    background: linear-gradient(135deg, #1f6feb, #2c6fc4);
    color: #fff; border: none; border-radius: 8px;
    font-size: 15px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: all 0.18s;
}
.btn-send:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(31,111,235,0.35); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-sm {
    padding: 6px 13px; font-size: 12px; font-weight: 600;
    border: none; border-radius: 7px;
    display: inline-flex; align-items: center; gap: 4px;
    transition: all 0.15s; background: #21262d; color: #8b949e;
    width: auto;
}
.btn-sm:hover { background: #30363d; color: #e6edf3; box-shadow: none; transform: none; }
.btn-sm.blue { background: #1c2a42; color: #79b8ff; }
.btn-sm.blue:hover { background: #1f6feb; color: #fff; }
.btn-sm.danger:hover { background: #3d1c1c; color: #f85149; }

/* Filter select */
.filter-select {
    padding: 5px 10px; background: #0d1117; border: 1px solid #30363d;
    border-radius: 7px; color: #8b949e; font-size: 12px; font-family: inherit;
    appearance: auto;
}
.filter-select:focus { outline: none; border-color: #2c6fc4; }

/* Alert */
.alert {
    padding: 12px 16px; border-radius: 8px;
    font-size: 13px; font-weight: 500; margin-top: 14px; display: none;
}
.alert.success { background: #0d2a1a; border: 1px solid #238636; color: #3fb950; }
.alert.error { background: #2d0a0a; border: 1px solid #6e1a1a; color: #f85149; }

/* Message cards */
.msg-card {
    background: #0d1117; border: 1px solid #21262d;
    border-radius: 10px; padding: 14px 16px; margin-bottom: 10px;
    cursor: pointer; transition: border-color 0.15s;
}
.msg-card:hover { border-color: #2c6fc4; }
.msg-card.unread { border-left: 3px solid #1f6feb; }
.msg-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; gap: 8px; }
.msg-from { font-size: 13px; font-weight: 600; color: #e6edf3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.msg-badge { font-size: 11px; font-weight: 600; color: #79b8ff; background: #1c2a42; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.msg-time { font-size: 11px; color: #6e7681; white-space: nowrap; }
.msg-subject { font-size: 13px; font-weight: 500; color: #c9d1d9; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-preview { font-size: 12px; color: #6e7681; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; }

/* Address form */
.addr-row { display: flex; gap: 8px; align-items: stretch; margin-bottom: 14px; }
.addr-wrap {
    flex: 1; display: flex; align-items: center;
    background: #0d1117; border: 1px solid #30363d; border-radius: 8px; overflow: hidden;
}
.addr-wrap:focus-within { border-color: #2c6fc4; box-shadow: 0 0 0 3px rgba(44,111,196,0.15); }
.addr-wrap input {
    flex: 1; padding: 10px 12px;
    background: transparent; border: none;
    color: #e6edf3; font-size: 14px; font-family: inherit;
}
.addr-wrap input:focus { outline: none; }
.addr-at { padding: 10px 14px; background: #21262d; color: #8b949e; font-size: 13px; font-family: monospace; font-weight: 600; white-space: nowrap; }

/* Rule cards */
.rule-card {
    background: #0d1117; border: 1px solid #21262d;
    border-radius: 10px; padding: 13px 16px; margin-bottom: 8px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.rule-email { font-size: 14px; font-weight: 700; color: #e6edf3; font-family: monospace; }
.rule-fwd { font-size: 12px; color: #6e7681; margin-top: 3px; }

/* Empty / Loading */
.empty-state { text-align: center; padding: 48px 20px; color: #6e7681; font-size: 14px; }
.empty-icon { font-size: 36px; margin-bottom: 12px; }
.loading { text-align: center; padding: 32px; color: #6e7681; display: flex; align-items: center; justify-content: center; gap: 10px; }

/* Spinner */
.spin {
    width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.15);
    border-top-color: #79b8ff; border-radius: 50%;
    animation: rot 0.7s linear infinite; display: inline-block; flex-shrink: 0;
}
@keyframes rot { to { transform: rotate(360deg); } }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal.open { display: flex; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(4px); }
.modal-box {
    position: relative; width: 100%; max-width: 700px; max-height: 88vh;
    background: #161b22; border: 1px solid #30363d;
    border-radius: 14px; display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-head {
    padding: 18px 22px; border-bottom: 1px solid #30363d;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    border-radius: 14px 14px 0 0;
}
.modal-head h3 { font-size: 15px; color: #e6edf3; flex: 1; }
.modal-x {
    background: none; border: none; color: #6e7681; font-size: 20px;
    cursor: pointer; width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; transition: all 0.15s; width: auto; padding: 4px 8px;
}
.modal-x:hover { background: #21262d; color: #e6edf3; box-shadow: none; transform: none; }
.modal-meta { padding: 16px 22px 0; }
.mrow { display: flex; gap: 8px; font-size: 13px; color: #8b949e; margin-bottom: 6px; }
.mrow strong { color: #c9d1d9; min-width: 60px; }
.modal-hr { height: 1px; background: #21262d; margin: 14px 22px; }
.modal-body-text { padding: 0 22px 22px; overflow-y: auto; font-size: 14px; color: #c9d1d9; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.modal-iframe { width: 100%; min-height: 380px; border: none; border-radius: 0 0 14px 14px; background: #fff; flex: 1; }
