*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    min-height: 100vh;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: #1a1a2e;
    color: #fff;
}

.brand {
    font-weight: 600;
    font-size: 1.1rem;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.username {
    opacity: 0.85;
    font-size: 0.9rem;
}

.inline-form {
    display: inline;
    margin: 0;
}

.btn {
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
    display: inline-block;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.btn-primary {
    background: #4361ee;
    color: #fff;
}

.btn-primary:hover {
    background: #3651d4;
}

.btn-secondary {
    background: #e9ecef;
    color: #1a1a2e;
}

.btn-secondary:hover {
    background: #dee2e6;
}

.btn-danger {
    background: #e63946;
    color: #fff;
}

.btn-ms {
    background: #2f2f2f;
    color: #fff;
}

.btn-ms:hover {
    background: #1a1a1a;
}

.flash-container {
    padding: 0.5rem 1.5rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.flash-error {
    background: #fde8e8;
    color: #9b1c1c;
}

.flash-success {
    background: #def7ec;
    color: #03543f;
}

.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 60px);
    padding: 2rem;
}

.auth-card {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    font-weight: 500;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

input[readonly] {
    background: #f8f9fa;
    color: #495057;
    cursor: default;
}

textarea {
    resize: vertical;
    font-family: inherit;
}

.admin-page {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.admin-section {
    background: #fff;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.admin-form {
    max-width: 400px;
}

.admin-form-wide {
    max-width: 560px;
}

.admin-tab-bar {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid #dee2e6;
}

.admin-tab {
    display: inline-block;
    padding: 0.65rem 1.25rem;
    text-decoration: none;
    color: #495057;
    font-size: 0.95rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.admin-tab:hover {
    color: #4361ee;
    background: #f8f9fa;
}

.admin-tab.active {
    color: #4361ee;
    border-bottom-color: #4361ee;
}

.admin-warning {
    margin-top: 1rem;
    margin-bottom: 0;
}

.admin-actions-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.admin-actions-cell .inline-form {
    margin: 0;
}

.denial-label-input {
    width: 100%;
    max-width: 14rem;
    padding: 0.35rem 0.5rem;
    font-size: 0.875rem;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

.denied-page {
    min-height: calc(100vh - 52px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.denied-page h1 {
    font-size: 4rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: #dc3545;
    margin: 0;
}

.admin-form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.user-table {
    width: 100%;
    border-collapse: collapse;
}

.user-table th,
.user-table td {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid #e9ecef;
}

.user-table th {
    font-weight: 600;
    background: #f8f9fa;
}

.mail-app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px);
}

.tab-bar {
    display: flex;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0 0.5rem;
    min-height: 44px;
}

.tabs {
    display: flex;
    flex: 1;
    overflow-x: auto;
}

.tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border: none;
    background: transparent;
    cursor: grab;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    font-size: 0.9rem;
    user-select: none;
}

.tab.tab-dragging {
    opacity: 0.55;
    cursor: grabbing;
}

.tab.tab-drag-over {
    background: #eef2ff;
    border-bottom-color: #4361ee;
}

.tab:hover {
    background: #f8f9fa;
}

.tab.active {
    border-bottom-color: #4361ee;
    color: #4361ee;
    font-weight: 500;
}

.tab.tab-has-new .tab-label {
    font-weight: 700;
}

.tab.active.tab-has-new .tab-label {
    font-weight: 700;
}

.tab-close {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.5;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.15rem;
    flex-shrink: 0;
}

.tab-close:hover {
    opacity: 1;
    color: #e63946;
}

.tab-add {
    width: 36px;
    height: 36px;
    border: 1px dashed #adb5bd;
    border-radius: 6px;
    background: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    margin: 0 0.5rem;
    flex-shrink: 0;
}

.tab-add:hover {
    border-color: #4361ee;
    color: #4361ee;
}

.mail-workspace {
    flex: 1;
    overflow: hidden;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6c757d;
}

.mail-panes {
    display: flex;
    height: 100%;
    background: #fff;
}

.folder-pane {
    width: 200px;
    flex-shrink: 0;
    border-right: 1px solid #dee2e6;
    padding: 1rem;
    overflow-y: auto;
}

.message-list-pane {
    width: var(--list-pane-width, 320px);
    min-width: 180px;
    max-width: 65%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pane-resizer {
    width: 6px;
    flex-shrink: 0;
    cursor: col-resize;
    background: #e9ecef;
    transition: background 0.15s;
    position: relative;
    z-index: 2;
}

.pane-resizer:hover,
.pane-resizer.dragging {
    background: #4361ee;
}

.pane-resizer::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -3px;
    right: -3px;
}

.message-detail-pane {
    flex: 1;
    min-width: 200px;
    overflow-y: auto;
    padding: 1.5rem;
}

.folder-pane h3 {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #6c757d;
}

#folder-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#folder-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.folder-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
}

.folder-row:hover {
    background: #f8f9fa;
}

.folder-row.active {
    background: #eef2ff;
    color: #4361ee;
    font-weight: 500;
}

.folder-toggle {
    width: 1.1rem;
    flex-shrink: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #6c757d;
    font-size: 0.7rem;
    padding: 0;
    line-height: 1;
}

.folder-toggle.empty {
    visibility: hidden;
}

.folder-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-children {
    margin-left: 0.75rem;
    border-left: 1px solid #e9ecef;
}

.message-list-pane {
    border-right: none;
}

.pane-toolbar {
    padding: 0.5rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.pane-toolbar-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2rem;
}

.pane-toolbar-search-row .msg-search {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.875rem;
}

.pane-toolbar .msg-sort {
    position: absolute;
    top: 0;
    right: 0;
    width: fit-content;
    padding: 0.35rem 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.875rem;
    background: #fff;
}

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

.message-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}

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

.msg-select-label {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding-top: 0.1rem;
    cursor: pointer;
}

.msg-select-label input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.message-item-content {
    flex: 1;
    min-width: 0;
}

#btn-delete-selected:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.message-item.active {
    background: #eef2ff;
}

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

.msg-subject {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-meta {
    font-size: 0.8rem;
    color: #6c757d;
    display: flex;
    justify-content: space-between;
}

.detail-meta {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.meta-row {
    display: grid;
    grid-template-columns: 3.5rem 1fr;
    gap: 0.5rem;
    align-items: start;
}

.meta-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
    padding-top: 0.15rem;
}

.meta-value {
    font-size: 0.95rem;
    color: #1a1a2e;
}

.recipient-block {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.recipient-name {
    font-weight: 600;
    color: #1a1a2e;
}

.recipient-email {
    font-size: 0.88rem;
    color: #4361ee;
    word-break: break-all;
}

.recipient-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.recipient-list .recipient-block + .recipient-block {
    padding-top: 0.25rem;
    border-top: 1px solid #f0f0f0;
}

.message-detail.empty-detail {
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.detail-header {
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.detail-subject {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
}

.detail-date {
    font-size: 0.88rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.detail-attachments {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
}

.detail-attachments-title {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.attachment-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.attachment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    text-decoration: none;
    color: #1a1a2e;
}

.attachment-item:hover {
    border-color: #4361ee;
    background: #eef2ff;
}

.attachment-item-disabled {
    opacity: 0.75;
    cursor: default;
}

.attachment-name {
    font-size: 0.9rem;
    font-weight: 500;
    word-break: break-all;
}

.attachment-size {
    font-size: 0.8rem;
    color: #6c757d;
    white-space: nowrap;
}

.msg-attach-indicator {
    display: inline-block;
    width: 0.65rem;
    height: 0.85rem;
    margin-right: 0.35rem;
    border: 2px solid #6c757d;
    border-radius: 2px 2px 0 0;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.compose-attachments {
    margin-bottom: 1rem;
}

.compose-autocomplete-wrap {
    position: relative;
    margin-bottom: 1rem;
}

.compose-autocomplete-wrap input {
    margin-bottom: 0;
}

.compose-autocomplete {
    position: absolute;
    z-index: 10;
    top: 100%;
    left: 0;
    right: 0;
    list-style: none;
    margin: 0.15rem 0 0;
    padding: 0.25rem 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 12rem;
    overflow-y: auto;
}

.compose-autocomplete.hidden {
    display: none;
}

.compose-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.compose-autocomplete-pick {
    flex: 1;
    background: none;
    border: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    color: #1a1a2e;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compose-autocomplete-pick:hover {
    background: #eef2ff;
    color: #4361ee;
}

.compose-autocomplete-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    color: #dc3545;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    border-radius: 4px;
}

.compose-autocomplete-remove:hover {
    background: #fee;
}

.compose-dropzone {
    border: 2px dashed #ced4da;
    border-radius: 8px;
    padding: 1.25rem 1rem;
    text-align: center;
    background: #f8f9fa;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.compose-dropzone:hover,
.compose-dropzone.drag-over {
    border-color: #4361ee;
    background: #eef2ff;
}

.compose-dropzone-text {
    margin: 0;
    font-size: 0.9rem;
    color: #6c757d;
}

.compose-dropzone-browse {
    background: none;
    border: none;
    padding: 0;
    color: #4361ee;
    font-size: inherit;
    cursor: pointer;
    text-decoration: underline;
}

.compose-attachment-list {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.compose-attachment-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

.compose-attachment-item .attachment-name {
    flex: 1;
}

.compose-attach-remove {
    background: none;
    border: none;
    color: #dc3545;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
}

.compose-attach-remove:hover {
    background: #fee;
}

.msg-attach-indicator::after {
    content: "";
    position: absolute;
    top: -5px;
    left: 50%;
    width: 8px;
    height: 5px;
    transform: translateX(-50%);
    border: 2px solid #6c757d;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
}

.detail-body {
    line-height: 1.6;
    font-size: 0.95rem;
}

.detail-body-html {
    margin-top: 0.25rem;
}

.message-body-frame {
    display: block;
    width: 100%;
    min-height: 120px;
    border: none;
    background: transparent;
}

body.resizing-panes {
    cursor: col-resize;
    user-select: none;
}

.hidden {
    display: none !important;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.modal-content {
    position: relative;
    background: #fff;
    padding: 1.5rem;
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-lg {
    max-width: 900px;
}

.modal-sm {
    max-width: 420px;
}

.confirm-message {
    color: #495057;
    line-height: 1.5;
    margin: 0 0 1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.field-hint {
    font-size: 0.8rem;
    color: #6c757d;
    margin: -0.5rem 0 1rem;
    line-height: 1.4;
}

.form-error {
    color: #e63946;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.loading {
    padding: 1rem;
    text-align: center;
    color: #6c757d;
}

@media (max-width: 900px) {
    .folder-pane,
    .message-list-pane,
    .pane-resizer {
        display: none;
    }

    .message-detail-pane {
        width: 100%;
    }
}
