// Promo Code Dashboard Styles
// Using LESS with less.js via CDN

// ===========================================
// Variables
// ===========================================

@primary-color: #4361ee;
@secondary-color: #3f37c9;
@success-color: #06d6a0;
@warning-color: #ffd166;
@danger-color: #ef476f;
@dark-color: #1a1a2e;
@light-color: #f8f9fa;
@gray-color: #6c757d;

@spacing-xs: 4px;
@spacing-sm: 8px;
@spacing-md: 16px;
@spacing-lg: 24px;
@spacing-xl: 32px;

@border-radius: 12px;
@border-radius-sm: 6px;

@shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
@shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
@shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);

@transition-fast: 0.15s ease;
@transition-normal: 0.25s ease;

// ===========================================
// Base
// ===========================================

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

// ===========================================
// Login Page
// ===========================================

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: @spacing-md;
}

.login-card {
    background: white;
    border-radius: @border-radius;
    box-shadow: @shadow-lg;
    padding: @spacing-xl;
    width: 100%;
    max-width: 400px;
    text-align: center;

    h1 {
        color: @dark-color;
        font-size: 1.75rem;
        margin-bottom: @spacing-xs;
    }

    .subtitle {
        color: @gray-color;
        margin-bottom: @spacing-lg;
    }

    .form-control {
        border-radius: @border-radius-sm;
        padding: @spacing-md;
        border: 2px solid #e9ecef;
        transition: border-color @transition-fast;

        &:focus {
            border-color: @primary-color;
            box-shadow: 0 0 0 3px fade(@primary-color, 15%);
        }
    }

    .btn-login {
        background: @primary-color;
        border: none;
        border-radius: @border-radius-sm;
        padding: @spacing-md @spacing-lg;
        font-weight: 600;
        width: 100%;
        transition: background @transition-fast, transform @transition-fast;

        &:hover {
            background: @secondary-color;
            transform: translateY(-1px);
        }
    }

    .error-message {
        color: @danger-color;
        margin-top: @spacing-md;
        font-size: 0.875rem;
    }
}

// ===========================================
// Dashboard Layout
// ===========================================

