:root {
    --sidebar-w: 220px;
    --topbar-h: 48px;
    --c-bg: #f5f6fa;
    --c-sidebar: #1e2235;
    --c-sidebar-hover: #2a2f4a;
    --c-accent: #4361ee;
    --c-text: #23272f;
    --c-muted: #6b7280;
    --c-border: #e5e7eb;
    --c-card: #fff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: var(--c-text);
    background: var(--c-bg);
}

/* ── Top bar (mobile only) ── */
.topbar {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--c-sidebar);
    z-index: 200;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
}

.topbar-toggle {
    background: none; border: none; color: #fff;
    font-size: 22px; cursor: pointer; padding: 4px 8px;
    display: flex; align-items: center;
}

.topbar-brand {
    color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .3px;
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 299;
}

.sidebar-overlay.open { display: block; }

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--c-sidebar);
    display: flex;
    flex-direction: column;
    z-index: 300;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 18px 16px;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    letter-spacing: .3px;
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.sidebar-nav { list-style: none; padding: 8px 0; margin: 0; flex: 1; }

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: rgba(255,255,255,.6);
    text-decoration: none;
    font-size: 13px;
    transition: background .15s, color .15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background: var(--c-sidebar-hover);
    color: #fff;
}

.sidebar-nav li a.active { border-left: 3px solid var(--c-accent); padding-left: 15px; }

.sidebar-section {
    padding: 18px 18px 6px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,.3);
}

/* ── Main ── */
.main { margin-left: var(--sidebar-w); padding: 24px 28px; min-height: 100vh; }

.page-title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 20px;
    color: var(--c-text);
}

/* ── Cards ── */
.card {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    box-shadow: none;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: 13px;
    padding: 12px 16px;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
}

.card-body { padding: 16px; }

