:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --warning: #f59e0b;
    --success: #16a34a;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #cbd5e1;
    --entity-fill: #dbeafe;
    --entity-stroke: #2563eb;
    --entity-header: #2563eb;
    --assoc-fill: #fef3c7;
    --assoc-stroke: #d97706;
    --assoc-header: #d97706;
    --link-color: #475569;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --radius: 6px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Toolbar */
#toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 100;
    flex-wrap: wrap;
}

.toolbar-brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-right: 16px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 8px;
}

.btn-help {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
    justify-content: center;
    color: var(--primary);
    border-color: var(--primary);
}

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

.toolbar-spacer {
    flex: 1;
}

/* Toolbar dropdown */
.toolbar-dropdown {
    position: relative;
}

.toolbar-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 150;
    min-width: 160px;
    padding: 4px 0;
}

.toolbar-dropdown-menu.open {
    display: block;
}

.toolbar-dropdown-menu button {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    border-radius: 0;
    padding: 7px 14px;
    font-size: 13px;
}

.toolbar-dropdown-menu button:hover {
    background: var(--bg);
}

/* Language selector */
.lang-selector {
    display: flex;
    align-items: center;
    gap: 4px;
}

.lang-select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
}

/* Auth zone */
.auth-zone {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.auth-guest, .auth-user {
    display: flex;
    align-items: center;
    gap: 6px;
}

.auth-username {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    padding: 4px 10px;
    background: var(--entity-fill);
    border-radius: var(--radius);
}

button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
}

button:hover:not(:disabled) {
    background: var(--bg);
    border-color: var(--primary);
    color: var(--primary);
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

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

button.btn-secondary {
    background: var(--bg);
}

button.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
}

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

button.btn-small {
    padding: 3px 8px;
    font-size: 12px;
}

/* Workspace */
#workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#mcd-canvas {
    width: 100%;
    height: 100%;
    cursor: default;
}

#mcd-canvas .entity-group { cursor: move; }
#mcd-canvas .assoc-group { cursor: move; }

#mcd-canvas .entity-rect {
    fill: var(--entity-fill);
    stroke: var(--entity-stroke);
    stroke-width: 2;
    rx: 4;
}

#mcd-canvas .entity-header-rect {
    fill: var(--entity-header);
    rx: 4;
}

#mcd-canvas .entity-header-cover {
    fill: var(--entity-header);
}

#mcd-canvas .entity-name {
    fill: white;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    pointer-events: none;
}

#mcd-canvas .entity-prop {
    fill: var(--text);
    font-size: 12px;
    font-family: var(--font);
    pointer-events: none;
}

#mcd-canvas .entity-prop-type {
    fill: var(--text-muted);
    font-size: 11px;
    font-family: var(--font);
    font-style: italic;
    pointer-events: none;
}

#mcd-canvas .entity-prop-id {
    text-decoration: underline;
    font-weight: 600;
}

#mcd-canvas .assoc-ellipse {
    fill: var(--assoc-fill);
    stroke: var(--assoc-stroke);
    stroke-width: 2;
}

#mcd-canvas .assoc-name {
    fill: var(--text);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font);
    pointer-events: none;
}

#mcd-canvas .assoc-prop {
    fill: var(--text);
    font-size: 11px;
    font-family: var(--font);
    pointer-events: none;
}

#mcd-canvas .link-line {
    stroke: var(--link-color);
    stroke-width: 1.5;
    fill: none;
}

#mcd-canvas .cardinality-text {
    fill: var(--text);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font);
}

#mcd-canvas .link-highlight {
    stroke: var(--primary);
    stroke-width: 3;
}

#mcd-canvas .selected .entity-rect {
    stroke: var(--primary);
    stroke-width: 3;
    stroke-dasharray: 5 3;
}

#mcd-canvas .selected .assoc-ellipse {
    stroke: var(--primary);
    stroke-width: 3;
    stroke-dasharray: 5 3;
}

/* MLD */
.mld-table {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    margin-bottom: 6px;
    line-height: 1.8;
}

.mld-table-name {
    font-weight: 700;
}

.mld-table-entity .mld-table-name {
    color: var(--entity-stroke);
}

.mld-table-assoc .mld-table-name {
    color: var(--assoc-stroke);
}

.mld-pk {
    text-decoration: underline;
    font-weight: 600;
}

.mld-fk {
    color: var(--danger);
}

.mld-type {
    color: var(--text-muted);
    font-size: 11px;
}

.mld-notnull {
    font-size: 9px;
    font-weight: 700;
    color: var(--danger);
    vertical-align: super;
}

