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

:root {
    --primary-color: #2563eb;
    --secondary-color: #7c3aed;
    --success-color: #059669;
    --warning-color: #d97706;
    --danger-color: #dc2626;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);

    /* Status colors */
    --status-available: #10b981;
    --status-this-tab: #3b82f6;
    --status-other-tab: #f59e0b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

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

header {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 2rem;
    color: var(--text-primary);
}

.tab-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    color: white;
}

.tab-id-label {
    font-weight: 600;
}

.tab-id {
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: bold;
}

main {
    margin-bottom: 2rem;
}

section {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* Data Table */
.table-view {
    width: 100%;
}

.table-container {
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.entity-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.entity-table thead {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.entity-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.entity-table th:first-child {
    border-top-left-radius: 0.5rem;
}

.entity-table th:last-child {
    border-top-right-radius: 0.5rem;
}

.entity-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.entity-table tbody tr:hover {
    background: var(--bg-color);
    transform: scale(1.01);
}

.entity-table tbody tr::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: transparent;
    transition: all 0.3s ease;
}

.entity-table tbody tr.available::before {
    background: var(--status-available);
}

.entity-table tbody tr.open-here {
    background: linear-gradient(to right, rgba(59, 130, 246, 0.08), transparent);
    border-left: 4px solid var(--status-this-tab);
}

.entity-table tbody tr.open-here::before {
    background: var(--status-this-tab);
    width: 4px;
    animation: pulse 2s ease-in-out infinite;
}

.entity-table tbody tr.open-elsewhere {
    background: linear-gradient(to right, rgba(245, 158, 11, 0.08), transparent);
    border-left: 4px solid var(--status-other-tab);
}

.entity-table tbody tr.open-elsewhere::before {
    background: var(--status-other-tab);
    width: 4px;
}

.entity-table td {
    padding: 1rem;
    color: var(--text-primary);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-badge.available {
    background: rgba(16, 185, 129, 0.1);
    color: var(--status-available);
}

.status-badge.open-here {
    background: rgba(59, 130, 246, 0.1);
    color: var(--status-this-tab);
}

.status-badge.open-elsewhere {
    background: rgba(245, 158, 11, 0.1);
    color: var(--status-other-tab);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-indicator.available {
    background: var(--status-available);
}

.status-indicator.open-here {
    background: var(--status-this-tab);
    animation: pulse 2s ease-in-out infinite;
}

.status-indicator.open-elsewhere {
    background: var(--status-other-tab);
}

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

.entity-type {
    text-transform: capitalize;
    color: var(--text-secondary);
}

.tab-indicator {
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Table Legend */
.table-legend {
    background: var(--bg-color);
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.table-legend h4 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-items {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.legend-indicator {
    width: 16px;
    height: 16px;
    border-radius: 0.25rem;
    display: inline-block;
}

.legend-indicator.available {
    background: var(--status-available);
}

.legend-indicator.open-here {
    background: var(--status-this-tab);
}

.legend-indicator.open-elsewhere {
    background: var(--status-other-tab);
}

/* Open Entities Section */
.open-entities {
    min-height: 200px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 3rem;
    font-style: italic;
}

.open-entity-item {
    background: var(--bg-color);
    border-left: 4px solid var(--primary-color);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-radius: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.open-entity-info {
    flex: 1;
}

.open-entity-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.open-entity-tab {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.this-tab-badge {
    background: var(--status-this-tab);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

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

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

.btn-primary {
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: var(--warning-color);
    color: white;
    padding: 0.75rem 1.5rem;
}

.btn-secondary:hover {
    background: #b45309;
}

.btn-cancel {
    background: var(--text-secondary);
    color: white;
    padding: 0.75rem 1.5rem;
}

.btn-cancel:hover {
    background: #475569;
}

/* Entity Details */
.entity-details {
    animation: slideIn 0.3s ease;
}

.entity-details.hidden {
    display: none;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
    gap: 1rem;
}

.back-btn {
    background: var(--text-secondary);
    color: white;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.back-btn:hover {
    background: #475569;
    transform: translateX(-3px);
}

.close-btn {
    background: var(--danger-color);
    color: white;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.close-btn:hover {
    background: #b91c1c;
}

.details-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.detail-section {
    background: var(--bg-color);
    padding: 1.5rem;
    border-radius: 0.75rem;
    border: 2px solid var(--border-color);
}

.detail-section h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border-color);
}

.detail-row {
    display: flex;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--card-bg);
    border-radius: 0.5rem;
    border-left: 4px solid var(--primary-color);
}

.detail-row:last-child {
    margin-bottom: 0;
}

.detail-row strong {
    min-width: 150px;
    color: var(--text-secondary);
    font-weight: 600;
}

.detail-row span {
    color: var(--text-primary);
    font-size: 1.05rem;
}

.awareness-info {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.awareness-description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    padding: 1rem;
    background: rgba(37, 99, 235, 0.05);
    border-radius: 0.5rem;
    border-left: 4px solid var(--primary-color);
}

.other-tabs-viewing {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.viewing-tab-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 0.5rem;
    border: 2px solid var(--border-color);
}

.viewing-tab-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.viewing-tab-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success-color);
    animation: pulse 2s ease-in-out infinite;
}

.viewing-tab-label {
    font-family: monospace;
    font-weight: 600;
    color: var(--text-primary);
}

.viewing-tab-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.no-other-tabs {
    text-align: center;
    color: var(--text-secondary);
    padding: 1.5rem;
    font-style: italic;
}

/* Row Popover Menu */
.row-popover {
    position: fixed;
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border-color);
    z-index: 1500;
    min-width: 280px;
    animation: popoverSlideIn 0.2s ease;
}

.row-popover.hidden {
    display: none;
}

@keyframes popoverSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    border-radius: 0.75rem 0.75rem 0 0;
}

.popover-entity-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.popover-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
}

.popover-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.popover-menu {
    padding: 0.5rem;
}

.popover-menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    border: none;
    background: transparent;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.popover-menu-item:hover {
    background: var(--bg-color);
    transform: translateX(4px);
}

.popover-menu-item:active {
    transform: translateX(4px) scale(0.98);
}

.menu-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.menu-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    flex: 1;
}

.menu-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.menu-description {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    animation: slideUp 0.3s ease;
}

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

.modal-content h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Debug Console */
.debug-section {
    grid-column: 1 / -1;
    margin-top: 0;
}

.debug-log {
    background: #1e293b;
    color: #94a3b8;
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.8;
}

.debug-log::-webkit-scrollbar {
    width: 8px;
}

.debug-log::-webkit-scrollbar-track {
    background: #0f172a;
    border-radius: 0.5rem;
}

.debug-log::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 0.5rem;
}

.log-entry {
    margin-bottom: 0.25rem;
    padding: 0.25rem 0;
}

.log-time {
    color: #64748b;
    margin-right: 0.5rem;
}

.log-type {
    font-weight: 600;
    margin-right: 0.5rem;
}

.log-type.info {
    color: #3b82f6;
}

.log-type.success {
    color: #10b981;
}

.log-type.warning {
    color: #f59e0b;
}

.log-type.error {
    color: #ef4444;
}

.clear-log-btn {
    background: var(--text-secondary);
    color: white;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
}

.clear-log-btn:hover {
    background: #475569;
}

/* Attention Banner */
.attention-banner {
    position: fixed;
    top: -100px;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    padding: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    transition: top 0.3s ease-out;
}

.attention-banner.show {
    top: 0;
}

.attention-banner-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 1.1rem;
    font-weight: 600;
}

.attention-icon {
    font-size: 2rem;
    animation: wave 1s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    75% { transform: rotate(-20deg); }
}

.attention-banner strong {
    color: #fef3c7;
    margin-left: 0.5rem;
}

.dismiss-banner {
    margin-left: auto;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
    padding: 0.5rem 1rem;
    font-weight: 600;
    cursor: pointer;
}

.dismiss-banner:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Responsive Design */
@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
    }
}

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

    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .entity-list {
        grid-template-columns: 1fr;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions button {
        width: 100%;
    }

    .attention-banner-content {
        font-size: 1rem;
        justify-content: center;
    }

    .dismiss-banner {
        width: 100%;
        margin-left: 0;
    }
}
