/* CSS Design System for Aliyun Bill Discount Analyzer */
:root {
    --bg-color: #0b0f19;
    --card-bg: rgba(22, 28, 45, 0.65);
    --card-border: rgba(255, 255, 255, 0.07);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --success-color: #10b981;
    --success-hover: #059669;
    --error-color: #ef4444;
    --error-hover: #dc2626;
    --cyan-color: #06b6d4;
    --purple-color: #8b5cf6;
    --gold-color: #f59e0b;
    --font-sans: 'Inter', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    line-height: 1.5;
}

/* Background glowing decorations */
.glow-bg {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(140px);
    opacity: 0.12;
    z-index: -1;
    pointer-events: none;
    animation: float 20s infinite alternate;
}

.bg-purple {
    background: var(--purple-color);
    top: -150px;
    right: -100px;
}

.bg-blue {
    background: var(--primary-color);
    bottom: -150px;
    left: -100px;
    animation-delay: 2s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(60px, 40px) scale(1.15); }
}

/* Container */
.app-container {
    max-width: 95%;
    width: 1800px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 3rem;
}

.header-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    font-size: 2.5rem;
}

.app-header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a78bfa, #6366f1, #3b82f6, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.header-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 400;
}

/* Layout */
.app-content {
    display: grid;
    grid-template-columns: 30% 65%;
    justify-content: space-between;
    align-items: start;
}

@media (max-width: 1024px) {
    .app-content {
        grid-template-columns: 1fr;
    }
    .config-section {
        position: relative;
        top: 0;
        height: auto;
        min-height: auto;
    }
    .config-table-container {
        max-height: 400px;
        flex: none;
    }
}

/* Card glassmorphism style */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    padding: 1.8rem;
    margin-bottom: 1.5rem;
    transition: var(--transition-smooth);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* Config Section Sticky Layout */
.config-section {
    position: sticky;
    top: 2rem;
    height: calc(100vh - 10rem);
    min-height: 550px;
    display: flex;
    flex-direction: column;
}

/* Table Style for Config */
.config-table-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 1.5rem;
}

.config-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.config-table th {
    background: #161c2d;
    color: var(--text-primary);
    font-weight: 600;
    padding: 0.8rem 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--card-border);
}

.config-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    vertical-align: middle;
}

.config-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Form controls */
.model-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    width: 100%;
    transition: var(--transition-smooth);
}

.model-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.3);
}

.form-select {
    padding: 8px 12px;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-select option {
    background-color: #1e2436;
    color: #f3f4f6;
}

.discount-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.discount-input {
    width: 70px;
    text-align: center;
}

.discount-percent {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.actions-col {
    width: 60px;
    text-align: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), #6366f1);
    color: #fff;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.35);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), #4f46e5);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-success {
    background: linear-gradient(135deg, var(--success-color), #34d399);
    color: #fff;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    background: linear-gradient(135deg, var(--success-hover), #10b981);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

.btn-danger-icon {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    transition: var(--transition-smooth);
}

.btn-danger-icon:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error-color);
}

.btn-large {
    padding: 0.8rem 1.8rem;
    font-size: 0.95rem;
    border-radius: 10px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none !important;
}

/* Upload Card Dropzone */
.drop-zone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 2.2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.15);
    transition: var(--transition-smooth);
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--cyan-color);
    background: rgba(6, 182, 212, 0.05);
}

.upload-icon {
    font-size: 2.8rem;
    animation: pulse 2s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.08); }
}

.drop-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.browse-link {
    color: var(--cyan-color);
    text-decoration: underline;
    font-weight: 500;
}

/* File Info Box */
.file-info {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    margin-bottom: 1.5rem;
    gap: 1rem;
    animation: fadeIn 0.3s ease;
}

.file-icon {
    font-size: 1.8rem;
}

.file-meta {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    overflow: hidden;
}

.file-name {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition-smooth);
}

.btn-close:hover {
    color: #fff;
}

.action-buttons {
    display: flex;
    gap: 1rem;
}

.action-buttons button {
    flex: 1;
}

/* Loading Spinner */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 1rem;
    color: var(--text-secondary);
    animation: fadeIn 0.3s ease;
}

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

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Results Section Summary Cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.2rem;
    margin-bottom: 1.5rem;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 640px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }
}

.summary-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 1.2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.summary-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.gold-border::after { background: var(--gold-color); }
.cyan-border::after { background: var(--cyan-color); }
.green-border::after { background: var(--success-color); }
.purple-border::after { background: var(--purple-color); }

.summary-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.summary-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.45rem;
    font-weight: 700;
}

/* Groups Card Container */
.groups-card {
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-weight: 500;
}

.groups-list {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    margin-top: 1rem;
}

/* Group Row Card Collapse Item */
.group-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    overflow: hidden;
    transition: var(--transition-smooth);
}

.group-item:hover {
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.1rem 1.4rem;
    cursor: pointer;
    user-select: none;
}

.group-title-section {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.group-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cyan-color);
}

.group-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1.05rem;
}

.group-records-count {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.group-sums {
    display: flex;
    align-items: center;
    gap: 1.8rem;
}

.group-sum-val {
    display: flex;
    flex-direction: column;
    text-align: right;
}

.group-sum-lbl {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.group-sum-num {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
}

.discount-highlight {
    color: var(--success-color);
}

.arrow-icon {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
}

.group-item.expanded .arrow-icon {
    transform: rotate(90deg);
}

/* Group Body Collapsible */
.group-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0);
}

.group-item.expanded .group-body {
    max-height: 2000px; /* high enough limit */
    border-top-color: rgba(255, 255, 255, 0.03);
}

.group-body-content {
    padding: 1.2rem 1.4rem;
}

.detail-table-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--cyan-color);
    margin-bottom: 0.6rem;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.detail-table-container {
    overflow-x: auto;
    margin-bottom: 1.2rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.detail-table-container:last-child {
    margin-bottom: 0;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.detail-table th {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    font-weight: 500;
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
}

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

.detail-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.01);
}

.rate-badge {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.rate-badge.none {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border-color: rgba(255, 255, 255, 0.07);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: #1e1b4b;
    border: 1px solid var(--purple-color);
    color: #fff;
    padding: 0.8rem 1.4rem;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(10px);
    transition: var(--transition-smooth);
    z-index: 9999;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Scrollbar customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Interactive sub-detail row styling */
.detail-table tbody tr.clickable-row {
    cursor: pointer;
    transition: var(--transition-smooth);
}

.detail-table tbody tr.clickable-row:hover {
    background: rgba(6, 182, 212, 0.08) !important;
}

.detail-table tbody tr.clickable-row.expanded {
    background: rgba(6, 182, 212, 0.04);
}

.sub-detail-row {
    background: rgba(0, 0, 0, 0.3) !important;
}

.sub-detail-row td {
    padding: 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04) !important;
}

.sub-detail-wrapper {
    padding: 0.8rem 1.4rem;
    animation: fadeIn 0.25s ease-out;
}

.nested-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    overflow: hidden;
}

.nested-detail-table th {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    padding: 0.5rem 0.8rem;
    font-weight: 500;
    text-align: left;
}

.nested-detail-table td {
    padding: 0.5rem 0.8rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

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

.row-toggle-icon {
    display: inline-block;
    font-size: 0.7rem;
    margin-right: 0.5rem;
    color: var(--cyan-color);
    transition: transform 0.2s ease;
}

.clickable-row.expanded .row-toggle-icon {
    transform: rotate(90deg);
}
