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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #212429;
    --border: #2a2a2a;
    --text-primary: #f1f1f1;
    --text-secondary: #bfbfbf;
    --text-muted: #8f98a0;
    --accent: #3a9aed;
    --accent-hover: #2a8add;
    --danger: #dc3545;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 500;
    margin: 0;
}

/* Forms */
.form-container {
    max-width: 400px;
    margin: 4rem auto;
    padding: 2rem;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
}

.form-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.form-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 0.75rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(58, 154, 237, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-secondary {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: var(--bg-card);
}

.btn-full {
    width: 100%;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.alert-error {
    background-color: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.3);
    color: #f5c6cb;
}

/* Inbox Layout */
.inbox-container {
    display: flex;
    height: calc(100vh - 60px);
}

.sidebar {
    width: 12rem;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-group {
    margin-bottom: 1.5rem;
}

.sidebar-group-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    padding: 0 0.5rem;
}

.email-list {
    list-style: none;
}

.email-item {
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.email-item:hover {
    background-color: var(--bg-card);
}

.email-item.active {
    background-color: var(--bg-card);
    font-weight: 500;
}

.email-item-subject {
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.email-item-from {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.email-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.email-header {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.email-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.email-meta {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.email-body {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    min-height: 400px;
}

.email-html-wrapper {
    width: 100%;
    min-height: 600px;
    background: white;
    border-radius: 0.5rem;
    overflow: hidden;
}

.email-html-iframe {
    width: 100%;
    min-height: 600px;
    border: none;
    background: white;
    display: block;
    transition: height 0.3s ease;
}

/* Улучшение отображения HTML писем */
.email-body {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    min-height: 400px;
}

.email-body pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    color: var(--text-primary);
    background: transparent;
    padding: 0;
    margin: 0;
}

/* Admin */
.admin-container {
    padding: 2rem;
}

.admin-section {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.admin-section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

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

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.table td {
    color: var(--text-primary);
}

.table tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.form-inline {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-inline .form-input {
    flex: 1;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.show {
    display: flex;
}

.alert-success {
    background-color: rgba(40, 167, 69, 0.1);
    border: 1px solid rgba(40, 167, 69, 0.3);
    color: #d4edda;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Container */
    .container {
        padding: 0 0.75rem;
    }
    
    /* Header */
    .header {
        padding: 0.75rem 0;
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .header h1 {
        font-size: 1.125rem;
    }
    
    .header-content > div {
        width: 100%;
    }
    
    .header-content .btn {
        width: 100%;
    }
    
    /* Forms */
    .form-container {
        max-width: 100%;
        margin: 2rem auto;
        padding: 1.5rem;
    }
    
    .form-title {
        font-size: 1.25rem;
    }
    
    /* Inbox Layout - Mobile */
    .inbox-container {
        flex-direction: column !important;
        height: calc(100vh - 60px) !important;
        display: flex !important;
    }
    
    .sidebar {
        flex: 1 1 55%;            /* минимум 55% экрана */
        max-height: 65vh;
        overflow-y: auto;
    }
    
    .email-content {
        flex: 1 1 45%;            /* остаток */
        min-height: 35vh;
        overflow-y: auto;
    }
    
    .email-header {
        padding: 1rem;
    }
    
    .email-title {
        font-size: 1.125rem;
    }
    
    .email-meta {
        font-size: 0.8125rem;
    }
    
    .email-body {
        padding: 1rem;
        min-height: 300px;
    }
    
    .email-body iframe {
        min-height: 400px;
    }
    
    /* Admin */
    .admin-container {
        padding: 1rem;
    }
    
    .admin-section {
        padding: 1rem;
        margin-bottom: 1rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .admin-section-title {
        font-size: 1.125rem;
    }
    
    /* Tables - Scrollable on mobile */
    .table {
        min-width: 600px;
    }
    
    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.8125rem;
    }
    
    .table .btn {
        white-space: nowrap;
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
    
    /* Form inline - Stack on mobile */
    .form-inline {
        flex-direction: column;
    }
    
    .form-inline .form-input {
        width: 100%;
    }
    
    /* Grid forms - Stack on mobile */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Modal */
    .modal-content {
        width: 95%;
        padding: 1.5rem;
        max-height: 85vh;
    }
    
    /* Buttons */
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.8125rem;
    }
}

@media (max-width: 480px) {
    /* Extra small devices */
    .form-container {
        margin: 1rem auto;
        padding: 1rem;
    }
    
    .form-title {
        font-size: 1.125rem;
    }
    
    .form-description {
        font-size: 0.8125rem;
    }
    
    .email-content {
        padding: 0.75rem;
    }
    
    .email-header {
        padding: 0.75rem;
    }
    
    .email-body {
        padding: 0.75rem;
        min-height: 250px;
    }
    
    .email-body iframe {
        min-height: 300px;
    }
    
    .sidebar {
        padding: 0.75rem !important;
        height: 40vh !important;
        max-height: 40vh !important;
        min-height: 250px !important;
        flex: 0 0 40vh !important;
    }
    
    .email-content {
        flex: 1 !important;
        height: auto !important;
    }
    
    .admin-container {
        padding: 0.75rem;
    }
    
    .admin-section {
        padding: 0.75rem;
    }
    
    .modal-content {
        padding: 1rem;
    }
}

