:root {
    --card-size: 200px;
    --flip-speed: 0.6s;
    --bg-light: #f2f2f2;
    --bg-dark: #1e1e1e;
}

body {
    font-family: sans-serif;
    padding: 10px;
    margin: 0;
    transition: background 0.3s, color 0.3s;
    background-color: var(--bg-light);
    color: #000;
}

body.dark {
    background-color: var(--bg-dark);
    color: #ddd;
}

/* --- TOP BAR --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    margin-left: 10px;
}

h3 {
    margin: 0;
    font-size: 28px;
    font-family: 'Brush Script MT', cursive;
    font-weight: normal;
}

.settings-btn {
    cursor: pointer;
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background: #fff;
}
body.dark .settings-btn { background: #444; border-color: #666; color: #eee; }

/* --- GRID LAYOUT --- */
.grid {
    display: none;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
}

/* --- FLIP CARD --- */
.flip-container {
    background-color: transparent;
    width: var(--card-size);
    height: var(--card-size);
    perspective: 1000px;
    cursor: pointer;
    user-select: none;
    will-change: transform;
}

.flipper {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform var(--flip-speed);
    transform-style: preserve-3d;
    border-radius: 14px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.flip-container.flipped .flipper {
    transform: rotateY(180deg);
}

.front, .back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    box-sizing: border-box;
    background: white;
    border: 1px solid rgba(0,0,0,0.05);
}

body.dark .front, body.dark .back {
    background: #2e2e2e;
    color: #eee;
    border-color: rgba(255,255,255,0.1);
}

/* --- FRONT SIDE --- */
.front { z-index: 2; transform: rotateY(0deg); }

.queue-header-front {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 1;
    position: relative;
    margin-bottom: 18px; /* Збільшено відступ, щоб бейдж не "наїжджав" на цифру */
}

.queue-name {
    font-weight: bold;
    font-size: 12px;
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
}

.queue-id {
    font-size: 11px;
    color: #565656;
    margin-bottom: 0;
}
body.dark .queue-id { color: #aaa; }

.front-lang-badge {
    position: absolute;
    top: 100%; /* Чіпляємо до низу заголовка */
    left: 50%;
    transform: translateX(-50%);
    margin-top: 4px; /* Відступ від заголовка */
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: bold;
    text-transform: uppercase;
    background-color: rgba(255, 255, 255, 0.8);
    color: inherit;
    border: 1px solid rgba(0,0,0,0.05);
    min-width: 30px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
    pointer-events: none;
}
body.dark .front-lang-badge {
    background-color: rgba(0, 0, 0, 0.5);
    color: inherit;
    border-color: rgba(255,255,255,0.1);
}

.queue-main-stat {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.queue-count {
    font-size: 40px;
    font-weight: bold;
    margin: 0;
    line-height: 1;
}

.queue-label {
    font-size: 10px;
    color: #777;
    margin-top: 5px;
}

.queue-footer {
    font-size: 11px;
    width: 100%;
    display: flex;
    justify-content: space-around;
    padding-top: 6px;
    border-top: 1px solid rgba(0,0,0,0.1);
}
body.dark .queue-footer { border-top-color: rgba(255,255,255,0.1); }

.footer-item { text-align: center; }
.footer-val { font-weight: bold; }
.footer-lbl { font-size: 10px; color: #777; }

/* --- BACK SIDE --- */
.back { transform: rotateY(180deg); align-items: flex-start; text-align: left; }

.back-header {
    width: 100%;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    margin-bottom: -1px;
    font-weight: bold;
    font-size: 12px;
    text-align: center;
}
body.dark .back-header { border-bottom-color: rgba(255,255,255,0.15); }

.caller-list-container {
    flex-grow: 1;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}
.caller-list-container::-webkit-scrollbar { width: 4px; }
.caller-list-container::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.2); border-radius: 2px; }

.caller-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    table-layout: fixed;
}

.caller-table th {
    text-align: left;
    padding: 4px;
    color: #888;
    font-size: 10px;
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 1;
}
.caller-table td {
    padding: 5px 2px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    vertical-align: middle;
}
body.dark .caller-table td { border-bottom-color: rgba(255,255,255,0.05); }

