:root {
    --primary: #4f46e5;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --bg: #f9fafb;
    --red: #dc2626;
    --green: #16a34a;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

html {
    background: #ffffff;
}

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
    background: var(--bg);
    color: #111827;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    opacity: 0;
    animation: page-fade-in 0.5s ease-out forwards;
}

@keyframes page-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 20px;
    background: #3f4654;
    border-bottom: 1px solid #2d323c;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
}

.header-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.header-updated {
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
    color: #c3c9d4;
}

.fx-info-wrap {
    position: relative;
    display: inline-flex;
}

.fx-info-btn {
    width: 16px;
    height: 16px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font: italic 700 10px/1 Georgia, serif;
    cursor: pointer;
}

.fx-info-btn:hover {
    color: #ffffff;
    border-color: #ffffff;
}

.fx-info-pop {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    min-width: 200px;
    padding: 8px 10px;
    background: #2d323c;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    color: #c3c9d4;
    font-size: 11px;
    line-height: 1.4;
    white-space: nowrap;
}

.fx-info-pop[hidden] {
    display: none;
}

.fx-info-pop a {
    color: #ffffff;
    text-decoration: underline;
}

.header-updated-hidden {
    display: none;
}

.back-pill {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    gap: 8px;
    padding: 4px 12px;
    background: #ffffff;
    border: 1px solid #a9c4ef;
    border-radius: 999px;
    color: #2563eb;
    font-weight: 600;
    font-size: 12px;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.12);
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.back-pill:hover {
    background: #eef4ff;
    transform: translateX(-2px);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.18);
}

.back-pill-arrow,
.back-pill-text {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.back-pill-arrow {
    font-size: 13px;
    transition: transform 0.15s;
}

.back-pill:hover .back-pill-arrow {
    transform: translateX(-3px);
}

.currency-select, .lang-select {
    padding: 3px 8px;
    border: 1px solid #a9c4ef;
    border-radius: 6px;
    background: #ffffff;
    font-size: 12px;
    color: #111827;
    cursor: pointer;
}

.site-title {
    white-space: nowrap;
    font-weight: 600;
    font-size: 17px;
    color: #ffffff;
}

.logo-dodo {
    height: 42px;
    width: 42px;
    object-fit: contain;
    border-radius: 10px;
}

.button {
    display: inline-block;
    padding: 8px 14px;
    background: var(--primary);
    color: #ffffff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
}

main {
    width: 100%;
    margin: 0;
    padding: 24px;
}

@media (min-width: 901px) and (min-height: 501px) {
    main {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow-y: auto;
    }

    .modules-container {
        flex: 0 0 auto;
    }

    .dashboard-card {
        flex: 1 1 auto;
        min-height: 50vh;
        display: flex;
        flex-direction: column;
    }

    .graph-container {
        flex: 1 1 auto;
        height: auto;
        min-height: 160px;
    }
}

.modules-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
    width: 100%;
}

