* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(128, 128, 128, 0.4);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--primary-color, rgba(128, 128, 128, 0.8));
}

body {
    background-color: var(--background-color);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    height: auto;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    width: 100%;
    max-width: 1400px;
    height: 100vh;
    background-color: var(--surface-color);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
}

.header {
    text-align: center;
    border-bottom: 2px solid var(--border-color);
    padding: 1rem;
    position: relative;
    flex-shrink: 0;
}
.header img{
    width: 100px;
}

.header h1 {
    color: var(--primary-color);
    font-size: 1.6rem;
}

#darkMode {
    position: absolute;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 1.2rem;
}

.email-settings {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 10px 2.5rem;
    background-color: var(--background-color);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

#emailShow {
    display: flex;
    align-items: center;
    gap: 8px;
}

#emailShow i {
    display: inline-block;
    font-size: 1rem;
    color: var(--text-color, inherit);
}

.emailBtns {
    display: flex;
    gap: 10px;
}

.emailBtns .btn {
    width: 200px;
    color: var(--primary-color);
    background-color: var(--border-color);
    border: none;
    padding: 6px 12px;
    cursor: pointer;
}
.main-layout {
    display: flex;
    gap: 2.5rem;
    padding: 2rem 2.5rem;
    height: calc(100vh - 120px); 
    overflow: hidden;
    align-items: stretch;
}

.sidebar {
    width: 22%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    height: 100%;
}

.sidebar h3 {
    color: var(--text-primary);
    font-size: 1.05rem;
    margin-bottom: 0.2rem;
    flex-shrink: 0;
}

.template {
    flex-grow: 1;
    overflow-y: auto;
    border-radius: 6px;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 12px;
}

.template div {
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 8px;
    transition: background-color 0.2s, color 0.2s;
}

.template div:hover,
.template .active {
    background-color: var(--primary-color);
    color: var(--surface-color);
}

.createTemplateOption {
    background-color: var(--secondary-color) !important;
    color: var(--surface-color) !important;
    font-weight: bold;
    text-align: center;
}

#showTemplate {
    width: 78%;
    display: flex;
    gap: 2.5rem;
    height: 100%;
    overflow: hidden;
}

form {
    flex: 3;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    height: 100%;
    flex-shrink: 0; 
    overflow-y: auto;
    padding-right: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.85rem;
}

#templateTitleGroup {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

input[type="text"],
input[type="file"],
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(126, 87, 194, 0.15);
}

textarea {
    min-height: 130px;
    resize: vertical;
}

.files { display: none; }

.file-upload-wrapper {
    display: flex;
    align-items: center;
}

.custom-file-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.65rem 1rem;
    background-color: var(--primary-color);
    color: var(--surface-color);
    border-radius: 6px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.custom-file-button:hover { opacity: 0.9; }

.file-list-container {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    height: 105px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--primary-color);
    background-color: var(--input-bg);
    margin-top: 3px;
    flex-shrink: 0;
}

.file-item button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--error-color);
    font-weight: bold;
    font-size: 0.9rem;
}

.rightSideBar {
    flex: 1; 
    display: flex;
    flex-direction: column;
    gap: 15px; 
    height: 100%;
    overflow-y: auto;
    padding-right: 10px;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    flex-shrink: 0;
}

.btn, .createTemplate, .deleteBtn {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    font-weight: bold;
    color: var(--surface-color);
    transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
}

.btn:hover, .createTemplate:hover, .deleteBtn:hover {
    opacity: 0.95;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn:active { transform: scale(0.98); }

.createTemplate { background-color: var(--secondary-color); }
.deleteBtn { background-color: var(--error-color); }
#updateTemplate { background-color: var(--warning-color); color: var(--text-primary); }
#reviewSend { background-color: var(--accent-color); }
#quickSend { background-color: var(--success-color); }

.history,
.rules {
    width: 100%;
    height: 250px;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--background-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history p,
.rules p {
    margin: 0;
    padding: 10px 15px;
    font-weight: bold;
    font-size: 1rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-color);
    flex-shrink: 0;
}

.history span {
    text-align: center;
    background-color: var(--error-color);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    font-weight: bold;
    color: white;
    padding: 5px;
    flex-shrink: 0;
}

#historyList,
#ruleList {
    margin: 0;
    padding: 10px;
    list-style: none;
    flex-grow: 1; 
    overflow-y: auto;
    overflow-x: hidden;
}

.history li,
.rules li {
    list-style: none;
    font-size: 0.9rem;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
    padding-bottom: 5px;
    color: var(--text-color);
    white-space: normal;
    word-wrap: break-word; 
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: auto;
}

#historyList li:last-child,
#ruleList li:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.custom-modal-overlay {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh;
    background: rgba(0,0,0,0.5); 
    display: flex; 
    align-items: center; 
    justify-content: center;
    z-index: 10000; 
    opacity: 0; 
    transition: opacity 0.3s ease;
}

.custom-modal-overlay.show { opacity: 1; }

.custom-modal-box {
    background: var(--surface-color, #fff); 
    color: var(--text-primary, #333);
    padding: 25px; 
    border-radius: 8px; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    min-width: 320px; 
    max-width: 400px; 
    transform: scale(0.9); 
    transition: transform 0.3s ease;
}

.custom-modal-overlay.show .custom-modal-box { transform: scale(1); }
.custom-modal-message { margin-top: 0; margin-bottom: 20px; font-size: 1rem; line-height: 1.4; }
.custom-modal-buttons { display: flex; justify-content: flex-end; gap: 10px; }
.custom-modal-btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; font-weight: 600; transition: background 0.2s; }
.custom-modal-btn.cancel { background: #e5e7eb; color: #374151; }
.custom-modal-btn.cancel:hover { background: #d1d5db; }
.custom-modal-btn.confirm { background: #3B82F6; color: #fff; }
.custom-modal-btn.confirm:hover { background: #2563EB; }

.custom-modal-input {
    width: 100%; 
    padding: 10px; 
    margin-bottom: 15px; 
    border: 1px solid var(--border-color);
    border-radius: 4px; 
    box-sizing: border-box; 
    display: block;
    background-color: var(--input-bg);
    color: var(--text-primary);
}

/* RESPONSIVE */
@media (max-width: 1200px) {
    .main-layout {
        gap: 1.5rem;
        padding: 1.5rem;
    }

    .emailBtns .btn {
        width: 150px;
    }
}

@media (max-width: 992px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        align-items: flex-start;
    }

    .container {
        height: auto;
        min-height: 100vh;
    }

    .main-layout {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        height: auto;
    }

    .template {
        max-height: 220px;
    }

    #showTemplate {
        width: 100%;
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    form {
        height: auto;
        overflow-y: visible;
        padding-right: 0;
    }

    .rightSideBar {
        height: auto;
        overflow-y: visible;
        padding-right: 0;
    }

    .history,
    .rules {
        height: 200px;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1.3rem;
    }

    .header img {
        width: 70px;
    }

    #darkMode {
        right: 16px;
        font-size: 1.1rem;
    }

    .email-settings {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 1.25rem;
        gap: 10px;
    }

    #emailShow {
        justify-content: center;
    }

    .emailBtns {
        justify-content: center;
        flex-wrap: wrap;
    }

    .emailBtns .btn {
        width: 100%;
        flex: 1 1 45%;
    }

    .main-layout {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0.75rem;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .emailBtns {
        flex-direction: column;
    }

    .emailBtns .btn {
        width: 100%;
    }

    .custom-modal-box {
        min-width: 0;
        width: 90%;
        padding: 18px;
    }

    .file-list-container {
        height: 90px;
    }

    .history,
    .rules {
        height: 160px;
    }
}