:root {
    --sidebar-width: 260px;
    --list-width: 360px;
}

/* Global */

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f3f3f3;
    overflow: hidden;   /* IMPORTANT: no page scroll */
}

#app {
    height: 100%;
}

/* Login */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.login-box {
    background: #fff;
    padding: 24px 28px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    width: 320px;
}

.login-box h1 {
    margin: 0 0 16px;
    font-size: 20px;
    color: #333;
}

.login-box label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
}

.login-box input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    margin-top: 4px;
    margin-bottom: 12px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.login-box button {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 4px;
    background: #0078d4;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.login-box button:hover {
    background: #005fa3;
}

.error {
    background: #ffe5e5;
    color: #b30000;
    padding: 8px;
    margin-bottom: 12px;
    border-radius: 4px;
    font-size: 13px;
}

/* Top bar */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f7f7f7;
    border-bottom: 1px solid #d6d6d6;
    color: #333;
    padding: 6px 12px;
    font-size: 14px;
}

.topbar-left {
    display: flex;
    align-items: center;
}

.app-title {
    font-weight: 600;
    margin-right: 12px;
}

.user-email {
    font-size: 13px;
    color: #555;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-right button,
.logout-btn {
    padding: 4px 10px;
    border-radius: 2px;
    background: #ffffff;
    border: 1px solid #d0d0d0;
    font-size: 13px;
    cursor: pointer;
    color: #333;
    text-decoration: none;
}

.topbar-right button:hover,
.logout-btn:hover {
    background: #e6f1fb;
}

/* Layout (3 resizable panels) */

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 4px var(--list-width) 4px 1fr;
    height: calc(100vh - 40px);   /* header is ~40px */
}

/* Dividers */

.divider {
    background: transparent;
    cursor: col-resize;
}

.divider:hover {
    background: #ddd;
}

/* Sidebar (folders) */

.sidebar {
    background: #fafafa;
    border-right: 1px solid #e0e0e0;
    padding: 8px 8px 4px;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 14px;
    color: #555;
}

.icon-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
    padding: 0;
    line-height: 18px;
    text-align: center;
}

.icon-btn:hover {
    background: #e6f1fb;
}

#folderList {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

#folderList li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    cursor: pointer;
}

/* base indent */
#folderList li .folder-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* depth 0 = top level, depth 1,2,3… are subfolders */
#folderList li.depth-0 .folder-label { padding-left: 0; }
#folderList li.depth-1 .folder-label { padding-left: 14px; }
#folderList li.depth-2 .folder-label { padding-left: 28px; }
#folderList li.depth-3 .folder-label { padding-left: 42px; }
/* add more if needed */

#folderList li.active {
    background: #e5f1fb;
    border-left: 3px solid #0078d4;
}

#folderList li:hover:not(.active) {
    background: #f0f0f0;
}

.folder-toggle {
    width: 14px;
    text-align: center;
    font-size: 11px;
    color: #666;
    user-select: none;
}

.folder-toggle.no-toggle {
    opacity: 0;          /* keep alignment, but no visible caret */
    cursor: default;
}

#folderList li .folder-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* extra margin so text isn’t stuck to the caret */
    margin-left: 4px;
}

#folderList li .folder-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

#folderList li:hover .folder-actions {
    opacity: 1;
}


.folder-btn {
    border: none;
    background: none;
    padding: 0 2px;
    cursor: pointer;
    font-size: 13px;
    color: #666;
}

.folder-btn:hover {
    color: #000;
}

.sidebar-footer-note {
    font-size: 11px;
    color: #777;
    padding-top: 4px;
    margin-bottom: 17px;
}

/* Message list (panel 2) */

/* Panel 2: message list */
.message-list {
    border-right: 1px solid #e0e0e0;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;      /* IMPORTANT for scrolling */
}

#messageList {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1;
    overflow-y: auto;   /* scroll INSIDE panel 2 */
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid #eee;
}

.list-header h3 {
    margin: 0;
    font-size: 15px;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
}

.pagination button {
    padding: 2px 6px;
    font-size: 12px;
    border-radius: 2px;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: default;
}

#messageList {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.message-item {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f1f1;
    cursor: pointer;
}

.message-item.selected {
    background: #e5f1fb;
}

.message-item:hover {
    background: #DAE2F0;
}

.msg-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    margin-bottom: 4px;
}

.msg-from {
    font-weight: 600;
    max-width: 60%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.msg-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.msg-date {
    font-size: 11px;
    color: #333;
    white-space: nowrap;
}

.msg-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.12s ease-in-out;
}

.message-item:hover .msg-actions {
    opacity: 1;
}

.msg-icon {
    width: 22px;
    height: 22px;
    border-radius: 11px;
    border: 1px solid #d0d7e6;
    background: #eef3fa;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    cursor: pointer;
}

.msg-icon.archive {
    background: #eef7ff;
}