.module {
    flex: 1 1 0;
    min-width: 0;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.label-full {
    display: inline;
}

.label-short {
    display: none;
}

@media (max-width: 900px), (max-height: 500px) {
    header {
        padding: 6px 10px;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .header-left {
        flex: 1 1 0;
        min-width: 0;
    }

    .header-right {
        flex: 0 1 auto;
        min-width: 0;
    }

    .header-controls {
        flex-wrap: nowrap;
        gap: 5px;
    }

    .logo-dodo {
        height: 32px;
        width: 32px;
    }

    .site-title {
        font-size: 14px;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .currency-select, .lang-select {
        padding: 3px 4px;
        font-size: 12px;
    }

    .back-pill {
        padding: 4px 9px;
        font-size: 11px;
        gap: 4px;
    }

    .header-updated {
        font-size: 10px;
    }

    main {
        padding: 8px;
    }

    .modules-container {
        flex-direction: column;
        gap: 8px;
    }

    .module {
        flex: 1 1 auto;
        width: 100%;
    }

    .module-header {
        padding: 10px 12px;
        font-size: 13px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .toggle-option {
        padding: 5px 8px;
        font-size: 11px;
    }

    .module-content {
        overflow-x: hidden;
    }

    table {
        table-layout: fixed;
        width: 100%;
    }

    thead td {
        padding: 4px 2px;
        font-size: 10px;
        white-space: normal;
        line-height: 1.15;
        vertical-align: bottom;
    }

    tbody td {
        padding: 6px 2px;
        font-size: 13px;
        font-weight: 600;
        white-space: nowrap;
        line-height: 1.2;
        text-align: center;
    }

    tbody td:first-child {
        font-size: 13px;
        font-weight: 700;
        text-align: left;
    }

    .sales-diff {
        white-space: normal;
    }

    .diff-amount,
    .diff-percent {
        white-space: nowrap;
    }

    .label-full {
        display: none;
    }

    .label-short {
        display: inline;
    }

    .dashboard-card {
        padding: 16px;
    }

    .graph-container {
        height: 300px;
    }

    .controls-header {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        flex-wrap: wrap;
    }

    .chart-select {
        flex: 1 1 auto;
    }

    .date-range-picker {
        flex: 1 1 auto;
    }

    .groups-header {
        flex-wrap: wrap;
        gap: 8px;
    }
}

.module-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    background: #f3f4f6;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 16px;
}

.sales-toggle {
    display: flex;
    gap: 6px;
    background: #e5e7eb;
    border-radius: 8px;
    padding: 3px;
}

.toggle-option {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-muted);
}

.toggle-option.active {
    background: #ffffff;
    color: #111827;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.module-content {
    overflow-x: auto;
}

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

thead td {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 13px 22px;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 15px 22px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #f9fafb;
}

tbody a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

tbody a:hover {
    text-decoration: underline;
}

.dashboard-card {
    margin-top: 24px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
}

.graph-container {
    height: 480px;
    position: relative;
}

.no-data {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
}

.chart-loading {
    display: none;
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
}

.dashboard-card.loading .chart-loading {
    display: block;
}

.dashboard-card.loading .controls-header,
.dashboard-card.loading .groups-header,
.dashboard-card.loading .group-controls,
.dashboard-card.loading canvas {
    display: none;
}

.dashboard-card .controls-header,
.dashboard-card .groups-header,
.dashboard-card .group-controls,
.dashboard-card canvas {
    opacity: 0;
    animation: page-fade-in 0.4s ease-out forwards;
}

.controls-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    font-size: 13px;
    color: #111827;
}

.btn-group {
    display: flex;
    gap: 5px;
}

.date-btn {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

.date-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.date-range-picker {
    display: flex;
    align-items: center;
    gap: 6px;
}

.date-input {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: #111827;
}

.date-separator {
    color: var(--text-muted);
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    user-select: none;
}

.toggle-switch {
    width: 34px;
    height: 20px;
    border-radius: 999px;
    background: #d1d5db;
    position: relative;
    transition: background 0.15s;
}

.toggle-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    transition: left 0.15s;
}

.merge-check:checked + .toggle-switch {
    background: var(--primary);
}

.merge-check:checked + .toggle-switch::after {
    left: 16px;
}

.action-btn {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    font-size: 13px;
    cursor: pointer;
    color: #111827;
}

.action-btn:hover, .date-btn:hover {
    border-color: var(--primary);
}

.groups-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.groups-label {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
}

.groups-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-updated-label {
    color: var(--text-muted);
    font-size: 11px;
}

.link-btn {
    border: none;
    background: none;
    font-size: 11px;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
}

.link-btn:last-child {
    color: var(--text-muted);
}

.group-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
}

.franchise-btn {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

.franchise-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.telegram-cta {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-left: 4px solid #cfe0fb;
    border-radius: 10px;
    padding: 10px 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    color: #111827;
    max-width: 260px;
    font-size: 12px;
    z-index: 100;
    transition: transform 0.15s, box-shadow 0.15s;
}

.telegram-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
}

.telegram-cta span {
    color: var(--text-muted);
}

.telegram-cta strong {
    color: #2563eb;
    font-size: 13px;
}

@media (max-width: 900px), (max-height: 500px) {
    .telegram-cta {
        display: none;
    }
}

.pwa-install-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #3f4654;
    color: #ffffff;
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 200;
    font-size: 14px;
}

.pwa-install-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
}

.pwa-install-banner .action-btn {
    background: #ffffff;
    color: #3f4654;
    border: none;
    font-weight: 600;
}

.pwa-install-banner .link-btn {
    color: #c3c9d4;
}

@media (min-width: 901px) and (min-height: 501px) {
    .pwa-install-banner {
        left: auto;
        right: 20px;
        bottom: 20px;
        max-width: 320px;
    }
}