.dashboard-container {
    padding: @spacing-lg;
    max-width: 1400px;
    margin: 0 auto;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: @spacing-xl;
    flex-wrap: wrap;
    gap: @spacing-md;

    h1 {
        color: white;
        font-size: 1.75rem;
        margin: 0;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    .header-actions {
        display: flex;
        align-items: center;
        gap: @spacing-md;
    }

    .view-toggle {
        .btn-view {
            background: rgba(255, 255, 255, 0.15);
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: rgba(255, 255, 255, 0.7);
            padding: @spacing-sm @spacing-md;
            transition: all @transition-fast;

            &:hover {
                background: rgba(255, 255, 255, 0.25);
                color: white;
            }

            &.active {
                background: rgba(255, 255, 255, 0.3);
                color: white;
                border-color: rgba(255, 255, 255, 0.4);
            }

            &:first-child {
                border-radius: @border-radius-sm 0 0 @border-radius-sm;
            }

            &:last-child {
                border-radius: 0 @border-radius-sm @border-radius-sm 0;
            }
        }
    }

    .btn-logout {
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: white;
        border-radius: @border-radius-sm;
        padding: @spacing-sm @spacing-md;
        transition: background @transition-fast;

        &:hover {
            background: rgba(255, 255, 255, 0.3);
            color: white;
        }
    }
}

// ===========================================
// Promocode Validation Section
// ===========================================

.validate-section {
    background: rgba(255, 255, 255, 0.15);
    border-radius: @border-radius;
    padding: @spacing-sm @spacing-lg;
    margin-bottom: @spacing-md;
    backdrop-filter: blur(10px);
}

.validate-input-group {
    .input-group {
        max-width: 600px;
    }

    .form-control {
        border: 2px solid rgba(255, 255, 255, 0.3);
        border-right: none;
        padding: @spacing-sm @spacing-md;
        font-size: 1rem;
        background: white;

        &:focus {
            box-shadow: none;
            border-color: rgba(255, 255, 255, 0.5);
        }

        &::placeholder {
            color: @gray-color;
        }
    }

    .btn-validate {
        background: @primary-color;
        border: 2px solid @primary-color;
        color: white;
        padding: @spacing-sm @spacing-lg;
        font-weight: 600;
        transition: all @transition-fast;

        &:hover {
            background: @secondary-color;
            border-color: @secondary-color;
        }
    }
}

.validate-results {
    margin-top: @spacing-sm;
}

.validate-not-found {
    background: fade(@danger-color, 15%);
    border: 1px solid fade(@danger-color, 30%);
    border-radius: @border-radius-sm;
    padding: @spacing-lg;
    display: flex;
    align-items: center;
    gap: @spacing-md;

    > i {
        font-size: 2rem;
        color: @danger-color;
    }

    .validate-not-found-text {
        display: flex;
        flex-direction: column;
        gap: @spacing-xs;

        strong {
            color: @danger-color;
            font-size: 1.1rem;
        }

        span {
            color: darken(@danger-color, 20%);
        }

        code {
            background: rgba(0, 0, 0, 0.1);
            padding: 2px 6px;
            border-radius: 4px;
            color: @dark-color;
        }
    }
}

.validate-found {
    background: white;
    border-radius: @border-radius-sm;
    overflow: hidden;
    box-shadow: @shadow-sm;
}

.validate-found-header {
    background: fade(@success-color, 15%);
    border-bottom: 1px solid fade(@success-color, 30%);
    padding: @spacing-md @spacing-lg;
    display: flex;
    align-items: center;
    gap: @spacing-sm;

    > i {
        font-size: 1.25rem;
        color: @success-color;
    }

    span {
        color: darken(@success-color, 30%);
        font-weight: 500;
    }

    code {
        background: rgba(0, 0, 0, 0.08);
        padding: 2px 6px;
        border-radius: 4px;
        color: @dark-color;
        font-weight: 600;
    }
}

.validate-found-results {
    padding: @spacing-sm 0;
}

.validate-result-item {
    padding: @spacing-md @spacing-lg;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: @spacing-sm;
    border-bottom: 1px solid #eee;

    &:last-child {
        border-bottom: none;
    }

    &:hover {
        background: @light-color;
    }
}

.validate-result-table {
    display: flex;
    align-items: center;

    i {
        color: @primary-color;
    }

    strong {
        color: @dark-color;
    }
}

.validate-result-status {
    display: flex;
    align-items: center;
    gap: @spacing-sm;
    flex-wrap: wrap;

    .badge {
        font-weight: 500;
    }
}

.validate-date {
    font-size: 0.85rem;
    color: @gray-color;
    margin-left: @spacing-sm;
}

// ===========================================
// Stats Cards
// ===========================================

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: @spacing-lg;
    transition: all @transition-normal;

    // ===========================================
    // List View Mode
    // ===========================================
    &.view-list {
        grid-template-columns: 1fr;

        .stats-card {
            display: flex;
            flex-direction: row;
            align-items: stretch;

            &:hover {
                transform: translateY(-2px);
            }
        }

        .card-header {
            flex-shrink: 0;
            width: 180px;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            gap: @spacing-sm;
            padding: @spacing-md @spacing-lg;

            h3 {
                font-size: 1rem;
            }

            .card-header-actions {
                flex-direction: column;
            }

            .btn-upload,
            .btn-get-code {
                font-size: 0.75rem;
                padding: @spacing-xs @spacing-sm;
                width: 100%;
                text-align: center;
            }
        }

        .card-body {
            flex: 1;
            display: flex;
            align-items: center;
            gap: @spacing-lg;
            padding: @spacing-md @spacing-lg;
        }

        .stats-row {
            flex: 0 0 auto;
            margin-bottom: 0;
            gap: @spacing-lg;
        }

        .stat-item {
            min-width: 80px;

            .stat-value {
                font-size: 1.25rem;
            }

            .stat-label {
                font-size: 0.65rem;
            }
        }

        .last-used {
            flex: 0 0 auto;
            margin-bottom: 0;
            white-space: nowrap;
            font-size: 0.8rem;
        }

        .sparkline-container {
            flex: 1;
            min-width: 150px;
            max-width: 300px;
            height: auto;
            margin-top: 0;
            padding-top: 0;
            border-top: none;
            border-left: 1px solid #eee;
            padding-left: @spacing-lg;
        }

        .sparkline-label {
            display: none;
        }

        .sparkline-canvas {
            height: 35px !important;
        }
    }
}

