/* SAPE Reports Dashboard - Custom Styles */

/* Smooth cross-document navigation between pages (Отчёты/Мониторинг/...) -
   progressive enhancement, ignored by browsers that don't support it, no
   change to how/when pages actually load or what data they show. */
@view-transition {
    navigation: auto;
}
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.08s;
}

*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    /* Colors from Dribbble design */
    --primary-orange: #FF8A5B;
    --secondary-orange: #FFA577;
    --peach-light: #FFE5D9;
    --peach-bg: #FFF5F0;
    --purple-accent: #9B59B6;
    --green-accent: #10B981;

    /* Neutrals */
    --text-primary: #1A1A1A;
    --text-secondary: #6B7280;
    --text-light: #9CA3AF;
    --border-color: #E5E7EB;
    --bg-white: #FFFFFF;
    --bg-light: #F9FAFB;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Global Styles */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-primary);
    background: var(--peach-bg);
    margin: 0;
    padding: 0;
}

/* Form controls don't inherit font-family from body by default */
input, select, textarea, button {
    font-family: inherit;
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 220px;
    background: var(--bg-white);
    border-right: 1px solid var(--border-color);
    transition: width 0.3s ease;
    z-index: 40;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary-orange), var(--secondary-orange));
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-logo-text {
    display: none;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.sidebar-nav-item:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

.sidebar-nav-item.active {
    background: var(--peach-light);
    color: var(--primary-orange);
    border-left-color: var(--primary-orange);
}

.sidebar-nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-nav-text {
    display: none;
}

.sidebar-toggle {
    position: fixed;
    left: 200px;
    top: 24px;
    width: 36px;
    height: 36px;
    background: var(--primary-orange);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: left 0.3s ease;
    z-index: 100;
    box-shadow: 0 4px 8px rgba(255, 138, 91, 0.3);
}

.sidebar-toggle:hover {
    background: var(--secondary-orange);
    box-shadow: 0 4px 12px rgba(255, 138, 91, 0.4);
}

.sidebar-toggle svg {
    stroke: white;
}

body:has(.sidebar.collapsed) .sidebar-toggle {
    left: 40px;
}

/* Main Content */
.main-content {
    margin-left: 220px;
    transition: margin-left 0.3s ease;
    min-height: 100vh;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 60px;
}

.content-header {
    background: linear-gradient(135deg, var(--peach-light) 0%, var(--peach-bg) 100%);
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.content-header h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.content-header p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

.content-body {
    padding: 24px;
}

/* Metric Cards */
.metric-card {
    background: var(--bg-white);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.metric-card:hover {
    box-shadow: var(--shadow-md);
}

.metric-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 16px;
}

.metric-label svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.metric-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.metric-change {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.metric-change.positive {
    color: var(--green-accent);
}

.metric-change.negative {
    color: #EF4444;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-orange), var(--secondary-orange));
    color: white;
    border: none;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

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

.btn-icon {
    width: 18px;
    height: 18px;
}

/* Tables */
.table-container {
    background: var(--bg-white);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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

thead {
    background: var(--bg-light);
}

th {
    padding: 16px 24px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-primary);
}

tbody tr:hover {
    background: var(--bg-light);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: #D1D5DB;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-switch.active {
    background: var(--green-accent);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-switch.active::after {
    transform: translateX(20px);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: #D1FAE5;
    color: #065F46;
}

.badge-warning {
    background: #FEF3C7;
    color: #92400E;
}

.badge-info {
    background: #DBEAFE;
    color: #1E40AF;
}

/* Mobile top bar - hidden on desktop, shown via the media query below */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    z-index: 60;
}

.mobile-menu-btn {
    background: none;
    border: none;
    padding: 6px;
    margin: 0;
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-backdrop {
    display: none;
}

.sidebar-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 65;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        top: 0;
        z-index: 70;
    }

    .main-content {
        margin-left: 0;
    }

    .content-header {
        padding: 16px;
    }

    .content-header h1 {
        font-size: 20px;
    }

    .content-body {
        padding: 16px;
    }

    .metric-card {
        padding: 16px;
    }

    /* Every inline grid layout collapses to a single column - stat rows,
       charts rows, manager panels, filter grids, etc. The !important is
       required since these are all set via inline style="" in templates,
       which a plain media-query selector can't otherwise out-rank. */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* Grid items get an automatic min-width based on their content's
       min-content size by default - a card containing a wide table (with
       its own overflow-x:auto scroller a few levels down) still forces
       the whole grid track that wide unless the item's own min-width is
       reset, even though the table itself would happily scroll in place. */
    #monitoringGrid > *,
    #reportsGrid > * {
        min-width: 0;
    }

    /* Flex rows (filter bars, card meta rows, button groups) wrap instead
       of overflowing horizontally off the edge of the screen. */
    [style*="display: flex"],
    [style*="display:flex"] {
        flex-wrap: wrap !important;
    }

    /* Monitoring/Reports toolbar rows (tabs+Обновить все / search+filters+
       Добавить мониторинг|Создать отчет) - stack as full-width rows instead
       of the generic wrap rule above, which otherwise squeezes each child
       into a narrow column since none of them have an explicit width. */
    .monitoring-toolbar-row,
    .reports-toolbar-row {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .monitoring-toolbar-row > *,
    .reports-toolbar-row > * {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* flex:1 children default to min-width:auto, which keeps them at their
       unwrapped content width even inside a wrapping flex row - this lets
       them actually shrink instead of pushing the row past the viewport. */
    [style*="flex: 1"],
    [style*="flex:1"] {
        min-width: 0 !important;
    }

    /* Campaign id/name/frequency row: on mobile there just isn't room for
       all 3 - frequency (daily/total) is the least useful column here, so
       drop it and let id+name sit on one clean, single-line, truncated
       row instead of wrapping a long unbroken tracking string. */
    .campaigns-table-header > div:nth-child(3),
    .campaign-row > div:nth-child(3) {
        display: none !important;
    }

    .campaigns-table-header [style*="flex: 1"],
    .campaign-row [style*="flex: 1"] {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Report card action row (Asana / Открыть отчет / Выбрать даты / ⋮) -
       keep on one line, shrinking padding/font rather than wrapping to a
       second row; scrolls internally in the rare case it still doesn't
       fit instead of pushing the card wider than the screen. */
    .report-card-actions {
        width: 100%;
        flex-wrap: nowrap !important;
        justify-content: flex-end !important;
        gap: 4px !important;
        overflow-x: auto;
    }

    .report-card-actions .btn {
        padding: 4px 6px !important;
        font-size: 9px !important;
        white-space: nowrap;
    }

    /* Monitoring card title - its own full-width line on mobile (not
       squeezed next to the timeline/gear/⋮ cluster), truncated if still
       too long for one line. flex-basis:100% in a wrapping flex row
       forces everything after it onto the next line. */
    .monitoring-card-title {
        flex-basis: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
        font-size: 13px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Badges + timeline/gear/⋮ wrap onto their own line below the title -
       plenty of room there since they're no longer sharing it with the
       name. */
    .monitoring-card-title-row {
        flex-wrap: wrap !important;
    }

    /* Drop the format badge and KPI-comment info icon on mobile - not
       essential, and freeing their space keeps the second line tidier. */
    .monitoring-card-title-row .ad-format-badge,
    .monitoring-card-title-row .kpi-info-icon {
        display: none !important;
    }

    /* Monitoring card meta row (Кабинет / Трафик-менеджер / Период /
       Данные обновлены) - stack each on its own line instead of wrapping
       an inline bullet-separated row, and drop the now-redundant bullets. */
    .monitoring-card-meta {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 4px !important;
    }

    .meta-dot {
        display: none;
    }

    .meta-field {
        width: 100%;
        font-size: 11px;
        white-space: nowrap;
    }

    /* Sync-status dot (green/grey) before "Данные обновлены" and the
       Аккаунт-менеджер footer line - both dropped on mobile to save a
       bit more vertical room on an already dense card. */
    .sync-dot,
    .am-footer,
    .campaigns-footer {
        display: none !important;
    }

    /* Page subtitle (e.g. "Настройка автоматической выгрузки в Google
       Sheets") - shrink and keep to one line instead of wrapping across
       half the header. */
    .content-header p {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Reports/Monitoring toolbar buttons/selects - icon+label truncation
       and full-width-in-row behavior, via the 2-row .reports-toolbar-row /
       .monitoring-toolbar-row markup above. */
    #reportsToolbar select,
    #reportsToolbar button,
    #monitoringToolbar select,
    #monitoringToolbar button {
        min-width: 0 !important;
        padding: 0 8px !important;
        font-size: 9px !important;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #reportsToolbar .tab-button,
    #monitoringToolbar .tab-button {
        min-width: 0 !important;
        margin: 0;
    }
    #reportsToolbar .btn-label,
    #monitoringToolbar .btn-label {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Wide tables (accounts list, KPI table) scroll horizontally inside
       their own card rather than overflowing the page. */
    .table-container {
        overflow-x: auto;
    }

    body {
        overflow-x: hidden;
    }
}