.mld-fk-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 12px;
}

.mld-fk-line {
    color: var(--text-muted);
    margin: 3px 0 3px 12px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
}

.mld-modal {
    width: 620px;
    max-width: 92vw;
}

.mld-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 14px;
}

.mld-tab {
    padding: 6px 16px;
    border: none;
    background: none;
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    color: var(--text-muted);
}

.mld-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.mld-content {
    max-height: 400px;
    overflow-y: auto;
    padding: 4px;
}

.mld-content pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.mld-warnings {
    margin-top: 12px;
    padding: 8px 12px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    font-size: 12px;
}

.mld-warnings strong {
    color: #92400e;
}

.mld-warnings ul {
    margin: 4px 0 0 16px;
    color: #92400e;
}

.mld-copy-btn {
    margin-top: 10px;
}

/* Panel */
.panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 340px;
    height: 100%;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -2px 0 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.2s ease;
}

.panel.hidden {
    transform: translateX(100%);
    pointer-events: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.panel-header h3 {
    font-size: 15px;
    font-weight: 600;
}

#panel-close {
    border: none;
    background: none;
    font-size: 20px;
    padding: 2px 6px;
    color: var(--text-muted);
}

#panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.panel-section {
    margin-bottom: 20px;
}

.panel-section h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.form-row .form-group { flex: 1; }

.prop-list {
    list-style: none;
}

.prop-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 13px;
    background: var(--bg);
}

.prop-item .prop-name {
    flex: 1;
}

.prop-item .prop-id-badge {
    font-size: 10px;
    font-weight: 700;
    color: var(--primary);
    background: var(--entity-fill);
    padding: 1px 5px;
    border-radius: 3px;
}

.prop-item .prop-type {
    font-size: 11px;
    color: var(--text-muted);
}

.prop-option-badge {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 4px;
    border-radius: 3px;
    white-space: nowrap;
}

.badge-null {
    color: #059669;
    background: #d1fae5;
}

.badge-not-null {
    color: #dc2626;
    background: #fee2e2;
}

.prop-item-clickable {
    cursor: pointer;
    transition: background 0.15s;
}

.prop-item-clickable:hover {
    background: rgba(37, 99, 235, 0.08);
}

.prop-item-active {
    background: rgba(37, 99, 235, 0.15);
    border-left: 3px solid var(--primary);
}

.prop-item button {
    border: none;
    background: none;
    color: var(--text-muted);
    padding: 2px 4px;
    font-size: 14px;
}

.prop-item button:hover {
    color: var(--danger);
}

.link-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 13px;
    background: var(--bg);
}

.link-item .link-info {
    flex: 1;
}

.link-item .link-entity {
    font-weight: 600;
}

.link-item .link-card {
    font-size: 12px;
    color: var(--text-muted);
}

.cardinality-select {
    display: flex;
    gap: 4px;
    align-items: center;
}

.cardinality-select select {
    width: 60px;
    padding: 3px 6px;
    font-size: 12px;
}

.card-input {
    width: 36px;
    padding: 3px 4px;
    font-size: 12px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

.card-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Toast */
#toast-container {
    position: fixed;
    top: 60px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius);
    color: white;
    font-size: 13px;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: toast-in 0.3s ease;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.toast-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.toast.toast-error { background: var(--danger); }
.toast.toast-warning { background: var(--warning); color: var(--text); }
.toast.toast-success { background: var(--success); }
.toast.toast-info { background: var(--primary); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    width: 420px;
    max-width: 90vw;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 16px; }

#modal-close {
    border: none;
    background: none;
    font-size: 20px;
    color: var(--text-muted);
    padding: 2px 6px;
}

#modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* Connection mode indicator */
.connection-mode #mcd-canvas {
    cursor: crosshair;
}

.connection-mode .entity-group {
    cursor: crosshair !important;
}

.mode-indicator {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--warning);
    color: var(--text);
    padding: 6px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    z-index: 60;
    box-shadow: var(--shadow);
}

/* Empty state */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
}

.empty-state h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    font-size: 14px;
}

/* Length hint */
.length-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin: 2px 0 6px;
    font-style: italic;
}

/* Checkbox */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.checkbox-group input[type="checkbox"] {
    width: auto;
}

/* MPD overlay */
.mpd-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    display: flex;
    flex-direction: column;
}

.mpd-overlay.hidden { display: none; }

.mpd-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.mpd-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
}