.stats-card {
    background: white;
    border-radius: @border-radius;
    box-shadow: @shadow-md;
    overflow: hidden;
    transition: transform @transition-normal, box-shadow @transition-normal;

    &:hover {
        transform: translateY(-4px);
        box-shadow: @shadow-lg;
    }

    &.stats-card-missing {
        border: 2px dashed rgba(108, 117, 125, 0.4);
        box-shadow: none;
        opacity: 0.85;

        &:hover {
            opacity: 1;
            border-color: @primary-color;
        }

        .card-body {
            padding: @spacing-xl @spacing-lg;
        }

        .btn-create-table {
            background: @primary-color;
            border: none;
            color: white;
            border-radius: @border-radius-sm;
            padding: @spacing-sm @spacing-lg;
            font-weight: 600;
            transition: background @transition-fast;

            &:hover {
                background: @secondary-color;
            }

            &:disabled {
                opacity: 0.7;
            }
        }
    }
}

.card-header {
    background: @dark-color;
    color: white;
    padding: @spacing-md @spacing-lg;
    display: flex;
    justify-content: space-between;
    align-items: center;

    h3 {
        margin: 0;
        font-size: 1.1rem;
        font-weight: 600;
    }

    .card-header-actions {
        display: flex;
        gap: @spacing-xs;
    }

    .btn-upload,
    .btn-get-code {
        background: rgba(255, 255, 255, 0.15);
        border: none;
        color: white;
        border-radius: @border-radius-sm;
        padding: @spacing-xs @spacing-sm;
        font-size: 0.8rem;
        transition: background @transition-fast;
        white-space: nowrap;

        &:hover {
            background: rgba(255, 255, 255, 0.25);
        }

        &:disabled {
            opacity: 0.7;
        }

        i {
            margin-right: @spacing-xs;
        }
    }

    .btn-get-code {
        background: fade(@success-color, 30%);

        &:hover {
            background: fade(@success-color, 45%);
        }
    }
}

// ===========================================
// Get Code Modal
// ===========================================

.get-code-modal-header {
    background: darken(@success-color, 15%);
}

.get-code-field {
    background: @light-color;
    border: 2px solid fade(@success-color, 40%);
    border-radius: @border-radius-sm;
    padding: @spacing-md @spacing-lg;
    font-size: 1.3rem;
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: @dark-color;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all @transition-fast;
    word-break: break-all;
    user-select: all;

    &:hover {
        background: fade(@success-color, 10%);
        border-color: @success-color;
    }

    &:active {
        transform: scale(0.98);
    }
}

.get-code-copied {
    display: none;
    color: @success-color;
    font-weight: 600;
    font-size: 0.9rem;
    margin-top: @spacing-sm;
}

.card-body {
    padding: @spacing-lg;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    gap: @spacing-md;
    margin-bottom: @spacing-lg;
}

.stat-item {
    text-align: center;
    flex: 1;

    .stat-value {
        font-size: 1.75rem;
        font-weight: 700;
        line-height: 1.2;
    }

    .stat-label {
        font-size: 0.75rem;
        color: @gray-color;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-top: @spacing-xs;
    }

    &.total .stat-value {
        color: @dark-color;
    }

    &.used .stat-value {
        color: @danger-color;
    }

    &.remaining .stat-value {
        color: @success-color;
    }
}

.last-used {
    font-size: 0.875rem;
    color: @gray-color;
    margin-bottom: @spacing-md;

    strong {
        color: @dark-color;
    }
}

