/**
 * APS Calculators South Africa - Professional Clean Styling
 * Modern, compact, and elegant design
 */

/* CSS Variables - Clean Professional Palette */
:root {
    --aps-primary: #2563eb;
    --aps-primary-dark: #1e40af;
    --aps-primary-light: #dbeafe;
    --aps-success: #059669;
    --aps-warning: #d97706;
    --aps-danger: #dc2626;
    
    --aps-gray-50: #f9fafb;
    --aps-gray-100: #f3f4f6;
    --aps-gray-200: #e5e7eb;
    --aps-gray-300: #d1d5db;
    --aps-gray-400: #9ca3af;
    --aps-gray-500: #6b7280;
    --aps-gray-600: #4b5563;
    --aps-gray-700: #374151;
    --aps-gray-800: #1f2937;
    --aps-gray-900: #111827;
    
    --aps-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --aps-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --aps-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --aps-radius: 8px;
    --aps-radius-lg: 12px;
}

/* Container - Clean and Compact */
.aps-advanced-wrapper {
    max-width: 820px;
    margin: 1.5rem auto;
    font-family: 'Times', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--aps-gray-900);
}

.aps-advanced-container {
    background: #ffffff;
    border-radius: var(--aps-radius-lg);
    box-shadow: var(--aps-shadow-lg);
    overflow: hidden;
    border: 1px solid var(--aps-gray-200);
}

/* Header - Clean Gradient */
.aps-advanced-header {
    padding: 1.5rem 1.5rem 1rem;
    background: linear-gradient(135deg, var(--aps-primary) 0%, #3b82f6 100%);
    color: white;
}

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

.aps-advanced-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.aps-advanced-badge {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 100px;
    backdrop-filter: blur(8px);
    font-size: 0.75rem;
    font-weight: 500;
}

.aps-badge-icon {
    font-size: 1rem;
}

.aps-advanced-description {
    margin: 0.25rem 0 0;
    font-size: 0.875rem;
    opacity: 0.9;
}

/* Subjects Container */
.aps-subjects-container {
    padding: 1.25rem 1.5rem;
}

/* Subjects Header - Clean Grid */
.aps-subjects-header {
    display: grid;
    grid-template-columns: 2.5fr 1fr 0.7fr 0.3fr;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 2px solid var(--aps-gray-200);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--aps-gray-500);
}

/* Subject Row - Compact and Clean */
.aps-subject-row {
    display: grid;
    grid-template-columns: 2.5fr 1fr 0.7fr 0.3fr;
    gap: 0.75rem;
    align-items: center;
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.375rem;
    background: var(--aps-gray-50);
    border-radius: var(--aps-radius);
    border: 1px solid var(--aps-gray-200);
    transition: all 0.15s ease;
}

.aps-subject-row:hover {
    background: #ffffff;
    border-color: var(--aps-gray-300);
    box-shadow: var(--aps-shadow);
}

.aps-subject-row.duplicate {
    border-color: var(--aps-warning);
    background: #fffbeb;
    animation: shake 0.3s ease;
}

/* Subject Select - Clean Dropdown */
.aps-subject-select {
    width: 100%;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--aps-gray-300);
    border-radius: 6px;
    font-size: 0.875rem;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.5rem center;
    background-size: 16px;
    color: var(--aps-gray-900);
    cursor: pointer;
    appearance: none;
    transition: border-color 0.15s;
}

.aps-subject-select:hover {
    border-color: var(--aps-gray-400);
}

.aps-subject-select:focus {
    outline: none;
    border-color: var(--aps-primary);
    box-shadow: 0 0 0 3px var(--aps-primary-light);
}

/* Mark Input - Clean Number Field */
.aps-mark-input-wrapper {
    position: relative;
}

.aps-mark-input {
    width: 100%;
    padding: 0.5rem 2.25rem 0.5rem 0.75rem;
    border: 1px solid var(--aps-gray-300);
    border-radius: 6px;
    font-size: 0.875rem;
    background: white;
    color: var(--aps-gray-900);
    transition: all 0.15s;
    -moz-appearance: textfield;
}

.aps-mark-input::-webkit-outer-spin-button,
.aps-mark-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.aps-mark-input:hover {
    border-color: var(--aps-gray-400);
}

.aps-mark-input:focus {
    outline: none;
    border-color: var(--aps-primary);
    box-shadow: 0 0 0 3px var(--aps-primary-light);
}

.aps-mark-input.error {
    border-color: var(--aps-danger);
    background: #fef2f2;
}

.aps-input-suffix {
    position: absolute;
    right: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--aps-gray-500);
    font-size: 0.75rem;
    font-weight: 500;
    pointer-events: none;
}

/* Points Display - Bold and Clear */
.aps-points-display {
    text-align: center;
}

