/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    color: #ffffff;
    overflow: hidden;
    height: 100vh;
    direction: rtl;
}

/* Header */
.header {
    background: rgba(26, 26, 46, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
}

.logo {
    font-size: 1.8rem;
    font-weight: bold;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(102, 126, 234, 0.3);
}

.header-actions {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.header-actions .btn {
    padding: 0.7rem 0.9rem;
    gap: 0;
}

.header-actions .btn:hover {
    padding: 0.7rem 1.4rem;
}

.header-actions .btn .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-actions .btn .label {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-width 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
    white-space: nowrap;
    margin-right: 0;
}

.header-actions .btn:hover .label {
    max-width: 150px;
    opacity: 1;
    margin-right: 0.6rem;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 6px;
}

.btn-danger {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(56, 239, 125, 0.4);
}

/* Main Container */
.main-container {
    display: flex;
    height: calc(100vh - 80px);
    overflow: hidden;
    position: relative;
}

/* Floating Panels */
.floating-panel {
    position: absolute;
    z-index: 100;
    background: rgba(26, 26, 46, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, height 0.3s ease;
}

#tools-panel {
    width: 200px;
}

#components-panel {
    width: 240px;
}

#about-panel {
    width: 260px;
}

.panel-header {
    background: rgba(255, 255, 255, 0.06);
    padding: 0.7rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: move;
    user-select: none;
}

.panel-icon {
    font-size: 1.1rem;
    margin-left: 0.5rem;
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #667eea;
    flex-grow: 1;
    text-align: right;
}

.panel-minimize-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-minimize-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.panel-body {
    padding: 1.2rem;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

/* Minimized State */
.floating-panel.minimized {
    width: auto !important;
    max-width: max-content;
}

.floating-panel.minimized .panel-body {
    max-height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.floating-panel.minimized .panel-header {
    border-bottom-color: transparent;
}

/* Horizontal Panel Mode */
.floating-panel.horizontal {
    flex-direction: row;
    align-items: center;
    height: 60px !important;
    width: auto !important;
    max-width: 90vw;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
}

.floating-panel.horizontal .panel-header {
    border-bottom: none;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    height: 100%;
    padding: 0 0.8rem;
}

.floating-panel.horizontal .panel-body {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: 100%;
    padding: 0 1rem;
    max-height: none;
    overflow-y: visible;
    overflow-x: auto;
    gap: 1.5rem;
}

.floating-panel.horizontal .palette-section {
    margin-bottom: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.floating-panel.horizontal .palette-section h4 {
    margin-bottom: 0;
    margin-left: 0.5rem;
    white-space: nowrap;
    font-size: 0.75rem;
}

.floating-panel.horizontal .tool-btn,
.floating-panel.horizontal .component-btn,
.floating-panel.horizontal .action-btn {
    margin-bottom: 0;
    padding: 0.4rem 0.6rem;
    width: auto;
    gap: 0;
    font-size: 0.85rem;
}

.floating-panel.horizontal .shortcut {
    padding: 0;
    gap: 0.5rem;
}

.floating-panel.horizontal .about-section {
    margin-top: 0 !important;
    padding-top: 0 !important;
    border-top: none !important;
    display: flex;
    align-items: center;
}

.floating-panel.horizontal .about-content {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.floating-panel.horizontal .about-content p {
    margin-bottom: 0;
}

.floating-panel.horizontal .panel-minimize-btn {
    display: none; /* Hide minimize button in horizontal mode */
}

.palette-section {
    margin-bottom: 1.5rem;
}

.palette-section:last-child {
    margin-bottom: 0;
}

.palette-section h4 {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tool-btn, .component-btn, .action-btn {
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center; /* Center the icon by default */
    font-size: 0.95rem;
}

.tool-btn:hover, .component-btn:hover, .action-btn:hover {
    background: rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.5);
    transform: translateY(-2px); /* Elegant vertical lift */
}

.tool-btn.active, .component-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.tool-btn .icon, .component-btn .icon, .action-btn .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Hide label text by default, reveal it smoothly on hover (V1.09) */
.tool-btn .label, .component-btn .label, .action-btn .label {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-width 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
    white-space: nowrap;
    margin-right: 0;
}

.tool-btn:hover .label, .component-btn:hover .label, .action-btn:hover .label {
    max-width: 120px;
    opacity: 1;
    margin-right: 0.6rem; /* Shift label slightly to the right of the icon in RTL */
}

/* Two-column layout for vertical components panel (V1.07) */
#components-panel:not(.horizontal) .panel-body {
    padding: 0.8rem;
}

#components-panel:not(.horizontal) .palette-section {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
    margin-bottom: 1.2rem;
}

#components-panel:not(.horizontal) .palette-section h4 {
    grid-column: span 2;
    margin-bottom: 0.3rem;
}

#components-panel:not(.horizontal) .component-btn {
    width: 100%;
    padding: 0.4rem 0.5rem;
    margin-bottom: 0;
    font-size: 0.8rem;
    border-radius: 8px;
    border-width: 1.5px;
    justify-content: center; /* Center the icon by default */
}