.mpd-canvas-wrapper {
    flex: 1;
    overflow: auto;
    position: relative;
}

#mpd-canvas {
    min-width: 100%;
    min-height: 100%;
}

/* MPD table boxes */
#mpd-canvas .mpd-table-header {
    fill: var(--primary);
}

#mpd-canvas .mpd-table-header-assoc {
    fill: var(--assoc-stroke);
}

#mpd-canvas .mpd-table-body {
    fill: var(--surface);
    stroke: var(--border);
    stroke-width: 1;
}

#mpd-canvas .mpd-table-name {
    fill: white;
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
}

#mpd-canvas .mpd-col-name {
    fill: var(--text);
    font-size: 11px;
    font-family: 'Consolas', 'Courier New', monospace;
}

#mpd-canvas .mpd-col-name-pk {
    fill: var(--text);
    font-size: 11px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-weight: 700;
    text-decoration: underline;
}

#mpd-canvas .mpd-col-name-fk {
    fill: var(--danger);
    font-size: 11px;
    font-family: 'Consolas', 'Courier New', monospace;
}

#mpd-canvas .mpd-col-type {
    fill: var(--text-muted);
    font-size: 10px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-style: italic;
}

#mpd-canvas .mpd-col-badge {
    font-size: 8px;
    font-weight: 700;
    font-family: var(--font);
}

#mpd-canvas .mpd-fk-line {
    stroke: var(--danger);
    stroke-width: 1.5;
    fill: none;
}

#mpd-canvas .mpd-fk-dot {
    fill: var(--danger);
}

/* Scrollbar */
#panel-body::-webkit-scrollbar { width: 6px; }
#panel-body::-webkit-scrollbar-track { background: transparent; }
#panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* === RESPONSIVE === */

/* Tablette (<= 1024px) */
@media (max-width: 1024px) {
    #toolbar {
        gap: 8px;
        padding: 6px 10px;
    }

    .toolbar-brand {
        font-size: 15px;
        margin-right: 8px;
    }

    .toolbar-separator {
        height: 20px;
        margin: 0 4px;
    }

    button {
        padding: 5px 10px;
        font-size: 12px;
    }

    .panel {
        width: 300px;
    }

    .modal {
        width: 380px;
    }

    .mld-modal {
        width: 520px;
    }
}

/* Mobile (<= 768px) */
@media (max-width: 768px) {
    #toolbar {
        gap: 6px;
        padding: 6px 8px;
    }

    .toolbar-brand {
        font-size: 14px;
        margin-right: 4px;
        width: 100%;
    }

    .toolbar-actions {
        gap: 4px;
        width: 100%;
    }

    .toolbar-spacer {
        display: none;
    }

    .toolbar-separator {
        display: none;
    }

    .auth-zone {
        width: 100%;
        justify-content: flex-end;
    }

    button {
        padding: 5px 8px;
        font-size: 11px;
        gap: 3px;
    }

    /* Cacher les labels des boutons, garder les icones */
    #btn-add-entity svg,
    #btn-add-association svg {
        margin: 0;
    }

    /* Panel plein ecran sur mobile */
    .panel {
        width: 100%;
        border-left: none;
    }

    /* Modal plein ecran sur mobile */
    .modal, .mld-modal {
        width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
    }

    .mld-content {
        max-height: 50vh;
    }

    /* Toast plus petit */
    #toast-container {
        right: 8px;
        left: 8px;
    }

    .toast {
        max-width: 100%;
        font-size: 12px;
    }

    /* Empty state */
    .empty-state h2 {
        font-size: 16px;
    }

    .empty-state p {
        font-size: 12px;
    }

    /* Mode indicator */
    .mode-indicator {
        font-size: 11px;
        padding: 4px 10px;
    }
}

/* Petit mobile (<= 480px) */
@media (max-width: 480px) {
    .toolbar-brand {
        font-size: 13px;
    }

    button {
        padding: 4px 6px;
        font-size: 10px;
    }

    .panel-header h3 {
        font-size: 13px;
    }

    #panel-body {
        padding: 10px;
    }

    .form-group label {
        font-size: 11px;
    }

    .form-group input,
    .form-group select {
        font-size: 12px;
        padding: 5px 8px;
    }

    .prop-item {
        font-size: 12px;
        padding: 4px 6px;
    }

    .modal-header {
        padding: 10px 14px;
    }

    #modal-body {
        padding: 14px;
    }

    .modal-footer {
        padding: 8px 14px;
    }

    .auth-username {
        font-size: 11px;
        padding: 3px 6px;
    }
}