.aps-points-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--aps-primary);
    line-height: 1.2;
}

.aps-points-label {
    display: inline-block !important;
    font-size: 14px !important;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--aps-gray-500);
}

/* Remove Button - Minimal */
.aps-remove-subject {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    margin: 0 auto;
    background: transparent;
    border: 1px solid var(--aps-gray-300);
    border-radius: 6px;
    color: var(--aps-gray-500);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s;
}

.aps-remove-subject:hover {
    background: var(--aps-danger);
    border-color: var(--aps-danger);
    color: white;
}

.aps-remove-subject:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: transparent;
    border-color: var(--aps-gray-300);
    color: var(--aps-gray-500);
}

/* Add Subject Button - Clean Link Style */
.aps-add-subject-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px dashed var(--aps-gray-300);
    border-radius: 6px;
    color: var(--aps-primary);
    font-size: 0.813rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.aps-add-subject-btn:hover {
    background: var(--aps-primary-light);
    border-color: var(--aps-primary);
    color: var(--aps-primary-dark);
}

.aps-add-subject-btn svg {
    width: 14px;
    height: 14px;
}

/* Stats Grid - Clean Cards */
.aps-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    padding: 0 1.5rem 1.25rem;
}

.aps-stat-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--aps-gray-50);
    border-radius: var(--aps-radius);
    border: 1px solid var(--aps-gray-200);
    transition: transform 0.15s;
}

.aps-stat-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--aps-shadow);
}

.aps-stat-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.aps-stat-content {
    flex: 1;
    min-width: 0;
}

.aps-stat-label {
    font-size: 0.688rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--aps-gray-500);
    margin-bottom: 0.125rem;
}

.aps-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--aps-gray-900);
    line-height: 1.2;
}

.aps-stat-max {
    font-size: 0.75rem;
    color: var(--aps-gray-500);
    font-weight: 400;
    margin-left: 0.125rem;
}

.aps-level-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    background: var(--aps-primary-light);
    color: var(--aps-primary-dark);
    border-radius: 100px;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-top: 0.25rem;
}

/* Progress Bar - Clean and Smooth */
.aps-progress-section {
    padding: 0 1.5rem 1.25rem;
}

.aps-progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--aps-gray-500);
}

.aps-progress-bar {
    height: 6px;
    background: var(--aps-gray-200);
    border-radius: 100px;
    overflow: hidden;
}

.aps-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--aps-primary) 0%, #60a5fa 100%);
    border-radius: 100px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

/* Chart Section */
.aps-chart-section {
    padding: 0 1.5rem 1.25rem;
}

.aps-chart-section h3 {
    margin: 0 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--aps-gray-700);
}

#aps-performance-chart {
    max-height: 180px;
    width: 100% !important;
}

/* Guidance Section */
.aps-guidance-section {
    padding: 0 1.5rem 1.25rem;
}

.aps-guidance-section h3 {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin: 0 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    color: var(--aps-gray-700);
}

/* Faculties Grid - Compact Cards */
.aps-faculties-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.aps-faculty-card {
    padding: 0.75rem;
    background: var(--aps-gray-50);
    border-radius: 6px;
    border-left: 3px solid var(--aps-gray-300);
    transition: all 0.15s;
}

.aps-faculty-card:hover {
    background: white;
    box-shadow: var(--aps-shadow);
}

.aps-faculty-card.recommended {
    border-left-color: var(--aps-success);
    background: #f0fdf4;
}

.aps-faculty-name {
    font-weight: 600;
    font-size: 0.813rem;
    margin-bottom: 0.125rem;
    color: var(--aps-gray-900);
}

.aps-faculty-requirement {
    font-size: 0.688rem;
    color: var(--aps-gray-600);
}

/* Institutions List */
.aps-institutions-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.aps-institution-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 0.875rem;
    background: var(--aps-gray-50);
    border-radius: 6px;
    transition: all 0.15s;
}

.aps-institution-item:hover {
    background: white;
    box-shadow: var(--aps-shadow);
}

.aps-institution-item.recommended {
    background: #f0fdf4;
    border: 1px solid #86efac;
}

.aps-institution-name {
    font-weight: 600;
    font-size: 0.813rem;
    color: var(--aps-gray-900);
}

.aps-institution-examples {
    font-size: 0.688rem;
    color: var(--aps-gray-500);
    margin-top: 0.125rem;
}

.aps-institution-badge {
    padding: 0.125rem 0.5rem;
    background: var(--aps-primary);
    color: white;
    border-radius: 100px;
    font-size: 0.625rem;
    font-weight: 600;
    white-space: nowrap;
}

.aps-institution-item.recommended .aps-institution-badge {
    background: var(--aps-success);
}

/* Action Buttons */
.aps-action-buttons {
    display: flex;
    gap: 0.625rem;
    padding: 0 1.5rem 1.5rem;
}

