/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --secondary-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f9fafb;
    --card-bg: #ffffff;
    --text-color: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 10px;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
    color: white;
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
    flex-shrink: 0;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.header-content {
    flex: 1;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 0;
}

.btn-lang {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-lang:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}

.lang-icon {
    font-size: 1.1rem;
}

.api-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ef4444;
    animation: pulse 2s ease-in-out infinite;
}

.api-status.connected .status-indicator {
    background-color: #10b981;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Main */
main {
    display: grid;
    grid-template-columns: 0.75fr 1.25fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

@media (max-width: 968px) {
    main {
        grid-template-columns: 1fr;
    }
}

/* Sections */
section {
    background: var(--card-bg);
    padding: 15px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

section h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.5rem;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

section h3 {
    color: var(--text-color);
    margin-bottom: 15px;
    margin-top: 20px;
    font-size: 1.1rem;
    font-weight: 600;
}

section h3:first-of-type {
    margin-top: 0;
}

.form-section {
    overflow-y: auto;
}

.chart-section {
    overflow: hidden;
}

/* Form Groups */
.form-group {
    margin-bottom: 20px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.input-field {
    display: flex;
    flex-direction: column;
    margin-bottom: 15px;
}

.input-field label {
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.input-field input,
.input-field select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: all 0.2s;
}

.input-field input:focus,
.input-field select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.input-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

@media (max-width: 768px) {
    .input-row,
    .input-row-3 {
        grid-template-columns: 1fr;
    }
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.checkbox-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-field label {
    cursor: pointer;
    user-select: none;
    font-size: 0.95rem;
}

.hint-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

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

.btn-primary:hover:not(:disabled) {
    background: #4338ca;
}

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

.btn-secondary:hover:not(:disabled) {
    background: #059669;
}

.btn-outline {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 20px;
    flex: 0 0 auto;  /* Don't grow, don't shrink - stay visible */
}

@media (max-width: 768px) {
    .button-group {
        grid-template-columns: 1fr;
    }
}

/* Chart Preview */
.chart-section {
    flex: 1;  /* Fill available vertical space */
    display: flex;
    flex-direction: column;
}

.chart-preview {
    flex: 1 1 auto;  /* Grow to fill space but allow shrinking for buttons */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border-radius: 8px;
    padding: 5px;  /* Minimal padding to maximize chart space */
    border: 2px dashed var(--border-color);
    margin-bottom: 10px;
    min-height: 0;  /* Allow flex to control height */
    overflow: hidden;  /* Prevent overflow */
}

.chart-preview.has-chart {
    border-style: solid;
    border-color: var(--success-color);
}

.chart-preview svg {
    max-width: 100%;
    height: auto;
}

.loading-state {
    text-align: center;
    color: var(--text-secondary);
}

.loading-state .spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

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

.no-chart {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Status Messages */
.status-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-message.info {
    background: #eff6ff;
    color: #1e40af;
    border-left: 4px solid #3b82f6;
}

.status-message.success {
    background: #f0fdf4;
    color: #166534;
    border-left: 4px solid #10b981;
}

.status-message.error {
    background: #fef2f2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
}

.status-message.warning {
    background: #fffbeb;
    color: #92400e;
    border-left: 4px solid #f59e0b;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    margin-top: 30px;
    color: var(--text-secondary);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

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

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .header-top {
        flex-direction: column;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #7c3aed;
}