.msg-icon.trash {
    background: #fdeaea;
    border-color: #f2b3b3;
}

.msg-icon:hover {
    filter: brightness(0.9);
}

.message-item.unread .msg-from,
.message-item.unread .msg-subject {
    font-weight: 600;
}

.message-item.unread {
    background: lightsteelblue;
}

.msg-subject {
    font-size: 13px;
    color: #333;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.loading, .empty, .error {
    padding: 10px;
    font-size: 13px;
    color: #777;
}

/* Search bar */
.search-bar {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-bottom: 1px solid #eee;
    gap: 4px;
}

.search-input {
    flex: 1;
    border-radius: 12px;
    border: 1px solid #ccc;
    padding: 4px 8px;
    font-size: 13px;
}

.search-unread {
    border: 1px solid #ccc;
    background: #f5f5f5;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.search-unread:hover {
    background: #e9e9e9;
}

.search-unread.active {
    background: #0078d4;
    color: #fff;
    border-color: #0078d4;
}

.folder-unread {
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 10px;
    background: #4caf50 !important;
    color: #fff;
    font-size: 11px;
    text-align: center;
    margin-left: 6px;
}

.search-clear {
    border: none;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
}

.list-footer {
    border-top: 1px solid #eee;
    padding: 4px 8px;
    font-size: 11px;
    color: #666;
}


/* Panel 3: message view */
.message-view {
    background: #fafafa;
    padding: 10px;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;      /* IMPORTANT for scrolling */
}

#messageContent {
    flex: 1;
    overflow-y: auto;   /* scroll INSIDE panel 3 */
}

.message-toolbar {
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #ddd;
    display: flex;
    gap: 6px;
}

.message-toolbar button {
    padding: 4px 8px;
    border-radius: 3px;
    border: 1px solid #ccc;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
}

.message-toolbar button:disabled {
    opacity: 0.4;
    cursor: default;
}

.msg-header {
    font-size: 13px;
}

.msg-header div {
    margin-bottom: 4px;
}

.msg-body {
    font-size: 14px;
    line-height: 1.4;
}

.html-body {
    background: #fff;
    padding: 10px;
    border-radius: 4px;
}

.msg-body pre {
    white-space: pre-wrap;
    font-family: Consolas, monospace;
}

/* Empty state */

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;  /* top-ish, not bottom */
    padding-top: 80px;            /* push down a bit from very top */
    color: #777;
    text-align: center;
}


.empty-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.empty-text-title {
    font-size: 18px;
    margin-bottom: 4px;
}

.empty-text-sub {
    font-size: 13px;
    color: #0078d4;
}

/* Modals */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    width: 720px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-content.small {
    width: 420px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
    font-size: 14px;
    font-weight: 600;
}

.close-btn {
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.modal-body {
    padding: 10px 12px;
    overflow-y: auto;
}

.compose-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 8px;
}

.compose-footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compose-status {
    font-size: 12px;
    color: #555;
    opacity: 0;
    transition: opacity 0.2s;
    white-space: nowrap;
}

.compose-status.visible {
    opacity: 1;
}



.modal-footer {
    padding: 8px 12px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.modal-footer button {
    padding: 6px 12px;
    border-radius: 3px;
    border: 1px solid #ccc;
    background: #f7f7f7;
    cursor: pointer;
    font-size: 13px;
}

.modal-footer button.primary {
    background: #0078d4;
    border-color: #0078d4;
    color: #fff;
}

/* Compose */

.field-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 13px;
}

.field-row-body {
    margin-top: 8px;
}

.field-label {
    width: 60px;
    color: #555;
}

.field-value {
    flex: 1;
    padding: 4px 6px;
    background: #f7f7f7;
    border-radius: 3px;
}

.field-row input {
    flex: 1;
    padding: 4px 6px;
    border-radius: 3px;
    border: 1px solid #ccc;
}

#composeBody {
    width: 100%;
    height: 260px;
    box-sizing: border-box;
    border-radius: 3px;
    border: 1px solid #ccc;
    padding: 6px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
}

.compose-body-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.compose-toolbar {
    border-bottom: 1px solid #eee;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
}

.compose-toolbar button {
    border: 0;
    background: none;
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 3px;
}

.compose-toolbar button:hover {
    background: #f0f4ff;
}

.danger {
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 3px;
    border: 1px solid #ccc;
    cursor: pointer;
    font-size: 13px;
    background: #FF0000;
    border-color: #FF0000;
    color: #fff;
}

.toolbar-select {
    font-size: 13px;
    padding: 2px 4px;
    margin-right: 4px;
}

.color-btn {
    position: relative;
    font-weight: bold;
}

.highlight-sample {
    padding: 0 2px;
    background: #ffff99;
}

.hidden-color {
    display: none;
}

