/* ─── Shopify Analytics Dashboard ─────────────────────────────────── */
/* Uses Lightspeed design system tokens for consistent branding       */

.sd-dashboard {
    padding: 24px;
    width: 100%;
    font-family: var(--font-family, 'Inter', 'Helvetica Neue', Arial, sans-serif);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Header */
.sd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.sd-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary, #0A2540);
    margin: 0;
}

.sd-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sd-sync-indicator {
    font-size: 0.75rem;
    color: var(--text-muted, #6B7C93);
    display: flex;
    align-items: center;
    gap: 6px;
}

.sd-sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success, #30B130);
    display: inline-block;
}

.sd-sync-dot.syncing {
    background: #f59e0b;
    animation: sd-pulse 1s ease-in-out infinite;
}

.sd-sync-dot.error {
    background: var(--danger, #DF1B41);
}

@keyframes sd-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.sd-date-select {
    padding: 10px 14px;
    border: 2px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg-alt, #F6F9FC);
    color: var(--text-primary, #0A2540);
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7C93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 34px;
}

.sd-date-select:focus {
    border-color: var(--cta, #635BFF);
    background-color: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.12);
}

.sd-compare-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary, #425466);
    cursor: pointer;
}

.sd-compare-toggle input {
    accent-color: var(--cta, #635BFF);
}

.sd-btn {
    padding: 10px 16px;
    border: 1px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    background: var(--bg-alt, #F6F9FC);
    color: var(--text-primary, #0A2540);
    cursor: pointer;
    transition: all 0.2s ease;
}

.sd-btn:hover {
    background: #FFFFFF;
    border-color: var(--text-muted, #6B7C93);
}

.sd-btn-primary {
    background: var(--cta, #635BFF);
    color: #fff;
    border-color: var(--cta, #635BFF);
    font-weight: 600;
    border-radius: var(--radius-pill, 24px);
}

.sd-btn-primary:hover {
    background: var(--cta-hover, #7A73FF);
    border-color: var(--cta-hover, #7A73FF);
    transform: translateY(-1px);
}

.sd-btn-gradient {
    background: linear-gradient(135deg, #E91E8C, #F47B3A, #F5C623);
    color: #fff;
    border: none;
    font-weight: 600;
    border-radius: var(--radius-pill, 24px);
    padding: 10px 20px;
}

.sd-btn-gradient:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Sync Banner */
.sd-sync-banner {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: var(--radius-md, 8px);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: #d97706;
    display: none;
}

/* KPI Cards */
.sd-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.sd-kpi-card {
    background: linear-gradient(90deg, #0F3460 0%, #5B1A6E 30%, #E91E8C 55%, #F47B3A 80%, #F5C623 100%);
    background-size: 150% 100%;
    background-position: 0% 50%;
    border: none;
    border-radius: var(--radius-lg, 12px);
    padding: 20px;
    box-shadow: var(--shadow-md, 0 2px 4px rgba(0, 0, 0, 0.15));
    transition: all 0.4s ease;
    position: relative;
    overflow: hidden;
}

.sd-kpi-card:hover {
    transform: translateY(-2px);
    background-position: 50% 50%;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.sd-kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.sd-kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: #FFFFFF;
    line-height: 1.15;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.sd-kpi-change {
    font-size: 0.8rem;
    font-weight: 500;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.sd-kpi-change.positive {
    color: #86efac;
}

.sd-kpi-change.negative {
    color: #fca5a5;
}

.sd-kpi-change.neutral {
    color: rgba(255, 255, 255, 0.7);
}

.sd-kpi-sparkline {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    opacity: 0.15;
}

/* Main Content Layout */
.sd-content {
    display: grid;
    grid-template-columns: 60% 40%;
    gap: 20px;
    align-items: stretch;
}

.sd-left-col {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sd-right-col {
    position: relative;
    min-height: 0;
}

.sd-right-col > .sd-card {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sdOrderFeedWrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.sd-card {
    background: #FFFFFF;
    border: 1px solid var(--border, #E3E8EE);
    border-radius: var(--radius-lg, 12px);
    padding: 24px;
    box-shadow: var(--shadow-md, 0 2px 4px rgba(0, 0, 0, 0.05));
    transition: all 0.3s ease;
}

.sd-card:hover {
    box-shadow: var(--shadow-lg, 0 4px 12px rgba(0, 0, 0, 0.08));
}

.sd-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary, #0A2540);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sd-card-title .sd-toggle-group {
    display: flex;
    gap: 4px;
}

.sd-toggle-btn {
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    background: var(--bg-alt, #F6F9FC);
    color: var(--text-secondary, #425466);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.sd-toggle-btn:hover {
    border-color: var(--text-muted, #6B7C93);
}

.sd-toggle-btn.active {
    background: var(--cta, #635BFF);
    color: #fff;
    border-color: var(--cta, #635BFF);
}

/* Chart Container */
.sd-chart-container {
    position: relative;
    width: 100%;
    height: 280px;
}

.sd-chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Donut Chart */
.sd-donut-container {
    position: relative;
    width: 100%;
    height: 220px;
}

/* Products Table */
.sd-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.sd-table th {
    text-align: left;
    font-weight: 600;
    color: #9ca3af;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border, #E3E8EE);
    cursor: pointer;
    user-select: none;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sd-table th:hover {
    color: var(--text-primary, #0A2540);
}

.sd-table td {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid #F3F4F6;
    color: var(--text-primary, #0A2540);
}

.sd-table tr:last-child td {
    border-bottom: none;
}

.sd-table .sd-rank {
    color: var(--text-muted, #6B7C93);
    font-weight: 500;
    width: 30px;
}

.sd-table .sd-amount {
    font-weight: 600;
    text-align: right;
}

.sd-table .sd-pct {
    color: var(--text-muted, #6B7C93);
    text-align: right;
    width: 60px;
}

/* Region Bars */
.sd-region-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.sd-region-label {
    font-size: 0.8rem;
    color: var(--text-primary, #0A2540);
    width: 120px;
    text-align: right;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sd-region-track {
    flex: 1;
    height: 24px;
    background: var(--bg-alt, #F6F9FC);
    border-radius: var(--radius-sm, 4px);
    overflow: hidden;
}

.sd-region-fill {
    height: 100%;
    background: linear-gradient(90deg, #635BFF, #E91E8C);
    border-radius: var(--radius-sm, 4px);
    min-width: 2px;
    transition: width 0.4s ease;
}

.sd-region-value {
    font-size: 0.75rem;
    color: var(--text-muted, #6B7C93);
    width: 80px;
    flex-shrink: 0;
}

/* Live Order Feed — max-height set dynamically by JS to match left column */
.sd-order-feed {
    overflow-y: auto;
}

.sd-order-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #F3F4F6;
    gap: 10px;
}

.sd-order-item:last-child {
    border-bottom: none;
}

.sd-order-info {
    flex: 1;
    min-width: 0;
}

.sd-order-number {
    font-weight: 600;
    color: var(--text-primary, #0A2540);
    font-size: 0.85rem;
}

.sd-order-customer {
    font-size: 0.75rem;
    color: var(--text-muted, #6B7C93);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sd-order-amount {
    font-weight: 700;
    color: var(--text-primary, #0A2540);
    font-size: 0.85rem;
    white-space: nowrap;
}

.sd-order-time {
    font-size: 0.7rem;
    color: var(--text-muted, #6B7C93);
    white-space: nowrap;
}

.sd-order-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.sd-badge-paid {
    background: #dcfce7;
    color: #15803d;
}

.sd-badge-pending {
    background: #fef3c7;
    color: #d97706;
}

.sd-badge-refunded {
    background: #fee2e2;
    color: #dc2626;
}

.sd-badge-fulfilled {
    background: #dcfce7;
    color: #15803d;
}

.sd-badge-unfulfilled {
    background: #fef3c7;
    color: #d97706;
}

.sd-badge-partial {
    background: #ede9fe;
    color: #635BFF;
}

/* Skeleton Loading */
.sd-skeleton {
    background: linear-gradient(90deg, #F6F9FC 25%, #E3E8EE 50%, #F6F9FC 75%);
    background-size: 200% 100%;
    animation: sd-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md, 8px);
}

@keyframes sd-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.sd-skeleton-kpi {
    height: 80px;
}

.sd-skeleton-chart {
    height: 280px;
}

.sd-skeleton-row {
    height: 36px;
    margin-bottom: 8px;
}

/* Empty State */
.sd-empty-state {
    text-align: center;
    padding: 80px 20px;
}

.sd-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.sd-empty-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary, #0A2540);
    margin-bottom: 8px;
}

.sd-empty-desc {
    font-size: 0.9rem;
    color: var(--text-secondary, #425466);
    margin-bottom: 24px;
    line-height: 1.6;
}

/* Full-Width Row (below main 2-col grid) */
.sd-full-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 20px;
}

/* Search Bar */
.sd-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 0;
}

.sd-search-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg-alt, #F6F9FC);
    color: var(--text-primary, #0A2540);
    outline: none;
    transition: all 0.2s ease;
}

.sd-search-input:focus {
    border-color: var(--cta, #635BFF);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.12);
}

.sd-search-results {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 10px;
}

/* Custom Date Range */
.sd-custom-dates {
    display: none;
    align-items: center;
    gap: 8px;
}

.sd-custom-dates.visible {
    display: flex;
}

.sd-date-input {
    padding: 8px 12px;
    border: 2px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--bg-alt, #F6F9FC);
    color: var(--text-primary, #0A2540);
    outline: none;
    transition: all 0.2s ease;
}

.sd-date-input:focus {
    border-color: var(--cta, #635BFF);
    background: #fff;
}

/* Export Dropdown */
.sd-export-wrap {
    position: relative;
    display: inline-block;
}

.sd-export-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 100;
    min-width: 160px;
    padding: 4px 0;
}

.sd-export-menu.open {
    display: block;
}

.sd-export-option {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    font-size: 0.84rem;
    font-family: inherit;
    color: var(--text-primary, #0A2540);
    cursor: pointer;
    transition: background 0.15s;
}

.sd-export-option:hover {
    background: var(--bg-alt, #F6F9FC);
}

/* AI Insights */
.sd-insights-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sd-insight-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px;
    background: var(--bg-alt, #F6F9FC);
    border-radius: var(--radius-md, 8px);
    border-left: 3px solid var(--cta, #635BFF);
}

.sd-insight-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    line-height: 1.4;
}

.sd-insight-text {
    font-size: 0.84rem;
    color: var(--text-primary, #0A2540);
    line-height: 1.5;
}

.sd-insight-text strong {
    color: var(--cta, #635BFF);
}

.sd-insight-loading {
    text-align: center;
    padding: 30px;
    color: var(--text-muted, #6B7C93);
    font-size: 0.85rem;
}

/* Ask Lightspeed Embed */
.sd-als-panel {
    margin-top: 20px;
}

.sd-als-container {
    display: flex;
    flex-direction: column;
    height: 400px;
    border: 1px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
    background: #fff;
}

.sd-als-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sd-als-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted, #6B7C93);
    font-size: 0.85rem;
    text-align: center;
    padding: 20px;
}

.sd-als-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.84rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.sd-als-msg.user {
    align-self: flex-end;
    background: var(--cta, #635BFF);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.sd-als-msg.assistant {
    align-self: flex-start;
    background: var(--bg-alt, #F6F9FC);
    color: var(--text-primary, #0A2540);
    border-bottom-left-radius: 4px;
}

.sd-als-msg.status {
    align-self: center;
    background: none;
    color: var(--text-muted, #6B7C93);
    font-size: 0.78rem;
    font-style: italic;
    padding: 4px;
}

.sd-als-input-row {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border, #E3E8EE);
    background: var(--bg-alt, #F6F9FC);
}

.sd-als-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--border, #E3E8EE);
    border-radius: var(--radius-md, 8px);
    font-size: 0.85rem;
    font-family: inherit;
    background: #fff;
    color: var(--text-primary, #0A2540);
    outline: none;
    resize: none;
    transition: border-color 0.2s;
}

.sd-als-input:focus {
    border-color: var(--cta, #635BFF);
}

.sd-als-send {
    padding: 10px 18px;
    background: var(--cta, #635BFF);
    color: #fff;
    border: none;
    border-radius: var(--radius-md, 8px);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.sd-als-send:hover {
    background: var(--cta-hover, #7A73FF);
}

.sd-als-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Whale/Customer avatar */
.sd-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #635BFF, #E91E8C);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sd-customer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #F3F4F6;
}

.sd-customer-row:last-child {
    border-bottom: none;
}

.sd-customer-info {
    flex: 1;
    min-width: 0;
}

.sd-customer-name {
    font-weight: 600;
    font-size: 0.84rem;
    color: var(--text-primary, #0A2540);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sd-customer-meta {
    font-size: 0.72rem;
    color: var(--text-muted, #6B7C93);
}

.sd-customer-amount {
    font-weight: 700;
    font-size: 0.84rem;
    color: var(--text-primary, #0A2540);
    white-space: nowrap;
}

/* Price Point Chart */
.sd-price-chart-container {
    position: relative;
    width: 100%;
    height: 250px;
}

/* Responsive */
@media (max-width: 1024px) {
    .sd-kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .sd-content {
        grid-template-columns: 1fr;
    }
    .sd-full-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .sd-dashboard {
        padding: 16px;
    }
    .sd-kpi-row {
        grid-template-columns: 1fr;
    }
    .sd-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .sd-kpi-value {
        font-size: 1.5rem;
    }
    .sd-custom-dates {
        flex-wrap: wrap;
    }
}
