/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    padding: 16px;
}

.container {
    max-width: 1100px;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 20px;
    text-align: center;
}

header h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 6px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

/* Main content */
main {
    padding: 16px;
    flex: 1;
    overflow: hidden;
}

/* Full-height two-column layout */
.app-grid {
    height: 100%;
    display: grid;
    grid-template-columns: 0.95fr 1.05fr;
    gap: 16px;
    align-items: stretch;
}

.panel {
    border: 1px solid #eee;
    border-radius: 10px;
    padding: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.panel-form {
    min-height: 0;
}

.panel-form form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.form-scroll {
    overflow: auto;
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

.form-footer {
    position: sticky;
    bottom: 0;
    background: white;
    padding-top: 12px;
    margin-top: 12px;
    border-top: 1px solid #f0f0f0;
}

/* Form styles */
.form-group {
    margin-bottom: 12px;
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #444;
    font-size: 14px;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.help-text {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #777;
}

/* Checkbox */
.checkbox-group {
    margin-bottom: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 8px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-label span {
    font-weight: 500;
}

/* Experimental badge */
.experimental-badge {
    display: inline-block;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

/* Warning text */
.warning-text {
    color: #856404;
    font-style: italic;
}

/* Advanced options section */
.advanced-section {
    margin-bottom: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.toggle-button {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f8f9fa;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #444;
    transition: background 0.2s;
}

.toggle-button:hover {
    background: #e9ecef;
}

.toggle-button .chevron {
    transition: transform 0.2s;
}

.toggle-button.active .chevron {
    transform: rotate(180deg);
}

.advanced-content {
    padding: 12px;
    background: #fafafa;
    border-top: 1px solid #e0e0e0;
    display: none;
}

.advanced-content.visible {
    display: block;
}

.kv-cache-fields {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.kv-cache-fields .form-group:last-child {
    grid-column: 1 / -1;
}

/* Submit button */
.submit-button {
    width: 100%;
    padding: 11px 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    transition: opacity 0.2s, transform 0.1s;
}

.submit-button:hover:not(:disabled) {
    opacity: 0.9;
}

.submit-button:active:not(:disabled) {
    transform: scale(0.98);
}

.submit-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Spinner */
.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner.visible {
    display: block;
}

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

#button-text.hidden {
    display: none;
}

/* Error message */
.error-message {
    display: none;
    margin-top: 12px;
    padding: 12px 16px;
    background: #fee;
    border: 1px solid #fcc;
    border-radius: 6px;
    color: #c33;
    font-size: 14px;
}

.error-message.visible {
    display: block;
}

/* Results empty state */
.results-empty {
    flex: 1;
    border: 1px dashed #ddd;
    border-radius: 10px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 18px;
    text-align: center;
    color: #555;
}

.results-empty-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
}

.results-empty-body {
    font-size: 13px;
    color: #666;
    max-width: 52ch;
}

/* Results section */
.results-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.results-section h2 {
    font-size: 16px;
    margin-bottom: 4px;
    color: #333;
}

.total-memory {
    text-align: center;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    margin-bottom: 0;
}

.total-label {
    display: block;
    color: white;
    font-size: 14px;
    margin-bottom: 8px;
    opacity: 0.9;
}

.total-value {
    display: block;
    color: white;
    font-size: 28px;
    font-weight: 700;
}

/* Progress bars */
.progress-bars {
    margin-bottom: 0;
}

.progress-bar {
    margin-bottom: 10px;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 13px;
}

.progress-label-name {
    font-weight: 500;
    color: #444;
    display: flex;
    align-items: center;
    gap: 0;
}

/* Legend circles in progress bar label */
.legend-circle {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.legend-circle.model-weights {
    background: linear-gradient(90deg, #667eea, #764ba2);
}

.legend-circle.kv-cache {
    background: linear-gradient(90deg, #f093fb, #f5576c);
}

.legend-label {
    margin-right: 12px;
}

.progress-label-value {
    color: #666;
}

.progress-track {
    height: 18px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    color: white;
    font-size: 11px;
    font-weight: 500;
    transition: width 0.3s ease;
}

/* Color scheme for progress bars */
.progress-fill.model-weights { background: linear-gradient(90deg, #667eea, #764ba2); }
.progress-fill.kv-cache { background: linear-gradient(90deg, #f093fb, #f5576c); }
.progress-fill.activation { background: linear-gradient(90deg, #4facfe, #00f2fe); }
.progress-fill.temp-buffer { background: linear-gradient(90deg, #43e97b, #38f9d7); }
.progress-fill.other { background: linear-gradient(90deg, #fa709a, #fee140); }

/* Color scheme for stacked progress segments */
.progress-segment.model-weights { background: linear-gradient(90deg, #667eea, #764ba2); }
.progress-segment.kv-cache { background: linear-gradient(90deg, #f093fb, #f5576c); }

/* Stacked progress track */
.progress-track-stacked {
    position: relative;
}

/* Individual segment within stacked bar */
.progress-segment {
    position: absolute;
    height: 100%;
    border-radius: 8px;
    transition: width 0.3s ease, left 0.3s ease;
}

/* Ensure first segment has left border radius */
.progress-segment:first-child {
    border-radius: 8px 0 0 8px;
}

/* Ensure last segment has right border radius */
.progress-segment:last-child {
    border-radius: 0 8px 8px 0;
}

/* If only one segment, full radius */
.progress-segment:first-child:last-child {
    border-radius: 8px;
}

/* Breakdown table */
.breakdown-section {
    margin-bottom: 0;
}

.breakdown-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: #444;
}

.breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.breakdown-table th,
.breakdown-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.breakdown-table th {
    font-weight: 600;
    color: #444;
    background: #f8f9fa;
}

.breakdown-table td {
    color: #666;
}

.breakdown-table tr:last-child th,
.breakdown-table tr:last-child td {
    border-bottom: none;
}

.breakdown-table .component-name {
    font-weight: 500;
    color: #333;
}

.breakdown-table .component-header {
    font-weight: 600;
    color: #667eea;
    background: #f8f9fa;
    padding-top: 10px;
    padding-bottom: 8px;
    font-size: 13px;
}

.breakdown-table .dtype-name {
    color: #444;
    font-weight: 500;
    font-size: 13px;
    padding-top: 8px;
    padding-bottom: 4px;
}

.breakdown-table .params-label {
    color: #666;
    font-size: 12px;
    padding-top: 4px;
    padding-bottom: 8px;
    padding-left: 10px;
}

.breakdown-table .dtype-divider {
    height: 1px;
    padding: 0;
    background: #e0e0e0;
}

.mini-progress {
    position: relative;
    height: 20px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
}

.mini-progress-fill {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    transition: width 0.3s ease;
}

.mini-progress-text {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 11px;
    font-weight: 500;
    color: #333;
    z-index: 1;
}

.breakdown-table .component-value {
    text-align: right;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* Footer */
footer {
    padding: 12px 16px;
    text-align: center;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

footer p {
    font-size: 13px;
    color: #666;
}

footer a {
    color: #667eea;
    text-decoration: none;
}

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

/* Responsive design */
@media (max-width: 900px) {
    body {
        padding: 10px;
        height: auto;
        overflow: auto;
    }

    header {
        padding: 20px;
    }

    header h1 {
        font-size: 22px;
    }

    main {
        padding: 20px;
        overflow: visible;
    }

    .container {
        height: auto;
    }

    .app-grid {
        height: auto;
        grid-template-columns: 1fr;
    }

    .total-value {
        font-size: 28px;
    }

    .breakdown-table {
        font-size: 13px;
    }

    .breakdown-table th,
    .breakdown-table td {
        padding: 8px 10px;
    }
}

@media (max-height: 720px) {
    body {
        height: auto;
        overflow: auto;
    }

    .container {
        height: auto;
    }

    main {
        overflow: visible;
    }

    .app-grid {
        height: auto;
    }
}