#components-panel:not(.horizontal) .component-btn:hover {
    transform: translateY(-2px);
}

#components-panel:not(.horizontal) .component-btn .icon {
    font-size: 1.1rem;
}

/* Help Section */
.help-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.help-section h4 {
    font-size: 0.9rem;
    color: #888;
    margin-bottom: 0.8rem;
}

.shortcut {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.85rem;
    color: #aaa;
}

kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* About Section */
.about-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    font-size: 0.85rem;
}

.about-section h4 {
    font-size: 0.9rem;
    color: #888;
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.about-content {
    color: #aaa;
    line-height: 1.6;
}

.about-content p {
    margin-bottom: 0.4rem;
}

.about-content a {
    color: #667eea;
    text-decoration: none;
    transition: color 0.3s ease;
}

.about-content a:hover {
    color: #764ba2;
    text-decoration: underline;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    position: relative;
}

#circuit-canvas {
    width: 100%;
    height: 100%;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    cursor: crosshair;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 20px;
    padding: 2rem;
    min-width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: modalSlideIn 0.3s ease;
}

.modal-large {
    min-width: 600px;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.5rem;
    color: #667eea;
}

.modal-body {
    margin-bottom: 1.5rem;
}

.input-text {
    width: 100%;
    padding: 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.input-text:focus {
    outline: none;
    border-color: #667eea;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.2);
}

.modal-body label {
    display: block;
    margin-bottom: 0.5rem;
    color: #aaa;
    font-size: 0.9rem;
}

.modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-start;
}

/* Circuits List */
.circuits-list {
    max-height: 400px;
    overflow-y: auto;
}

.circuit-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 0.8rem;
    transition: all 0.3s ease;
}

.circuit-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(102, 126, 234, 0.5);
    transform: translateX(-3px);
}

.circuit-info {
    flex: 1;
}

.circuit-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.circuit-date {
    font-size: 0.85rem;
    color: #888;
}

.circuit-actions {
    display: flex;
    gap: 0.5rem;
}

.loading, .empty-state, .error-state {
    text-align: center;
    padding: 2rem;
    color: #888;
    font-size: 1.1rem;
}

.error-state {
    color: #f5576c;
}

/* Notification */
.notification {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 2rem;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    font-weight: 600;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s ease;
}

.notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.notification-success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.notification-error {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

/* Scrollbar Styling */
.panel-body::-webkit-scrollbar,
.circuits-list::-webkit-scrollbar {
    width: 6px;
}

.panel-body::-webkit-scrollbar-track,
.circuits-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
}

.panel-body::-webkit-scrollbar-thumb,
.circuits-list::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 10px;
}

.panel-body::-webkit-scrollbar-thumb:hover,
.circuits-list::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.6);
}

/* Responsive Design */
@media (max-width: 768px) {
    .floating-panel {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
        width: 100% !important;
        margin-bottom: 1rem;
    }

    .main-container {
        flex-direction: column;
        overflow-y: auto;
    }

    .canvas-container {
        min-height: 400px;
    }

    .modal {
        min-width: 90vw;
    }
}
