:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --border: rgba(0, 0, 0, 0.06);
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --green: #34c759;
    --yellow: #ff9f0a;
    --red: #ff3b30;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 4px 24px rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --transition: 0.2s ease;
}

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

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

.app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* Content Layout */
.content-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

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

/* Header */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.header p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Controls Bar */
.controls-bar {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-bottom: 32px;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.segmented-control {
    display: flex;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 3px;
    box-shadow: var(--shadow-sm);
}

.segment {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition);
}

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

.segment.selected {
    background: var(--accent);
    color: white;
    box-shadow: 0 1px 4px rgba(0, 113, 227, 0.3);
}

.speed-control .segment {
    padding: 8px 12px;
    font-size: 12px;
}

/* Main Area */
.main-area {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

/* CRUD Buttons */
.crud-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.crud-btn {
    width: 40px;
    height: 40px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.crud-btn:hover {
    background: #e8e8ed;
    transform: translateY(-1px);
}

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

/* Canvas */
.canvas {
    position: relative;
    height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 20px;
}

.binary {
    width: 120px;
    height: 64px;
    background: linear-gradient(135deg, #f0f0f5 0%, #e8e8ed 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
}

.binary.processing {
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.2);
}

.version-label {
    font-size: 32px;
    font-weight: 600;
    color: var(--text);
}

/* Action Ball */
.action-ball {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.action-ball:hover {
    transform: scale(1.15);
}

.action-ball.blue { background: #007aff; }
.action-ball.green { background: var(--green); }
.action-ball.yellow { background: var(--yellow); }
.action-ball.red { background: var(--red); }

/* Databases */
.databases {
    display: flex;
    justify-content: center;
    gap: 48px;
}

.db-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 24px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.db-card:hover {
    background: #e8e8ed;
}

.db-card.dimmed {
    opacity: 0.4;
}

.db-icon {
    width: 36px;
    height: 36px;
    color: var(--text-secondary);
}

.db-icon svg {
    width: 100%;
    height: 100%;
}

.db-name {
    font-size: 13px;
    font-weight: 500;
}

.db-badge {
    font-size: 10px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg);
    color: var(--text-secondary);
}

.db-badge.active {
    background: rgba(52, 199, 89, 0.15);
    color: var(--green);
}

/* Version Controls */
.version-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

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

.btn.primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

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

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Schema Section */
.schema-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.schema-card {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    width: 200px;
}

.schema-header {
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.schema-header.old {
    background: #fff3e0;
    color: #e65100;
}

.schema-header.new {
    background: #e8f5e9;
    color: #2e7d32;
}

.schema-body {
    padding: 12px 16px;
}

.schema-row {
    font-size: 11px;
    font-family: 'SF Mono', Menlo, monospace;
    color: var(--text-secondary);
    padding: 3px 0;
}

.schema-row.highlight {
    color: var(--text);
    font-weight: 500;
}

.schema-footer {
    padding: 8px 16px;
    font-size: 10px;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.schema-arrow {
    font-size: 20px;
    color: var(--text-secondary);
}

/* Legend */
.legend {
    display: flex;
    justify-content: center;
    gap: 24px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.blue { background: #007aff; }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }

/* Version Info (Right Sidebar) */
.version-info-section {
    width: 320px;
    flex-shrink: 0;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.version-info-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.version-info-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.version-info-body {
    padding: 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.info-row:first-child {
    padding-top: 0;
}

.info-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.info-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.info-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

/* Action History */
.history-section {
    width: 320px;
    flex-shrink: 0;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

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

.history-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.clear-btn {
    font-size: 12px;
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
}

.clear-btn:hover {
    background: var(--border);
    color: var(--text);
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
}

.history-empty {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 13px;
}

.history-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    overflow: hidden;
}

.history-item:last-child {
    margin-bottom: 0;
}

.history-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg);
    cursor: pointer;
    transition: var(--transition);
}

.history-item-header:hover {
    background: #e8e8ed;
}

.history-action-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--accent);
    color: white;
}

.history-action-badge.error {
    background: var(--red);
}

.history-item-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.history-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.history-item-expand {
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform var(--transition);
}

.history-item.expanded .history-item-expand {
    transform: rotate(180deg);
}

.history-subactions {
    display: none;
    padding: 0 12px 12px 12px;
}

.history-item.expanded .history-subactions {
    display: block;
}

.subaction {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 0;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
}

.subaction:last-child {
    border-bottom: none;
}

.subaction-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
    margin-top: 2px;
}

.subaction-icon.check { background: #e3f2fd; color: #1976d2; }
.subaction-icon.write { background: #e8f5e9; color: #388e3c; }
.subaction-icon.read { background: #fff8e1; color: #f57c00; }
.subaction-icon.error { background: #ffebee; color: #d32f2f; }
.subaction-icon.heal { background: #f3e5f5; color: #7b1fa2; }

.subaction-content {
    flex: 1;
}

.subaction-label {
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.subaction-detail {
    font-family: 'SF Mono', Menlo, monospace;
    font-size: 11px;
    color: var(--text);
    word-break: break-all;
}

.subaction-result {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: auto;
    flex-shrink: 0;
}

.subaction-result.success { background: #e8f5e9; color: #388e3c; }
.subaction-result.found { background: #e8f5e9; color: #388e3c; }
.subaction-result.not-found { background: #fff8e1; color: #f57c00; }
.subaction-result.available { background: #e8f5e9; color: #388e3c; }
.subaction-result.duplicate { background: #ffebee; color: #d32f2f; }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    max-width: 90%;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 1000;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.95);
    transition: var(--transition);
}

.modal-overlay.visible .modal {
    transform: scale(1);
}

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

/* Table in modal */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th,
.data-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table td {
    font-family: 'SF Mono', Menlo, monospace;
    font-size: 11px;
}

/* Detail list in modal */
.detail-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.detail-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.detail-value {
    font-size: 12px;
    font-weight: 500;
    text-align: right;
}

.detail-value.success { color: var(--green); }
.detail-value.error { color: var(--red); }

.project-header {
    font-size: 13px;
    font-weight: 600;
    margin: 16px 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.project-header:first-child {
    margin-top: 0;
}

.empty-state {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    padding: 12px 0;
}

/* Responsive */
@media (max-width: 1100px) {
    .content-layout {
        flex-direction: column;
    }

    .history-section,
    .version-info-section {
        width: 100%;
    }

    .content-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    .right-content {
        grid-column: 1 / -1;
        order: -1;
    }
}

@media (max-width: 700px) {
    .content-layout {
        display: flex;
        flex-direction: column;
    }

    .right-content {
        order: 0;
    }
}

@media (max-width: 600px) {
    .controls-bar {
        flex-direction: column;
        gap: 16px;
    }

    .schema-section {
        flex-direction: column;
    }

    .schema-arrow {
        transform: rotate(90deg);
    }

    .schema-card {
        width: 100%;
        max-width: 240px;
    }
}