/* ── Stat widgets ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }

.stat-card {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: 8px;
    padding: 16px;
}

.stat-label { font-size: 12px; color: var(--c-muted); margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; }

/* ── Tables ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
    text-align: left;
    padding: 8px 12px;
    font-weight: 600;
    color: var(--c-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid var(--c-border);
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.tbl tbody tr:hover { background: #f9fafb; }
.tbl a { color: var(--c-accent); text-decoration: none; }
.tbl a:hover { text-decoration: underline; }

/* ── Tags ── */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
}
.tag-tg { background: #e3f0ff; color: #2563eb; }
.tag-vk { background: #eef2ff; color: #4f46e5; }
.tag-ok { background: #ecfdf5; color: #059669; }
.tag-warn { background: #fffbeb; color: #d97706; }
.tag-err { background: #fef2f2; color: #dc2626; }
.tag-muted { background: #f3f4f6; color: #6b7280; }
.tag-our { background: #ecfdf5; color: #059669; }
.tag-ad { background: #f0f4ff; color: #4f46e5; }
.tag-competitor { background: #fef2f2; color: #dc2626; }

/* ── Status dots ── */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-ok { background: #10b981; }
.dot-warn { background: #f59e0b; }
.dot-err { background: #ef4444; }
.dot-muted { background: #9ca3af; }

/* ── Buttons ── */
.btn-p {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: var(--c-accent); color: #fff;
    border: none; border-radius: 6px;
    font-size: 13px; font-weight: 500;
    cursor: pointer; text-decoration: none;
    transition: opacity .15s;
}
.btn-p:hover { opacity: .85; color: #fff; }

.btn-s {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    background: transparent; color: var(--c-text);
    border: 1px solid var(--c-border); border-radius: 6px;
    font-size: 13px; cursor: pointer; text-decoration: none;
    transition: background .15s;
}
.btn-s:hover { background: #f3f4f6; color: var(--c-text); }

.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    border: 1px solid var(--c-border); border-radius: 6px;
    background: transparent; cursor: pointer;
    color: var(--c-muted); font-size: 14px;
    transition: background .15s, color .15s;
}
.btn-icon:hover { background: #f3f4f6; color: var(--c-text); }
.btn-icon.danger:hover { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

/* ── Calendar ── */
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th { padding: 8px; text-align: center; font-size: 12px; color: var(--c-muted); font-weight: 600; text-transform: uppercase; }
.cal td {
    height: 100px; vertical-align: top; padding: 6px 8px;
    border: 1px solid var(--c-border); background: var(--c-card);
}
.cal td.out { background: #fafafa; color: #ccc; }
.cal td.today { background: #f0f4ff; border-color: var(--c-accent); }
.cal .day-num { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.cal-pill {
    display: block;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-pill.pending { background: #f3f4f6; color: #6b7280; }
.cal-pill.matched { background: #ecfdf5; color: #059669; }
.cal-pill.missed { background: #fef2f2; color: #dc2626; }
.cal-pill.late { background: #fffbeb; color: #d97706; }

/* ── Schedule dates - clean minimal style ── */
.schedule-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.sched-date {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.sched-date:hover {
    opacity: 0.85;
}
.sched-date.pending {
    background: #f1f5f9;
    color: #64748b;
}
.sched-date.matched {
    background: #dcfce7;
    color: #16a34a;
}
.sched-date.missed {
    background: #fee2e2;
    color: #dc2626;
}
.sched-date.late {
    background: #fef3c7;
    color: #d97706;
}
.sched-date.different_day {
    background: #fef9c3;
    color: #ca8a04;
}
.sched-date.pin-check {
    border: 1px dashed currentColor;
}

/* ── Admin grid view ── */
.admin-header {
    text-align: center;
    margin-bottom: 24px;
}
.admin-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 4px 0;
}
.admin-header p {
    font-size: 14px;
    color: #64748b;
    margin: 0;
}
.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
.admin-group-title {
    grid-column: 1 / -1;
    background: #1e293b;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 8px;
    margin-top: 8px;
}
.admin-box {
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
}
.admin-box-top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.admin-box-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
}
.admin-box-badge.tg {
    background: #dbeafe;
    color: #1d4ed8;
}
.admin-box-badge.vk {
    background: #ede9fe;
    color: #7c3aed;
}
.admin-box-name {
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-box-type {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 12px;
}
.admin-box-dates {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.admin-box-date {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}
.admin-box-date.pending {
    background: #f1f5f9;
    color: #64748b;
    border: 2px solid #e2e8f0;
}
.admin-box-date.matched {
    background: #dcfce7;
    color: #15803d;
    border: 2px solid #86efac;
}
.admin-box-date.missed {
    background: #fee2e2;
    color: #dc2626;
    border: 2px solid #fca5a5;
}
.admin-box-date.late {
    background: #fef3c7;
    color: #b45309;
    border: 2px solid #fcd34d;
}
.admin-box-date.different_day {
    background: #fef9c3;
    color: #a16207;
    border: 2px solid #fde047;
}
.admin-box-date.empty {
    background: #f8fafc;
    color: #cbd5e1;
    border: 2px dashed #e2e8f0;
}
/* Publication time inside date pills */
.pub-time {
    display: block;
    font-size: 10px;
    font-weight: 500;
    opacity: 0.8;
    margin-top: 1px;
}
.sched-date .pub-time {
    font-size: 9px;
}
.admin-box-date {
    flex-direction: column;
    line-height: 1.1;
}
@media (max-width: 700px) {
    .admin-grid { grid-template-columns: 1fr; }
}

.cal-count {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--c-accent); color: #fff;
    font-size: 13px; font-weight: 700;
    margin-top: 2px;
}
.cal-count-ok { background: #059669; }
.cal-count-err { background: #ef4444; }
.cal-count-pending { background: var(--c-accent); }

/* ── Alerts list ── */
.alert-row { padding: 10px 0; border-bottom: 1px solid var(--c-border); }
.alert-row:last-child { border-bottom: none; }
.alert-severity { font-weight: 600; font-size: 12px; }

/* ── Forms (modals) ── */
.form-label { font-size: 13px; font-weight: 500; color: var(--c-text); }
.form-text { font-size: 12px; color: var(--c-muted); }

/* ── Breadcrumb ── */
.bc { display: flex; gap: 6px; font-size: 13px; color: var(--c-muted); margin-bottom: 16px; }
.bc a { color: var(--c-accent); text-decoration: none; }
.bc a:hover { text-decoration: underline; }
.bc span { color: var(--c-muted); }

/* ── Filters row ── */
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filters select, .filters input[type=number] {
    padding: 6px 10px; border: 1px solid var(--c-border); border-radius: 6px;
    font-size: 13px; background: #fff;
}

/* ── Pagination ── */
.pager { display: flex; gap: 4px; margin-top: 16px; }
.pager a, .pager span {
    padding: 6px 12px; border: 1px solid var(--c-border); border-radius: 6px;
    font-size: 13px; text-decoration: none; color: var(--c-text);
}
.pager a:hover { background: #f3f4f6; }
.pager .current { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }

/* ═══════════════════════════════════════════════
   ── Responsive: Mobile & Telegram Web App ──
   ═══════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Show top bar */
    .topbar { display: flex; }

    /* Sidebar: hidden by default, slides in */
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    .sidebar.open { transform: translateX(0); }

    /* Main content: no sidebar margin, add top bar padding */
    .main {
        margin-left: 0;
        padding: 60px 14px 16px;
    }

    /* Stat grid: 2 columns on mobile */
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-value { font-size: 22px; }
    .stat-card { padding: 12px; }

    /* Page title */
    .page-title { font-size: 17px; margin-bottom: 14px; }

    /* Tables: smaller text */
    .tbl th { font-size: 10px; padding: 6px 8px; }
    .tbl td { padding: 8px; font-size: 12px; }

    /* Calendar: compact */
    .cal td { height: 60px; padding: 4px; }
    .cal .day-num { font-size: 11px; }
    .cal-pill { font-size: 10px; padding: 1px 4px; }

    /* Buttons: touch-friendly sizes */
    .btn-p, .btn-s { padding: 10px 16px; font-size: 14px; }
    .btn-icon { width: 36px; height: 36px; font-size: 16px; }

    /* Filters: stack vertically */
    .filters { gap: 8px; }
    .filters select { font-size: 14px; padding: 8px 10px; }
}

/* ── Telegram Web App specific ── */
body.tg-webapp {
    /* Telegram provides safe area insets */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

body.tg-webapp .topbar {
    /* Account for Telegram header */
    padding-top: env(safe-area-inset-top, 0);
}
