:root {
    --bg: #f5f7fb;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --secondary-text: #555;
    --border: #e0e0e0;
    --primary: #4a6cf7;
    --danger: #e74c3c;
    --warning: #f39c12;
    --success: #2ecc71;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --radius: 8px;
}
body.dark {
    --bg: #1a1a2e;
    --card-bg: #16213e;
    --text: #eee;
    --secondary-text: #ccc;
    --border: #2a2a4a;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
}
.container { max-width: 1200px; width: 100%; margin-top: 5vh; }
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}
.auth-form { display: flex; gap: 10px; max-width: 400px; margin: 40px auto; }
.auth-form input {
    flex: 1; padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px; background: var(--bg); color: var(--text);
}
.btn {
    padding: 10px 20px; border: none;
    border-radius: var(--radius); cursor: pointer;
    font-size: 14px; font-weight: 500;
    transition: opacity 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn:hover { opacity: 0.85; }
.tabs { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
    padding: 8px 16px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); cursor: pointer;
    font-size: 14px; color: var(--text);
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Дашборд */
.dashboard-widgets {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px; margin-bottom: 20px;
}
.widget {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 15px; text-align: center;
}
.widget-title { font-size: 12px; color: var(--secondary-text); text-transform: uppercase; margin-bottom: 8px; }
.widget-value { font-size: 24px; font-weight: bold; color: var(--primary); }
.widget-value.danger { color: var(--danger); }
.widget-value.warning { color: var(--warning); }

/* Стрічка */
.ticker-wrapper { background: rgba(0,0,0,0.02); border: 1px solid var(--border); margin-bottom: 15px; border-radius: 8px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.02); }
body.dark .ticker-wrapper { background: rgba(255,255,255,0.03); }
.ticker-marquee { 
    display: block; overflow-x: scroll; white-space: nowrap; padding: 15px 0;
    scrollbar-width: none; -ms-overflow-style: none; cursor: default;
    font-weight: bold; font-size: 16px; color: var(--primary);
}
.ticker-marquee::-webkit-scrollbar { display: none; }
.feed-textarea {
    width: 100%; height: 100px; padding: 15px; font-family: monospace;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg); color: var(--text); resize: vertical; margin-bottom: 20px;
}

/* Telegram */
.tg-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 800px) { .tg-grid { grid-template-columns: 1fr; } }
.tg-card {
    border: 1px solid var(--border); border-radius: var(--radius); padding: 15px;
    background: var(--bg);
}
.tg-card h4 { margin-bottom: 10px; color: var(--primary); border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.tg-card .post-body { white-space: pre-wrap; font-family: monospace; font-size: 14px; margin-bottom: 15px; min-height: 100px; }

/* Сирі дані */
.raw-table-container { overflow-x: auto; max-height: 70vh; border-radius: var(--radius); border: 1px solid var(--border); }
.raw-table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
.raw-table th, .raw-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 10px; vertical-align: top; }
.raw-table th { background: var(--bg); font-weight: bold; position: sticky; top: 0; z-index: 10; box-shadow: 0 1px 0 var(--border); }
.raw-table tr:nth-child(even) { background: rgba(0,0,0,0.02); }
body.dark .raw-table tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.street-item { margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
.street-item:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.house-numbers { font-size: 13px; color: var(--secondary-text); }

.toggle-dark {
    position: absolute; top: 15px; right: 20px;
    background: var(--bg); border: 1px solid var(--border);
    padding: 5px 10px; border-radius: 4px; cursor: pointer;
    color: var(--text);
}
.empty { color: var(--secondary-text); font-style: italic; }
.status-bar { padding: 12px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.status-ok { background: #e6ffed; color: #0a5e2e; }
.status-error { background: #ffeaea; color: #a00; }
body.dark .status-ok { background: #1a3a2a; color: #7ee0a0; }
body.dark .status-error { background: #3a1a1a; color: #ff8888; }

/* Нові стилі для тижневої сітки стрічки та модальних вікон */
.feed-section-title {
    margin: 25px 0 10px 0;
    color: var(--primary);
    font-size: 18px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 5px;
}
.feed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-top: 15px;
}
.feed-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 140px;
}
.feed-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.feed-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}
.feed-card-title {
    font-weight: bold;
    font-size: 15px;
}
.feed-card-subtitle {
    font-size: 12px;
    color: var(--secondary-text);
    margin-top: 2px;
}
.feed-card-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-success { background: rgba(46, 204, 113, 0.15); color: #27ae60; }
.badge-danger { background: rgba(231, 76, 60, 0.15); color: #c0392b; }
.badge-secondary { background: rgba(127, 140, 141, 0.15); color: #7f8c8d; }

body.dark .badge-success { background: rgba(46, 204, 113, 0.2); color: #2ecc71; }
body.dark .badge-danger { background: rgba(231, 76, 60, 0.2); color: #ff7675; }
body.dark .badge-secondary { background: rgba(127, 140, 141, 0.2); color: #b2bec3; }

.feed-card-body {
    font-size: 13px;
    color: var(--secondary-text);
    margin-bottom: 12px;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.feed-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--secondary-text);
    border-top: 1px solid var(--border);
    padding-top: 8px;
}
.feed-card-changes {
    background: rgba(74, 108, 247, 0.1);
    color: var(--primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

/* Модальне вікно */
.feed-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease-out;
}
.feed-modal {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 650px;
    max-height: 85vh;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: scaleIn 0.2s ease-out;
}
.feed-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.feed-modal-header h3 {
    font-size: 17px;
    color: var(--text);
}
.feed-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--secondary-text);
    line-height: 1;
}
.feed-modal-close:hover {
    color: var(--danger);
}
.feed-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.feed-modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: rgba(0,0,0,0.01);
}
body.dark .feed-modal-footer {
    background: rgba(255,255,255,0.01);
}
.feed-history-title {
    font-weight: bold;
    font-size: 14px;
    margin: 20px 0 10px 0;
    color: var(--primary);
}
.feed-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--bg);
}
.feed-history-item {
    font-size: 13px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    line-height: 1.4;
}
.feed-history-item:last-child {
    border-bottom: none;
}
.feed-history-meta {
    font-size: 11px;
    color: var(--secondary-text);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}
.feed-history-badge {
    background: var(--warning);
    color: #fff;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}
.feed-history-badge.manual {
    background: var(--primary);
}

/* Статистика */
.anomalies-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--bg);
    margin-top: 10px;
}
.anomaly-log-item {
    font-size: 13px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.anomaly-log-item:last-child {
    border-bottom: none;
}
.anomaly-log-meta {
    font-size: 11px;
    color: var(--secondary-text);
    font-weight: bold;
}
.anomaly-log-diff {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-family: monospace;
    font-size: 12px;
    margin-top: 4px;
    padding-left: 6px;
    border-left: 2px solid var(--warning);
}
.diff-old { color: var(--danger); text-decoration: line-through; opacity: 0.8; }
.diff-new { color: var(--success); font-weight: 500; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
