/* Emlup Mail – Live.com-style webmail */
:root {
    --bg-app: #f3f3f3;
    --bg-sidebar: #faf9f8;
    --bg-header: #fff;
    --bg-list: #fff;
    --bg-read: #fff;
    --border: #edebe9;
    --text: #323130;
    --text-muted: #605e5c;
    --accent: #0078d4;
    --accent-hover: #106ebe;
    --accent-light: #e6f2fa;
    --unread: #fff;
    --shadow: rgba(0,0,0,.06);
    --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}
body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text);
    background: var(--bg-app);
    line-height: 1.4;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0d3b5c 0%, #1a5f7a 50%, #159895 100%);
}
.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: var(--bg-header);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.login-header {
    margin-bottom: 1.5rem;
}
.login-header h1 {
    margin: 0 0 .25rem;
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text);
}
.login-header p {
    margin: 0;
    color: var(--text-muted);
}
.login-error {
    padding: .75rem;
    margin-bottom: 1rem;
    background: #fde7e9;
    color: #a4262c;
    border-radius: 4px;
}
.login-form label {
    display: block;
    margin: 1rem 0 .35rem;
    font-weight: 500;
    color: var(--text);
}
.login-form input {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
}
.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}
.login-form .btn-primary {
    width: 100%;
    margin-top: 1.5rem;
    padding: .65rem 1rem;
}

/* Buttons */
.btn-primary {
    padding: .5rem 1.25rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary:hover {
    background: var(--accent-hover);
}
.btn-secondary {
    padding: .5rem 1rem;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
}
.btn-secondary:hover {
    background: var(--bg-app);
}

/* App layout */
.app-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 48px;
    padding: 0 1rem;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.btn-menu {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: .25rem;
}
.app-logo {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}
.app-header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
}
.user-email {
    color: var(--text-muted);
    font-size: 13px;
}
.btn-logout {
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
}
.btn-logout:hover {
    text-decoration: underline;
}

.app-sidebar {
    position: fixed;
    left: 0;
    top: 48px;
    bottom: 0;
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: .75rem 0;
    z-index: 10;
}
.app-sidebar.collapsed {
    transform: translateX(-100%);
}

.nav-app-switcher {
    display: flex;
    margin: 0 .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg-list);
}
.nav-app-link {
    flex: 1;
    padding: .5rem .75rem;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
}
.nav-app-link:hover {
    color: var(--text);
    background: var(--bg-app);
}
.nav-app-link.active {
    color: #fff;
    background: var(--accent);
}

.btn-compose {
    width: calc(100% - 1rem);
    margin: 0 .5rem .75rem;
    padding: .6rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
}
.btn-compose:hover {
    background: var(--accent-hover);
}
.nav-section {
    margin-bottom: 1rem;
}
.nav-title {
    margin: 0 1rem .5rem;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.nav-folders,
.nav-contacts {
    list-style: none;
    margin: 0;
    padding: 0;
}
.nav-folders .nav-subfolder .nav-link {
    padding-left: 1.75rem;
}
.nav-link {
    display: block;
    padding: .5rem 1rem;
    color: var(--text);
    text-decoration: none;
    border-left: 3px solid transparent;
}
.nav-link:hover {
    background: var(--bg-app);
}
.nav-link.active {
    background: var(--accent-light);
    border-left-color: var(--accent);
    font-weight: 600;
}
.btn-add-contact {
    margin: .5rem 1rem 0;
    padding: .35rem .5rem;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    cursor: pointer;
}
.btn-add-contact:hover {
    text-decoration: underline;
}
.btn-add-folder {
    margin: .5rem 1rem 0;
    padding: .35rem .5rem;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}
.btn-add-folder:hover {
    text-decoration: underline;
}

.app-main {
    flex: 1;
    display: flex;
    margin-left: 240px;
    min-width: 0;
    overflow: hidden;
}
/* Only one of mail or calendar is visible; hidden panes must not take space */
.app-main .calendar-pane[hidden],
.app-main .message-list-pane[hidden],
.app-main .read-pane[hidden] {
    display: none !important;
}
.app-sidebar.collapsed ~ .app-main {
    margin-left: 0;
}

.message-list-pane {
    width: 320px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
    background: var(--bg-list);
    border-right: 1px solid var(--border);
    overflow: hidden;
}
.message-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem 1rem;
    border-bottom: 1px solid var(--border);
}
.folder-name {
    font-weight: 600;
}
.btn-refresh {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: .25rem;
}
.btn-refresh:hover {
    color: var(--accent);
}
.message-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}
.message-list li {
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}
.message-list li a {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: .65rem 1rem;
    color: var(--text);
    text-decoration: none;
}
.message-list li a:hover {
    background: var(--bg-app);
}
.message-list li.unread a {
    background: var(--unread);
    font-weight: 600;
}
.message-list li.selected a {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
    padding-left: calc(1rem - 3px);
}
.message-list .msg-subject {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.message-list .msg-from {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: .15rem;
}
.message-list .msg-delete {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    padding: 0;
    margin: 0 .25rem;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.message-list .msg-delete:hover {
    color: #a4262c;
    background: #fde7e9;
}
.message-list-empty,
.message-list-loading {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
}
.message-list-loading {
    display: none;
}
.message-list-loading.visible {
    display: block;
}

.read-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-read);
    overflow: hidden;
    min-width: 0;
}
.read-pane-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.read-pane-empty[hidden],
.read-pane-message[hidden] {
    display: none !important;
}
.read-pane-message {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
}
.read-toolbar {
    display: flex;
    gap: .5rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.btn-read-action {
    padding: .4rem .85rem;
    font-size: 13px;
    font-family: inherit;
    color: var(--accent);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}
.btn-read-action:hover {
    background: var(--accent-light);
    border-color: var(--accent);
}
.btn-read-action-danger {
    color: #a4262c;
    margin-left: auto;
}
.btn-read-action-danger:hover {
    background: #fde7e9;
    border-color: #a4262c;
}
.read-header {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.read-subject {
    margin: 0 0 .5rem;
    font-size: 1.25rem;
    font-weight: 600;
}
.read-meta {
    font-size: 13px;
    color: var(--text-muted);
}
.read-body {
    line-height: 1.6;
}
.read-body img {
    max-width: 100%;
    height: auto;
}
.read-attachments {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}
.read-attachment-list {
    list-style: none;
    margin: .5rem 0 0;
    padding: 0;
}
.read-attachment-list li {
    margin: .25rem 0;
}
.read-attachment-list a {
    color: var(--accent);
    text-decoration: none;
}
.read-attachment-list a:hover {
    text-decoration: underline;
}

.compose-pane {
    position: absolute;
    left: 320px;
    right: 0;
    top: 0;
    bottom: 0;
    background: var(--bg-read);
    padding: 1.5rem 2rem;
    overflow-y: auto;
    box-shadow: -4px 0 16px var(--shadow);
    z-index: 5;
}
.compose-form label {
    display: block;
    margin: .75rem 0 .25rem;
    font-weight: 500;
    font-size: 13px;
}
.compose-row input[type="file"] {
    font-size: 13px;
}
.compose-attachment-list {
    margin-top: .35rem;
    font-size: 12px;
    color: var(--text-muted);
}
.compose-attachment-item {
    display: inline-block;
    margin-right: .5rem;
    margin-bottom: .25rem;
}
.compose-attachment-remove {
    margin-left: .2rem;
    padding: 0 .25em;
    font-size: 1.1em;
    line-height: 1;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 2px;
}
.compose-attachment-remove:hover {
    color: var(--text);
    background: var(--border);
}
.compose-row input,
.compose-row textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
}
.compose-body-row textarea {
    min-height: 200px;
    resize: vertical;
}

.compose-wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: .35rem 0;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    background: var(--bg-app);
}
.wysiwyg-btn {
    padding: .35rem .6rem;
    font-size: 13px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
}
.wysiwyg-btn:hover {
    background: var(--border);
}
.wysiwyg-btn[data-cmd="bold"] { font-weight: 700; }
.wysiwyg-btn[data-cmd="italic"] { font-style: italic; }
.wysiwyg-btn[data-cmd="underline"] { text-decoration: underline; }
.wysiwyg-btn[data-cmd="strikeThrough"] { text-decoration: line-through; }
.compose-wysiwyg-editor {
    min-height: 200px;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 0 0 4px 4px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    overflow-y: auto;
    outline: none;
}
.compose-wysiwyg-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
}
.compose-wysiwyg-editor p { margin: 0 0 .5em; }
.compose-wysiwyg-editor p:last-child { margin-bottom: 0; }

.compose-actions {
    margin-top: 1rem;
    display: flex;
    gap: .5rem;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal[hidden] {
    display: none !important;
}
.modal-content {
    background: var(--bg-header);
    padding: 1.5rem 2rem;
    border-radius: 8px;
    min-width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-content label {
    display: block;
    margin: .75rem 0 .25rem;
    font-weight: 500;
}
.modal-content input {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}
.modal-actions {
    margin-top: 1.25rem;
    display: flex;
    gap: .5rem;
}

@media (max-width: 900px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
    }
    .btn-menu {
        display: block;
    }
    .message-list-pane {
        width: 100%;
    }
    .read-pane {
        position: fixed;
        left: 0;
        right: 0;
        top: 48px;
        bottom: 0;
        z-index: 8;
    }
    .compose-pane {
        left: 0;
    }
}

/* Calendar */
.calendar-pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    background: var(--bg-list);
    padding: 1rem;
}
.calendar-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}
.calendar-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}
.calendar-nav {
    padding: .4rem .75rem;
    font-size: 1.25rem;
    line-height: 1;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-header);
    color: var(--text);
    cursor: pointer;
}
.calendar-nav:hover {
    background: var(--bg-app);
}
.calendar-grid-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
}
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    min-width: 320px;
}
.calendar-weekday {
    padding: .35rem .5rem;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    background: var(--bg-sidebar);
}
.calendar-day {
    min-height: 80px;
    padding: .35rem;
    background: var(--bg-list);
    font-size: 13px;
}
.calendar-day.other-month {
    background: var(--bg-app);
    color: var(--text-muted);
}
.calendar-day.today {
    background: var(--accent-light);
}
.calendar-day-num {
    font-weight: 500;
    margin-bottom: .25rem;
}
.calendar-day-events {
    list-style: none;
    margin: 0;
    padding: 0;
}
.calendar-event {
    font-size: 11px;
    padding: .15rem .35rem;
    margin-bottom: 2px;
    border-radius: 2px;
    background: var(--accent);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