.aps-btn-primary,
.aps-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    flex: 1;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.813rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.aps-btn-primary {
    background: var(--aps-primary);
    color: white;
}

.aps-btn-primary:hover {
    background: var(--aps-primary-dark);
    box-shadow: var(--aps-shadow);
}

.aps-btn-secondary {
    background: white;
    color: var(--aps-gray-700);
    border: 1px solid var(--aps-gray-300);
}

.aps-btn-secondary:hover {
    background: var(--aps-gray-50);
    border-color: var(--aps-gray-400);
}

.aps-btn-primary svg,
.aps-btn-secondary svg {
    width: 14px;
    height: 14px;
}

/* Error Container */
.aps-error-container {
    margin: 0 1.5rem 1rem;
    padding: 0.625rem 0.875rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
}

.aps-error-message {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--aps-danger);
    font-size: 0.813rem;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* Responsive Design */
@media (max-width: 640px) {
    .aps-advanced-wrapper {
        margin: 0.75rem;
    }
    
    .aps-advanced-header {
        padding: 1.25rem 1rem 0.875rem;
    }
    
    .aps-advanced-title {
        font-size: 1.25rem;
    }
    
    .aps-header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .aps-subjects-container {
        padding: 1rem;
    }
    
    .aps-subjects-header {
        display: none;
    }
    
    .aps-subject-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 0.875rem;
    }
    
    .aps-points-display {
        text-align: left;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    .aps-points-value {
        font-size: 1.125rem;
    }
    
    .aps-remove-subject {
        width: 100%;
        margin-top: 0.25rem;
    }
    
    .aps-stats-grid {
        grid-template-columns: 1fr;
        padding: 0 1rem 1rem;
    }
    
    .aps-faculties-grid {
        grid-template-columns: 1fr;
    }
    
    .aps-action-buttons {
        flex-direction: column;
        padding: 0 1rem 1rem;
    }
    
    .aps-chart-section,
    .aps-guidance-section,
    .aps-progress-section {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Loading State */
.aps-calculating {
    position: relative;
    pointer-events: none;
}

.aps-calculating::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid var(--aps-gray-200);
    border-top-color: var(--aps-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Dark Theme Support */
[data-theme="dark"] .aps-advanced-container {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] {
    color: #e2e8f0;
}

[data-theme="dark"] .aps-subject-row {
    background: #0f172a;
    border-color: #334155;
}

[data-theme="dark"] .aps-subject-row:hover {
    background: #1e293b;
    border-color: #475569;
}

[data-theme="dark"] .aps-subject-select,
[data-theme="dark"] .aps-mark-input {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

[data-theme="dark"] .aps-stat-card,
[data-theme="dark"] .aps-faculty-card,
[data-theme="dark"] .aps-institution-item {
    background: #0f172a;
    border-color: #334155;
}

[data-theme="dark"] .aps-stat-value,
[data-theme="dark"] .aps-faculty-name,
[data-theme="dark"] .aps-institution-name {
    color: #f1f5f9;
}

[data-theme="dark"] .aps-btn-secondary {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
}

[data-theme="dark"] .aps-btn-secondary:hover {
    background: #1e293b;
    border-color: #475569;
}

[data-theme="dark"] .aps-faculty-card.recommended,
[data-theme="dark"] .aps-institution-item.recommended {
    background: #064e3b;
    border-color: #059669;
}

/* Print Styles */
@media print {
    .aps-advanced-wrapper {
        max-width: 100%;
        margin: 0;
    }
    
    .aps-add-subject-btn,
    .aps-remove-subject,
    .aps-action-buttons {
        display: none !important;
    }
    
    .aps-advanced-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* Custom Scrollbar */
.aps-subjects-list::-webkit-scrollbar {
    width: 6px;
}

.aps-subjects-list::-webkit-scrollbar-track {
    background: var(--aps-gray-100);
    border-radius: 3px;
}

.aps-subjects-list::-webkit-scrollbar-thumb {
    background: var(--aps-gray-400);
    border-radius: 3px;
}

.aps-subjects-list::-webkit-scrollbar-thumb:hover {
    background: var(--aps-gray-500);
}

/* Smooth Transitions */
.aps-subject-row,
.aps-stat-card,
.aps-faculty-card,
.aps-institution-item,
.aps-btn-primary,
.aps-btn-secondary {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Focus Visible for Accessibility */
.aps-subject-select:focus-visible,
.aps-mark-input:focus-visible,
.aps-btn-primary:focus-visible,
.aps-btn-secondary:focus-visible,
.aps-add-subject-btn:focus-visible,
.aps-remove-subject:focus-visible {
    outline: 2px solid var(--aps-primary);
    outline-offset: 2px;
}