// ===========================================
// Promotion Info - Upload Modal Preview
// ===========================================

.promo-parsed-info {
    background: fade(@success-color, 10%);
    border: 1px solid fade(@success-color, 30%);
    border-radius: @border-radius-sm;
    padding: @spacing-md;
    margin-bottom: @spacing-md;
}

.promo-parsed-row {
    padding: @spacing-xs 0;
    font-size: 0.875rem;
    color: @dark-color;
    display: flex;
    align-items: center;

    i {
        color: @success-color;
        width: 20px;
        text-align: center;
        flex-shrink: 0;
    }

    strong {
        margin-right: @spacing-xs;
    }

    &:not(:last-child) {
        border-bottom: 1px solid fade(@success-color, 15%);
    }
}

.promo-file-id-preview {
    font-size: 0.85rem;
    color: @gray-color;
    padding: @spacing-xs @spacing-md;
    margin-bottom: @spacing-md;

    strong {
        font-family: 'Courier New', monospace;
        color: @dark-color;
        letter-spacing: 0.5px;
    }
}

// ===========================================
// Promotion Info - Stats Card
// ===========================================

.promo-info {
    font-size: 0.8rem;
    margin-bottom: @spacing-md;
    padding: @spacing-sm @spacing-md;
    background: fade(@primary-color, 5%);
    border-radius: @border-radius-sm;
    border-left: 3px solid @primary-color;

    &.promo-info-empty {
        background: fade(@gray-color, 8%);
        border-left-color: @gray-color;
        color: @gray-color;
        font-style: italic;
        padding: @spacing-sm @spacing-md;
    }
}

.promo-info-row {
    padding: 2px 0;
    display: flex;
    align-items: center;

    i {
        width: 16px;
        text-align: center;
        flex-shrink: 0;
        font-size: 0.7rem;
        color: @gray-color;
    }
}