.compose-editor {
    border: 1px solid #ccc;
    border-radius: 0 0 4px 4px;
    min-height: 220px;
    max-height: 60vh;
    padding: 6px;
    overflow-y: auto;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.compose-editor blockquote.quoted {
    margin: 0.75em 0 0.75em 1em;
    padding-left: 0.75em;
    border-left: 2px solid #ccc;
    color: #555;
}


.icon-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
}

.icon-btn:hover {
    background: #e0e0e0;
}

.compose-attachments {
    border-top: 1px solid #eee;
    padding: 8px 12px;
}

.attach-icon {
    background: none;
    border: 0;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 6px;
}

.attach-icon:hover {
    background: #f0f4ff;
    border-radius: 4px;
}

/* Panel is collapsed by default */
.attachment-drop {
    margin-top: 6px;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, opacity 0.25s ease;
}

/* When open */
.attachment-drop.open {
    max-height: 220px;
    opacity: 1;
}

.attachment-drop-inner {
    border: 1px dashed #bbb;
    border-radius: 6px;
    padding: 12px 16px;
    text-align: center;
    cursor: pointer;           /* whole area shows pointer */
    background: #fafafa;
}

.attachment-drop-inner.dragover {
    background: #f0f6ff;
    border-color: #4a90e2;
}

.attachment-help {
    font-size: 12px;
    color: #777;
    margin-top: 4px;
}

.attachment-browse {
    margin-top: 8px;
    padding: 4px 12px;
    border-radius: 16px;
    border: 1px solid #4a90e2;
    background: #4a90e2;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
}

.attachment-browse:hover {
    background: #336fbd;
}

.attachment-list {
    list-style: none;
    padding: 6px 0 0;
    margin: 0;
    text-align: left;
    font-size: 13px;
}

.attachment-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
}

.attachment-remove {
    cursor: pointer;
    color: #c00;
    margin-left: 8px;
}


.compose-options-row {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 4px 0 8px;
    font-size: 13px;
}

.compose-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.compose-toggle input[type="checkbox"] {
    cursor: pointer;
}

.compose-priority {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.compose-priority select {
    font-size: 13px;
    padding: 2px 6px;
}


#signatureText {
    width: 100%;
    box-sizing: border-box;
    border-radius: 3px;
    border: 1px solid #ccc;
    padding: 6px;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
}

.signature-editor {
    width: 100%;
    min-height: 120px;
    box-sizing: border-box;
    border-radius: 3px;
    border: 1px solid #ccc;
    padding: 6px;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
    overflow-y: auto;
}

.signature-editor:focus {
    outline: 1px solid #0078d4;
}

.signature-hint {
    margin-top: 4px;
    font-size: 11px;
    color: #666;
}


/* Responsive */

@media (max-width: 900px) {
    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 40% 60%;
    }
    .sidebar {
        display: none;
    }
    .message-list {
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
    .modal-content {
        width: 95vw;
    }
}


.global-status {
    position: fixed;
    right: 20px;
    bottom: 20px;
    padding: 10px 16px;
    background: rgba(80, 88, 95, 0.96);
    color: #fff;
    border-radius: 4px;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 9999;
}

.global-status.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Full-area loading wrapper inside the message pane */
.message-loading {
    height: 100%;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

/* The small card that contains spinner + text */
.message-loading-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    background: #ffffff;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    border: 1px solid #e2e5ea;
    max-width: 360px;
}

/* Circular spinner */
.message-loading-spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid #d4d9e2;
    border-top-color: #3b82f6;         /* accent color */
    animation: message-loading-spin 0.8s linear infinite;
}

/* Text next to spinner */
.message-loading-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message-loading-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
}

.message-loading-subtitle {
    font-size: 12px;
    color: #6b7280;
}

/* Spinner animation */
@keyframes message-loading-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}



.outbox-queue-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    margin-bottom: 10px;
    background: #fff3cd;
    border: 1px solid #ffeeba;
    border-radius: 4px;
    font-size: 13px;
    color: #856404;
}

.outbox-queue-main {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}

.outbox-queue-countdown {
    font-weight: 600;
}

.outbox-queue-actions {
    display: flex;
    gap: 8px;
}

.outbox-row-actions {
    margin: 4px 0 0 0;
    padding-left: 12px;
    display: flex;
    gap: 6px;
}

.btn-outbox-undo,
.btn-outbox-delete {
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid #d0d0d0;
    background: #fff;
    cursor: pointer;
}

.btn-outbox-sendnow {
    border-radius: 3px;
    border: 1px solid transparent;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}

.btn-outbox-undo {
    border-color: #2f855a;
    color: #2f855a;
}

.btn-outbox-delete {
    border-color: #e53e3e;
    color: #e53e3e;
}

.btn-outbox-sendnow {
    background: #007bff;
    border-color: #007bff;
    color: #ffffff;
}

/* small countdown pill in Outbox list */
.outbox-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    background: #ffe9b3;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.outbox-pill-label {
    opacity: 0.8;
}