.col-pos {width: 15px; font-weight: bold; color: #888; text-align: center;}
.col-info {width: 45%; overflow: hidden;}
.col-num {width: 40%; text-align: right; font-family: monospace;}

.client-row-name {
    display: block;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 9px;
}
.client-meta {
    font-size: 9px;
    color: #666;
    display: flex;
    gap: 4px;
    margin-top: 2px;
}
.badge {
    background: #e0e0e0;
    padding: 1px 3px;
    border-radius: 3px;
    font-size: 8px;
}
body.dark .badge { background: #444; color: #ccc; }

/* STATUS COLORS */
.status-high .front, .status-high .back { background-color: #f8d7da; color: #721c24; }
body.dark .status-high .front, body.dark .status-high .back { background-color: #5b1f1f; color: #f8d7da; }

.status-medium .front, .status-medium .back { background-color: #fff3cd; color: #5c4604; }
body.dark .status-medium .front, body.dark .status-medium .back { background-color: #665700; color: #fff3cd; }

.status-low .front, .status-low .back { background-color: #d4edda; color: #13471f; }
body.dark .status-low .front, body.dark .status-low .back { background-color: #235d3a; color: #ebffea; }

/* --- MODAL STYLES --- */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: white;
    padding: 15px 20px;
    border-radius: 12px;
    width: 300px;
    max-height: 85vh;
    overflow-y: auto;
    font-size: 13px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
body.dark .modal-content { background: #2b2b2b; color: #eee; }

.modal h2 {
    font-size: 16px;
    margin-top: 0;
    margin-bottom: 10px;
    text-align: center;
}

.modal-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 15px; }

.save-btn, .cancel-btn {
    padding: 5px 12px;
    font-size: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.save-btn { background: #4CAF50; color: white; }
.cancel-btn { background: #ccc; }
body.dark .cancel-btn { background: #555; color: #eee; }

/* --- SETTINGS GROUPS --- */
.settings-group {
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 8px;
}
.settings-group:last-child { border-bottom: none; }
body.dark .settings-group { border-bottom-color: rgba(255,255,255,0.05); }

.settings-group strong {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
}

.settings-group label {
    display: flex;
    align-items: center;
    margin-bottom: 0;
    cursor: pointer;
    font-size: 12px;
}

.settings-group input[type="checkbox"],
.settings-group input[type="radio"] {
    margin-right: 8px;
    transform: scale(1.1);
}

/* Slider */
.scale-control { display: flex; align-items: center; gap: 10px; font-size: 11px; color: #777; }
input[type=range] { flex-grow: 1; cursor: pointer; height: 4px; }

/* --- QUEUE LIST (SCROLLABLE) --- */
.queue-list-container {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 4px;
    background: #fff;
}
body.dark .queue-list-container { background: #333; border-color: #555; }

.queue-list-container::-webkit-scrollbar { width: 4px; }
.queue-list-container::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.queue-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    width: 100%;
    padding: 3px 0;
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
}
body.dark .queue-row { border-bottom-color: #444; }
.queue-row:last-child { border-bottom: none; }

.queue-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    font-size: 11px;
    color: #333;
}
body.dark .queue-row label { color: #ddd; }

.queue-row input[type="checkbox"] { transform: scale(1); margin: 0; flex-shrink: 0; }

.bell-icon {
    flex-shrink: 0;
    color: #ccc;
    transition: color 0.2s, transform 0.1s;
    cursor: pointer;
    font-size: 14px;
    padding: 0 6px;
}
.bell-icon:hover { transform: scale(1.2); }
.bell-active { color: #ffb300; }
body.dark .bell-icon { color: #666; }
body.dark .bell-active { color: #ffd740; }

/* --- TRIGGERS DESIGN --- */
.trigger-input-row { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; margin-top: 4px; }
.trigger-select { width: 85px; padding: 4px; border: 2px solid #2196F3; border-radius: 6px; background: white; font-size: 11px; color: #333; cursor: pointer; box-sizing: border-box; height: 28px; }
body.dark .trigger-select { background: #333; color: #eee; border-color: #64b5f6; }
.trigger-input { flex: 1; padding: 4px 6px; border: 1px solid #ccc; border-radius: 6px; font-size: 11px; box-sizing: border-box; height: 28px; min-width: 0; }
body.dark .trigger-input { background: #444; border-color: #666; color: #eee; }
.btn-add-trigger { width: 28px; height: 28px; background-color: #66BB6A; color: white; border: none; border-radius: 6px; font-size: 18px; font-weight: bold; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; }
.btn-add-trigger:hover { background-color: #4CAF50; }

.triggers-list { display: flex; flex-direction: column; gap: 4px; max-height: 150px; overflow-y: auto; }
.trigger-item { border: 1px dashed #ccc; border-radius: 6px; padding: 4px 8px; display: flex; justify-content: space-between; align-items: center; }
body.dark .trigger-item { border-color: #555; }
.trigger-info { display: flex; flex-direction: column; gap: 1px; }
.trigger-queue-name { font-weight: bold; font-size: 11px; color: #000; }
body.dark .trigger-queue-name { color: #eee; }
.trigger-phone-number { font-family: monospace; font-size: 11px; color: #555; }
body.dark .trigger-phone-number { color: #aaa; }
.btn-remove-trigger { width: 20px; height: 20px; background-color: #ffcdd2; color: #b71c1c; border: none; border-radius: 4px; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-remove-trigger:hover { background-color: #ef9a9a; }

/* --- TABS --- */
.tabs-header { display: flex; border-bottom: 1px solid #ccc; margin-bottom: 10px; }
.tab-btn { flex: 1; padding: 8px; background: none; border: none; cursor: pointer; font-weight: bold; font-size: 12px; color: #666; border-bottom: 3px solid transparent; transition: 0.3s; }
.tab-btn.active { color: #4CAF50; border-bottom-color: #4CAF50; }
.tab-content { display: none; animation: fadeIn 0.3s; }
.tab-content.active { display: block; }

/* --- ORCHARD --- */
.orchard-input { width: 100%; padding: 6px; border-radius: 6px; border: 1px solid #ccc; box-sizing: border-box; margin-bottom: 8px; font-size: 12px; }
.orchard-stats { background: #f9f9f9; padding: 8px; border-radius: 8px; margin-bottom: 10px; font-size: 12px; border: 1px solid #eee; }
body.dark .orchard-stats { background: #333; border-color: #444; }
.orchard-stat-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.orchard-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.btn-orchard { flex: 1; padding: 8px; border-radius: 6px; border: none; color: white; cursor: pointer; font-weight: bold; font-size: 12px; }
.btn-start { background: #2196F3; }
.btn-end { background: #f44336; }
.orchard-warning { font-size: 10px; color: #888; font-style: italic; text-align: center; }

/* --- NOTIFICATION CONTAINER --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column; /* Вишиковує сповіщення у стовпчик */
    gap: 10px; /* Відступ між сповіщеннями */
    pointer-events: none; /* Дозволяє клікати крізь пусті місця контейнера */
}

/* --- NOTIFICATION TOAST --- */
.trigger-notification {
    /* position: fixed; <--- ВИДАЛЕНО */
    /* top: 20px; right: 20px; <--- ВИДАЛЕНО */

    position: relative;
    pointer-events: auto; /* Повертаємо клікабельність самому сповіщенню */
    background: #fff;
    color: #333;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    padding: 12px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 5px solid #ffb300;
    max-width: 300px;
    font-family: sans-serif;

    /* Анімація появи */
    animation: slideInRight 0.4s ease-out forwards;
    transition: all 0.5s ease; /* Для плавного зникнення */
}

/* Типи сповіщень */
.trigger-notification.type-error { border-left-color: #f44336; }
.trigger-notification.type-success { border-left-color: #4CAF50; }
.trigger-notification.type-info { border-left-color: #2196F3; }

.trigger-notification .icon { font-size: 20px; }

.trigger-notification .content {
    display: flex;
    flex-direction: column;
}

.trigger-notification .title {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 2px;
}

.trigger-notification .subtitle {
    font-size: 12px;
    color: #666;
}

/* Dark Theme */
body.dark .trigger-notification {
    background: #333;
    color: #fff;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}
body.dark .trigger-notification .subtitle { color: #ddd; }

/* Анімації */
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* --- CHEATSHEET (FIXED) --- */
.cheatsheet {
    display: none; /* <--- Приховуємо за замовчуванням */

    /* Ваші існуючі стилі залишаються нижче: */
    justify-content: center;
    margin-top: 20px;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    /* і так далі... */
}
.cheatsheet-card { background: #fff; padding: 15px; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); flex: 1; min-width: 280px; max-width: 1000px; }
body.dark .cheatsheet-card { background: #2e2e2e; color: #eee; }
.cheatsheet-card h3 { margin-top: 0; border-bottom: 1px solid #ccc; padding-bottom: 5px; font-size: 14px; }
.cheatsheet-card ul {
    list-style: none;
    padding-left: 0;
    font-size: 12px;
    margin-top: 8px;
    margin-bottom: auto;
    color: inherit;
}
.cheatsheet-card li {
    margin-bottom: 6px;
    padding-bottom: 4px;
    /* Для охайного вигляду можна додати border-bottom, але це опціонально */
}

/* --- UTILS --- */
.copy-num { cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.copy-num:hover { background: rgba(0,0,0,0.1); }
body.dark .copy-num:hover { background: rgba(255,255,255,0.2); }
.copy-num.copied { background: #4CAF50 !important; color: white !important; }

.blurred { filter: blur(6px); pointer-events: none; user-select: none; }
.sortable-drag { opacity: 1 !important; background: transparent; cursor: grabbing; transform: scale(1.05); z-index: 9999; }
.sortable-ghost { opacity: 0.2; background-color: #000; border-radius: 14px; border: 2px dashed rgba(0,0,0,0.2); }
body.dark .sortable-ghost { background-color: #fff; border-color: rgba(255,255,255,0.2); }
.sortable-drag .flipper { transition: none !important; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }