* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #f5f5f7;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
}

header {
    background: #2c3e50;
    color: #fff;
    padding: 15px 0;
    margin-bottom: 30px;
}

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

header .logo {
    color: #fff;
    text-decoration: none;
    font-size: 1.3em;
    font-weight: bold;
}

header nav a {
    color: #fff;
    margin-left: 20px;
    text-decoration: none;
    opacity: 0.85;
}

header nav a:hover { opacity: 1; text-decoration: underline; }

main { padding: 20px 0; min-height: 60vh; }

footer {
    padding: 20px 0;
    margin-top: 40px;
    text-align: center;
    color: #888;
    font-size: 0.9em;
    border-top: 1px solid #ddd;
}

form {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    max-width: 500px;
}

form label {
    display: block;
    margin-bottom: 15px;
    font-weight: 500;
}

form input, form textarea, form select {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
    font-family: inherit;
}

form button {
    background: #3498db;
    color: #fff;
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    cursor: pointer;
}

form button:hover { background: #2980b9; }

.errors {
    background: #fee;
    border-left: 4px solid #e74c3c;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.errors p { margin: 5px 0; color: #c0392b; }

.flash {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 4px;
}

.flash-success { background: #d4edda; color: #155724; border-left: 4px solid #28a745; }
.flash-error { background: #f8d7da; color: #721c24; border-left: 4px solid #dc3545; }
.flash-info { background: #d1ecf1; color: #0c5460; border-left: 4px solid #17a2b8; }

/* Кнопки */
.btn {
    display: inline-block;
    padding: 8px 16px;
    background: #e0e0e0;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.95em;
    font-family: inherit;
    margin-right: 8px;
    margin-bottom: 8px;
}

.btn:hover { background: #d0d0d0; }

.btn-primary {
    background: #3498db;
    color: #fff;
}

.btn-primary:hover { background: #2980b9; }

.btn-sm { padding: 5px 10px; font-size: 0.85em; }

.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }

.btn-warning { background: #f39c12; color: #fff; }
.btn-warning:hover { background: #d68910; }

/* Действия над списком */
.actions {
    margin: 20px 0;
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Сетка мониторов */
.monitors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.monitor-card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
}

.monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.monitor-header h3 {
    margin: 0;
    font-size: 1.1em;
}

.monitor-header h3 a {
    color: #2c3e50;
    text-decoration: none;
}

.monitor-header h3 a:hover { color: #3498db; }

.monitor-body { flex: 1; }
.monitor-body p { margin: 8px 0; font-size: 0.9em; }

.monitor-actions {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-active { background: #d4edda; color: #155724; }
.badge-inactive { background: #f8d7da; color: #721c24; }

.empty-state {
    text-align: center;
    padding: 40px;
    background: #fff;
    border-radius: 8px;
    color: #888;
}

/* Карточка монитора (детали) */
.monitor-detail {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.monitor-detail h2 {
    margin-top: 30px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}

.monitor-detail h2:first-child { margin-top: 0; }

.info-box {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
    border-left: 4px solid #3498db;
    margin: 15px 0;
}

code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: "Courier New", monospace;
    font-size: 0.9em;
    word-break: break-all;
}

.copyable {
    display: block;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    margin: 5px 0 15px;
    font-size: 1em;
}

.hint {
    font-size: 0.85em;
    color: #888;
    margin: 5px 0;
}

form fieldset {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 15px;
    margin: 15px 0;
}

form fieldset legend {
    padding: 0 8px;
    font-weight: 600;
    color: #555;
}

.checkbox-label {
    display: block;
    padding: 8px 0;
    font-weight: 400;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    display: inline-block;
    margin-right: 8px;
    vertical-align: middle;
}

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

input[type="file"] {
    padding: 6px;
    background: #f8f9fa;
}

/* ========== ИСТОРИЯ СООБЩЕНИЙ ========== */

.history {
    margin: 20px 0;
}

.history-date-group {
    margin-bottom: 30px;
}

.history-date-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    margin-bottom: 12px;
    border-bottom: 2px solid #e0e0e0;
}

.history-date-label {
    font-size: 1.05em;
    font-weight: 600;
    color: #2c3e50;
}

.history-date-count {
    font-size: 0.85em;
    color: #888;
}

/* ===== ПЛОТНАЯ СЕТКА КАРТОЧЕК ===== */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    align-items: start;
}

.msg-card {
    background: #fff;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border-left: 4px solid #ccc;
    display: flex;
    flex-direction: column;
    transition: transform 0.15s, box-shadow 0.15s;
    min-width: 0;              /* важно для обрезки текста в grid */
    overflow: hidden;
}

.msg-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
}

/* Цвета статусов */
.msg-card.msg-status-done { border-left-color: #28a745; }
.msg-card.msg-status-partial { border-left-color: #f39c12; }
.msg-card.msg-status-delivered { border-left-color: #3498db; }
.msg-card.msg-status-pending { border-left-color: #95a5a6; }

.msg-card-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;   /* элементы слева */
    gap: 6px;
    margin-bottom: 6px;
    padding-right: 60px;           /* место под кнопки ⭐ 🗑 */
}

.msg-time {
    font-size: 0.8em;
    color: #666;
    font-weight: 600;
    flex-shrink: 0;
}

.msg-sender {
    font-size: 0.7em;
    color: #555;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.msg-badge {
    font-size: 0.65em;
    padding: 2px 5px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-status-done-badge { background: #d4edda; color: #155724; }
.msg-status-partial-badge { background: #fff3cd; color: #856404; }
.msg-status-delivered-badge { background: #d1ecf1; color: #0c5460; }
.msg-status-pending-badge { background: #f0f0f0; color: #555; }

/* ===== КВАДРАТНОЕ ПРЕВЬЮ 1:1 ===== */
.msg-image-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #000;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msg-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;         /* заполняет квадрат целиком */
    display: block;
}

/* ===== ТЕКСТ С ОБРЕЗКОЙ ===== */
.msg-text {
    font-size: 0.85em;
    color: #333;
    margin-bottom: 6px;
    line-height: 1.35;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;     /* максимум 3 строки */
    -webkit-box-orient: vertical;
    flex: 1;
}

.msg-text-muted {
    color: #aaa;
    font-style: italic;
}

.msg-meta {
    font-size: 0.7em;
    color: #888;
    margin-top: auto;
    padding-top: 6px;
    border-top: 1px solid #f0f0f0;
    overflow: hidden;
}

.msg-recipients {
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg-details {
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== АДАПТИВ ===== */
@media (max-width: 900px) {
    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }
}

@media (max-width: 600px) {
    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 8px;
    }

    .msg-card {
        padding: 8px;
    }

    .msg-text {
        font-size: 0.75em;
        -webkit-line-clamp: 2;
    }

    .msg-badge {
        font-size: 0.55em;
        padding: 1px 4px;
    }
}

@media (max-width: 400px) {
    .history-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========== МОДАЛЬНОЕ ОКНО СООБЩЕНИЯ ========== */

.msg-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.msg-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.msg-modal {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    max-width: 720px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.2s;
}

.msg-modal-overlay.active .msg-modal {
    transform: scale(1);
}

.msg-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    color: #333;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: background 0.15s;
    padding: 0;
    font-family: inherit;
}

.msg-modal-close:hover {
    background: rgba(0, 0, 0, 0.16);
}

.msg-modal-body {
    display: flex;
    flex-direction: column;
}

.msg-modal-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    padding: 12px;
}

.msg-modal-image-wrap img {
    width: 100%;
    max-width: 480px;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    display: block;
    background: #000;
    border-radius: 6px;
}

.msg-modal-content {
    padding: 20px 24px 24px;
}

.msg-modal-status {
    display: inline-block;
    font-size: 0.75em;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 12px;
}

.msg-modal-status.msg-status-done { background: #d4edda; color: #155724; }
.msg-modal-status.msg-status-partial { background: #fff3cd; color: #856404; }
.msg-modal-status.msg-status-delivered { background: #d1ecf1; color: #0c5460; }
.msg-modal-status.msg-status-pending { background: #f0f0f0; color: #555; }

.msg-modal-text {
    font-size: 1.05em;
    color: #222;
    line-height: 1.5;
    margin-bottom: 18px;
    word-break: break-word;
    white-space: pre-wrap;   /* сохраняет переводы строк */
}

.msg-modal-meta {
    font-size: 0.9em;
    color: #666;
    border-top: 1px solid #eee;
    padding-top: 14px;
    line-height: 1.7;
}

.msg-modal-meta strong {
    color: #333;
    font-weight: 600;
}

.msg-modal-meta > div {
    margin-bottom: 4px;
}

/* Адаптив */
@media (max-width: 600px) {
    .msg-modal-overlay {
        padding: 10px;
    }

    .msg-modal {
        max-height: 95vh;
        border-radius: 8px;
    }

    .msg-modal-content {
        padding: 16px 18px 20px;
    }

    .msg-modal-image-wrap {
        padding: 8px;
        border-radius: 8px 8px 0 0;
    }

    .msg-modal-text {
        font-size: 1em;
    }

    .msg-modal-close {
        top: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        font-size: 20px;
    }
}

/* Курсор-указатель на карточках */
.msg-card {
    cursor: pointer;
}

.msg-card:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* ========== СЧЁТЧИК И СТРЕЛКИ В МОДАЛКЕ ========== */

.msg-modal-counter {
    position: absolute;
    top: 16px;
    left: 16px;
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
    background: rgba(0, 0, 0, 0.06);
    padding: 4px 10px;
    border-radius: 12px;
    z-index: 10;
    pointer-events: none;
    user-select: none;
}

.msg-modal-counter span {
    color: #333;
}

/* ===== СТРЕЛКИ НАВИГАЦИИ ===== */
.msg-modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 60px;
    background: rgba(0, 0, 0, 0.06);
    color: #333;
    font-size: 32px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    border-radius: 6px;
    user-select: none;
    transition: background 0.15s, opacity 0.15s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 300;
}

.msg-modal-nav:hover {
    background: rgba(0, 0, 0, 0.14);
}

.msg-modal-nav-prev {
    left: 8px;
}

.msg-modal-nav-next {
    right: 8px;
}

.msg-modal-nav.disabled {
    opacity: 0.2;
    pointer-events: none;
}

/* На мобильных стрелки скрываем — там свайп */
@media (max-width: 600px) {
    .msg-modal-nav {
        display: none;
    }

    .msg-modal-counter {
        top: 12px;
        left: 12px;
        font-size: 0.75em;
        padding: 3px 8px;
    }
}

/* Подсказка «свайпайте» на мобильных */
@media (max-width: 600px) and (pointer: coarse) {
    .msg-modal::after {
        content: '↔ Свайпайте для навигации';
        position: absolute;
        bottom: 8px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 0.7em;
        color: #aaa;
        background: rgba(255, 255, 255, 0.9);
        padding: 3px 10px;
        border-radius: 10px;
        pointer-events: none;
        animation: hintFade 3s ease-in-out forwards;
        z-index: 5;
    }

    @keyframes hintFade {
        0%, 60% { opacity: 1; }
        100% { opacity: 0; }
    }
}

/* ========== ТУЛБАР НА КАРТОЧКЕ (кнопки ⭐ 🗑) ========== */

.msg-card {
    position: relative;   /* для абсолютного позиционирования тулбара */
}

.msg-card-toolbar {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 5;
}

/* Показываем тулбар при наведении на десктопе */
.msg-card:hover .msg-card-toolbar {
    opacity: 1;
}

/* На тач-устройствах показываем всегда */
@media (pointer: coarse) {
    .msg-card-toolbar {
        opacity: 1;
    }
}

.msg-tool-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-family: inherit;
    transition: transform 0.15s, background 0.15s;
}

.msg-tool-btn:hover {
    transform: scale(1.15);
}

.msg-tool-screensaver:hover { background: #fff8d8; }
.msg-tool-return:hover { background: #e3f2fd; }
.msg-tool-delete:hover { background: #ffebee; }

/* Отступ сверху для карточки, чтобы тулбар не наезжал на время */
.msg-card-header {
    padding-right: 60px;   /* место под кнопки */
}

/* ========== ТОЧКА СЛЕВА ОТ ВРЕМЕНИ ========== */

.msg-status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: transform 0.15s;
}

.msg-card:hover .msg-status-dot {
    transform: scale(1.15);
}

/* 🟢 Зелёная — все получатели подтвердили показ */
.msg-status-dot-done {
    background: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.15);
}

/* ⚪ Серая — ещё не показано (доставлено/ожидает/частично) */
.msg-status-dot-none {
    background: #ccc;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

/* Время — крупнее и темнее, чтобы было главным элементом строки */
.msg-time {
    font-size: 0.85em;
    color: #444;
    font-weight: 600;
}

/* ========== КАСТОМНАЯ КНОПКА ЗАГРУЗКИ КАРТИНКИ ========== */

.file-input-label {
    display: block;
    margin-bottom: 15px;
    font-weight: 500;
}

.file-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.file-input-button {
    display: inline-block;
    padding: 10px 20px;
    background: #e0e0e0;
    color: #333;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-family: inherit;
    transition: background 0.15s;
    user-select: none;
}

.file-input-button:hover {
    background: #d0d0d0;
}

.file-input-filename {
    margin-left: 12px;
    font-size: 0.9em;
    color: #28a745;
    font-weight: 500;
}