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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #475569;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
    flex-wrap: wrap;
}

.tab {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--primary-light);
    border-bottom-color: var(--primary);
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.card > p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

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

.btn.primary:disabled {
    background: var(--secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn.secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.secondary:hover {
    background: var(--border);
}

.btn.icon {
    padding: 0.5rem;
    font-size: 1.2rem;
    line-height: 1;
    background: transparent;
    color: var(--text-muted);
}

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

.btn.small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

.btn.large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    transition: all 0.3s;
    margin-bottom: 1.5rem;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.upload-zone p {
    margin-bottom: 0.5rem;
}

.upload-zone .small {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Example Schemas */
.example-schemas {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.example-schemas h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.example-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Schema Preview */
.schema-preview {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.schema-preview h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.schema-preview pre {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    color: var(--primary-light);
}

.hidden {
    display: none !important;
}

/* Entity Cards */
.entities-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.entity-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.entity-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.entity-name {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    font-weight: 600;
}

.fields-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* Field Rows */
.field-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem;
    background: var(--bg-input);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.field-name {
    width: 150px;
    padding: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}

.field-type {
    width: 160px;
    padding: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
}

.field-options {
    flex: 1;
    min-width: 150px;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.field-options input,
.field-options select {
    padding: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
}

.field-options input[type="text"] {
    flex: 1;
    min-width: 100px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
}

/* Settings */
.settings-group {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.settings-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-group h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.help-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.radio-group {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

input[type="number"],
input[type="text"],
select {
    padding: 0.625rem 0.875rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    width: 100%;
    max-width: 300px;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Error Settings */
.error-settings {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.setting-row label {
    width: 180px;
    font-size: 0.9rem;
}

.setting-row input[type="range"] {
    flex: 1;
    max-width: 300px;
}

.range-value {
    width: 50px;
    text-align: right;
    font-weight: 600;
    color: var(--primary-light);
}

/* Relationships */
.relationship-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.relationship-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.relationship-row select {
    flex: 1;
    min-width: 120px;
}

.rel-type {
    background: var(--primary) !important;
    font-weight: 500;
}

.relationship-visual {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    min-height: 150px;
}

#diagramCanvas {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 1rem;
}

.diagram-entity {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 1rem;
    min-width: 150px;
    text-align: center;
}

.diagram-entity h4 {
    color: var(--primary-light);
    margin-bottom: 0.5rem;
}

.diagram-entity ul {
    list-style: none;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Generation */
.generation-summary {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.generation-summary h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

#summaryContent {
    font-size: 0.9rem;
}

#summaryContent .entity-summary {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

#summaryContent .entity-summary:last-child {
    border-bottom: none;
}

.empty-state {
    color: var(--text-muted);
    font-style: italic;
}

.generate-actions {
    text-align: center;
    margin-bottom: 1.5rem;
}

/* Progress */
.progress-container {
    margin-bottom: 1.5rem;
}

.progress-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 4px;
    transition: width 0.3s;
    width: 0%;
}

#progressText {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.progress-container {
    text-align: center;
}

.progress-percent {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-light);
    margin: 0.5rem 0;
}

.cancel-btn {
    margin-top: 1rem;
}

/* Output Section */
.output-section {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.output-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.output-preview {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    max-height: 400px;
    overflow: auto;
}

.output-preview pre {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-all;
}

.output-stats {
    margin-top: 1rem;
    display: flex;
    gap: 2rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.output-stats span {
    color: var(--success);
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .tabs {
        gap: 0.25rem;
    }

    .tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .field-row {
        flex-direction: column;
        align-items: stretch;
    }

    .field-name,
    .field-type {
        width: 100%;
    }

    .setting-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .setting-row input[type="range"] {
        width: 100%;
        max-width: none;
    }

    .relationship-row {
        flex-direction: column;
    }

    .relationship-row select {
        width: 100%;
    }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 1000;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.info {
    border-left: 4px solid var(--primary);
}

/* Validation Errors */
.validation-error {
    border-color: var(--danger) !important;
    background: rgba(239, 68, 68, 0.1) !important;
}

.error-message {
    display: block;
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 0.25rem;
    position: absolute;
    left: 0;
    bottom: -18px;
}

.entity-header,
.field-row {
    position: relative;
}

.entity-header {
    padding-bottom: 1rem;
}

/* Validation Errors in Summary */
.validation-errors {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 1rem;
}

.validation-errors p {
    color: var(--danger);
    margin-bottom: 0.5rem;
}

.validation-errors ul {
    margin-left: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.validation-errors li {
    margin-bottom: 0.25rem;
}

/* Tooltips */
.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: var(--border);
    border-radius: 50%;
    font-size: 10px;
    font-weight: bold;
    color: var(--text-muted);
    cursor: help;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.tooltip-icon:hover {
    background: var(--primary);
    color: white;
}

.tooltip-icon:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Relationship Warning */
.relationship-warning {
    display: none;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--warning);
}

.warning-icon {
    margin-right: 0.5rem;
}

/* Improved Diagram Styles */
#diagramCanvas {
    position: relative;
    min-height: 200px;
    display: block;
    overflow: auto;
}

.diagram-entity {
    position: absolute;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 0.75rem;
    min-width: 150px;
    text-align: left;
}

.diagram-entity h4 {
    color: var(--primary-light);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.diagram-entity h4.unnamed {
    color: var(--warning);
    font-style: italic;
}

.diagram-entity ul {
    list-style: none;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.diagram-entity li {
    padding: 0.15rem 0;
}

.diagram-entity .field-name {
    width: auto;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: inherit;
}

.diagram-entity .field-type {
    width: auto;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: inherit;
}

.diagram-entity .more {
    color: var(--text-muted);
    font-style: italic;
}

.relationship-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Clear Button Styles */
.btn.danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

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

/* Accessibility Improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles for keyboard navigation */
.btn:focus,
input:focus,
select:focus,
.tab:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Improved contrast for text */
.text-muted {
    color: #b0b8c4;
}

/* Summary warning text */
#summaryContent .warning {
    color: var(--warning);
}

/* Entity name field in parent container needs relative positioning */
.entity-header {
    position: relative;
    margin-bottom: 1.5rem;
}

/* Field row needs space for error message */
.field-row {
    margin-bottom: 0.75rem;
    position: relative;
    padding-bottom: 0.5rem;
}

/* Header actions (for clear button) */
.header-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Schema Actions */
.schema-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Header Logo */
.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.header-logo {
    width: 56px;
    height: 56px;
    filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
    transition: transform 0.3s ease;
}

.header-logo:hover {
    transform: scale(1.05);
}

/* Footer */
.site-footer {
    margin-top: 4rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 3rem 2rem 1.5rem;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
}

.footer-logo {
    width: 40px;
    height: 40px;
}

.footer-brand p {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
}

.footer-links {
    display: flex;
    gap: 4rem;
    flex-wrap: wrap;
}

.footer-section h4 {
    color: var(--primary-light);
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footer-section ul {
    list-style: none;
}

.footer-section li {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.footer-section a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-section a:hover {
    color: var(--primary-light);
}

.footer-bottom {
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-bottom p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.footer-bottom a {
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.footer-bottom a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.footer-copyright {
    color: var(--text-muted);
    opacity: 0.7;
}

/* Footer Responsive */
@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .footer-brand {
        align-items: center;
    }

    .footer-links {
        justify-content: center;
        gap: 2rem;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
    }
}