.promo-tracking {
    .promo-tracking-id {
        font-family: 'Courier New', monospace;
        font-size: 0.75rem;
        color: @gray-color;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.promo-title-row {
    strong {
        color: @dark-color;
        font-size: 0.85rem;
    }
}

.promo-dates {
    display: flex;
    gap: @spacing-md;
    flex-wrap: wrap;
}

.promo-date-start,
.promo-date-end {
    display: inline-flex;
    align-items: center;
    color: @dark-color;

    i {
        margin-right: 2px;
    }
}

.promo-date-end {
    &.promo-ending-soon {
        color: darken(@warning-color, 20%);
        font-weight: 600;

        i {
            color: darken(@warning-color, 10%);
        }

        small {
            color: darken(@warning-color, 15%);
        }
    }

    &.promo-expired {
        color: @danger-color;
        font-weight: 600;

        i {
            color: @danger-color;
        }

        small {
            color: @danger-color;
        }
    }
}

.promo-uploaded {
    color: @gray-color;
    font-size: 0.75rem;
}

// ===========================================
// Sparkline Chart
// ===========================================

.sparkline-container {
    height: 60px;
    margin-top: @spacing-md;
    padding-top: @spacing-md;
    border-top: 1px solid #eee;
    cursor: pointer;
    border-radius: @border-radius-sm;
    transition: background @transition-fast;

    &:hover {
        background: fade(@primary-color, 5%);

        .sparkline-label {
            color: @primary-color;
        }
    }
}

.sparkline-label {
    font-size: 0.75rem;
    color: @gray-color;
    margin-bottom: @spacing-xs;
    transition: color @transition-fast;

    i {
        font-size: 0.65rem;
        opacity: 0.6;
    }
}

.sparkline-canvas {
    width: 100% !important;
    height: 40px !important;
}

.no-data {
    color: @gray-color;
    font-size: 0.875rem;
    font-style: italic;
    text-align: center;
    padding: @spacing-md 0;
}

// ===========================================
// Upload Modal
// ===========================================

.modal-content {
    border-radius: @border-radius;
    border: none;
    box-shadow: @shadow-lg;
}

.modal-header {
    background: @dark-color;
    color: white;
    border-radius: @border-radius @border-radius 0 0;
    border-bottom: none;

    .btn-close {
        filter: brightness(0) invert(1);
    }
}

.modal-body {
    padding: @spacing-lg;

    .alert-warning {
        border-radius: @border-radius-sm;
        border: none;
        background: fade(@warning-color, 20%);
        color: darken(@warning-color, 30%);
    }

    .form-label {
        font-weight: 600;
        color: @dark-color;
    }

    .form-control-file {
        padding: @spacing-md;
        border: 2px dashed #dee2e6;
        border-radius: @border-radius-sm;
        background: @light-color;
        cursor: pointer;
        transition: border-color @transition-fast;

        &:hover {
            border-color: @primary-color;
        }
    }
}

.modal-footer {
    border-top: 1px solid #eee;
    padding: @spacing-md @spacing-lg;

    .btn-cancel {
        background: @light-color;
        border: none;
        color: @dark-color;
    }

    .btn-upload-confirm {
        background: @danger-color;
        border: none;
        color: white;

        &:hover {
            background: darken(@danger-color, 10%);
        }

        &:disabled {
            opacity: 0.6;
        }
    }
}

// ===========================================
// History Modal
// ===========================================

#historyModal {
    .modal-body {
        padding: @spacing-xl;
    }
}

.history-chart-container {
    height: 200px;
    margin-bottom: @spacing-lg;
    padding-bottom: @spacing-lg;
    border-bottom: 1px solid #eee;
}

.history-summary {
    background: @light-color;
    border-radius: @border-radius-sm;
    padding: @spacing-lg;
    margin-bottom: @spacing-lg;

    .h4 {
        color: @primary-color;
        font-weight: 700;
    }

    .h6 {
        color: @dark-color;
    }
}

#historyTable {
    thead {
        background: @dark-color;
        color: white;

        th {
            font-weight: 600;
            font-size: 0.875rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            border: none;
            padding: @spacing-md;
        }
    }

    tbody {
        tr {
            transition: background @transition-fast;

            &:hover {
                background: fade(@primary-color, 8%);
            }
        }

        td {
            padding: @spacing-md;
            vertical-align: middle;
        }

        .badge {
            font-size: 0.875rem;
            padding: @spacing-xs @spacing-sm;
        }
    }
}

#historyEmpty {
    i {
        color: @gray-color;
        display: block;
    }

    p {
        margin: 0;
    }
}

// ===========================================
// Loading State
// ===========================================

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

// ===========================================
// Responsive
// ===========================================

// ===========================================
// Responsive - Tablet
// ===========================================

@media (max-width: 992px) {
    .stats-grid.view-list {
        .card-header {
            width: 140px;
        }

        .stat-item {
            min-width: 60px;

            .stat-value {
                font-size: 1.1rem;
            }
        }

        .sparkline-container {
            min-width: 100px;
            max-width: 200px;
        }
    }
}

// ===========================================
// Responsive - Mobile
// ===========================================

@media (max-width: 768px) {
    // Force grid view on mobile (list view doesn't fit)
    .stats-grid.view-list {
        .stats-card {
            flex-direction: column;
        }

        .card-header {
            width: 100%;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
        }

        .card-body {
            flex-direction: column;
            align-items: stretch;
            gap: @spacing-md;
        }

        .stats-row {
            width: 100%;
        }

        .last-used {
            text-align: center;
        }

        .sparkline-container {
            max-width: none;
            min-width: auto;
            border-left: none;
            border-top: 1px solid #eee;
            padding-left: 0;
            padding-top: @spacing-md;
        }

        .sparkline-label {
            display: block;
        }
    }
}

@media (max-width: 576px) {
    .dashboard-container {
        padding: @spacing-md;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;

        .header-actions {
            width: 100%;
            justify-content: space-between;
        }
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stats-row {
        flex-direction: column;
        gap: @spacing-sm;
    }

    .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;

        .stat-label {
            margin-top: 0;
            order: -1;
        }
    }
}
