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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 0;
    overflow-x: hidden;
}

.container {
    max-width: 100%;
    margin: 0;
    background: white;
    border-radius: 0;
    box-shadow: none;
    padding: 12px;
    min-height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 6px;
    font-size: 1.4em;
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 1001;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    opacity: 0.3;
}

.view-toolbar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 6px;
    border-radius: 8px;
    margin-bottom: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.view-toolbar label {
    color: white;
    font-weight: 600;
    font-size: 13px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 180px;
    height: 36px;
    margin-bottom: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.3);
    transition: 0.4s;
    border-radius: 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.slider-label {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    transition: 0.4s;
    z-index: 2;
    pointer-events: none;
    margin-bottom: 0;
}

.slider-label.active {
    color: #667eea;
}

.slider-label.left {
    margin-left: 5px;
}

.slider-label.right {
    margin-right: 5px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 30px;
    width: 85px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

input:checked + .slider:before {
    transform: translateX(87px);
}

.main-grid {
    display: grid;
    grid-template-columns: 380px 1fr 300px;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
}

.left-panel::-webkit-scrollbar {
    width: 6px;
}

.left-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.left-panel::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.middle-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow: hidden;
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
}

.right-panel::-webkit-scrollbar {
    width: 6px;
}

.right-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.right-panel::-webkit-scrollbar-thumb {
    background: #28a745;
    border-radius: 10px;
}

.history-panel {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 8px;
    border-left: 4px solid #28a745;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.history-panel h3 {
    color: #28a745;
    margin-bottom: 6px;
    font-size: 0.95em;
    flex-shrink: 0;
}

.history-content {
    background: white;
    padding: 8px;
    border-radius: 5px;
    flex: 1;
    overflow-y: auto;
}

.history-panel-bottom {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    z-index: 999;
    height: 50vh;
    transform: translateY(calc(100% - 40px));
}

.history-panel-bottom.expanded {
    transform: translateY(0);
}

.history-panel-bottom .history-panel {
    border: none;
    border-radius: 0;
    height: calc(100% - 40px);
    background: #f8f9fa;
    padding: 10px;
    border-left: 4px solid #28a745;
}

.history-drawer-handle {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: #f8f9fa;
    border-top: 2px solid #e0e0e0;
    user-select: none;
    position: relative;
}

.history-drawer-handle:active {
    background: #e9ecef;
}

.drawer-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.drawer-notch {
    width: 40px;
    height: 4px;
    background: #28a745;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.drawer-icon {
    color: #28a745;
    font-weight: bold;
    font-size: 14px;
    transition: transform 0.3s ease;
}

.history-panel-bottom.expanded .drawer-icon {
    transform: rotate(180deg);
}

.drawer-title {
    color: #28a745;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info {
    background: #d1ecf1;
    padding: 8px;
    border-radius: 5px;
    border-left: 4px solid #17a2b8;
    font-size: 12px;
    flex-shrink: 0;
}

.signal-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.signal-btn {
    padding: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.signal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

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

.function-display {
    background: #f8f9fa;
    padding: 8px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    flex-shrink: 0;
}

.function-display h3 {
    color: #667eea;
    margin-bottom: 6px;
    font-size: 0.95em;
    padding: 0 4px;
}

.function-text {
    font-size: 1.3rem;
    font-weight: 600;
    color: #495057;
    background: white;
    padding: 8px;
    border-radius: 5px;
    word-wrap: break-word;
    font-family: 'Courier New', monospace;
    min-height: 40px;
    max-height: 100px;
    overflow-x: auto;
}

.storage-display {   
    background: white;
    border-radius: 5px;
    margin-bottom: 8px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
}

.storage-display::-webkit-scrollbar {
    width: 5px;
}

.storage-display::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.storage-display::-webkit-scrollbar-thumb {
    background: #007bff;
    border-radius: 10px;
}

.storage-empty {
    color: #6c757d;
    font-style: italic;
    padding: 6px;
    font-size: 12px;
}

.storage-item {
    background: #e7f3ff;
    padding: 7px;
    border-radius: 5px;
    margin-bottom: 6px;
    border-left: 3px solid #007bff;
    cursor: pointer;
    transition: all 0.2s;
}

.storage-item:hover {
    background: #d0e7ff;
    transform: translateX(2px);
}

.storage-item-label {
    font-size: 10px;
    font-weight: 700;
    color: #007bff;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.storage-item-notation {
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    font-family: 'Courier New', monospace;
    word-wrap: break-word;
}

.storage-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 6px;
}

.btn-store {
    padding: 8px;
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: transform 0.2s;
}

.btn-store:hover {
    transform: translateY(-2px);
}

.btn-clear-storage {
    padding: 8px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: transform 0.2s;
}

.btn-clear-storage:hover {
    transform: translateY(-2px);
}

.history-content::-webkit-scrollbar {
    width: 5px;
}

.history-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.history-content::-webkit-scrollbar-thumb {
    background: #28a745;
    border-radius: 10px;
}

.history-empty {
    color: #6c757d;
    font-style: italic;
    text-align: center;
    padding: 12px 8px;
    font-size: 12px;
}

.history-block {
    background: #e8f5e9;
    padding: 7px;
    border-radius: 5px;
    border-left: 3px solid #28a745;
    margin-bottom: 7px;
}

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

.step-label {
    font-size: 10px;
    font-weight: 700;
    color: #28a745;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.signal-text {
    font-size: 12px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 3px;
    word-wrap: break-word;
    font-family: 'Courier New', monospace;
}

.operation-text {
    font-size: 11px;
    color: #6c757d;
    font-style: italic;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.btn-primary {
    padding: 8px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: transform 0.2s;
}

.btn-secondary {
    padding: 8px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: transform 0.2s;
}

.btn-transfer {
    padding: 9px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: transform 0.2s;
    width: 100%;
    flex-shrink: 0;
    margin-top: 6px;
}

.btn-clear-history {
    padding: 7px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    font-size: 11px;
    transition: transform 0.2s;
    margin-top: 6px;
    flex-shrink: 0;
}

.btn-primary:hover, .btn-secondary:hover, .btn-transfer:hover, .btn-clear-history:hover {
    transform: translateY(-2px);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 550px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

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

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e9ecef;
}

.modal-header h2 {
    color: #667eea;
    margin: 0;
    font-size: 1.2em;
}

.close {
    font-size: 26px;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
    transition: color 0.3s;
    line-height: 1;
}

.close:hover {
    color: #000;
}

.input-group {
    margin-bottom: 10px;
}

label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    color: #333;
    font-size: 12px;
}

input, select {
    width: 100%;
    padding: 6px 8px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 12px;
    transition: border-color 0.3s;
}

input:focus, select:focus {
    outline: none;
    border-color: #667eea;
}

.param-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.modal-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 15px;
}

.operation-section {
    background: #fff3cd;
    padding: 10px;
    border-radius: 8px;
    border-left: 4px solid #ffc107;
    flex-shrink: 0;
}

.operation-section h3 {
    margin-bottom: 8px;
    color: #856404;
    font-size: 0.95em;
}

.chart-wrapper {
    background: #f8f9fa;
    padding: 8px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.convolution-mode ~ .chart-wrapper {
    flex: 0.6;
}

.chart-title {
    text-align: center;
    font-weight: 600;
    color: #667eea;
    margin-bottom: 6px;
    font-size: 0.95em;
    flex-shrink: 0;
}

.chart-container {
    flex: 1;
    position: relative;
    min-height: 0;
}

.chart-container canvas {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.convolution-mode .chart-container {
    position: static;
    display: block;
}

.conv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    height: 100%;
}

.conv-chart-item {
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 220px;
}

.conv-chart-label {
    font-weight: 600;
    font-size: 12px;
    color: #495057;
    margin-bottom: 6px;
    text-align: center;
    padding: 6px;
    background: #f8f9fa;
    border-radius: 4px;
    flex-shrink: 0;
}

.conv-chart-item canvas {
    position: absolute !important;
    top: 34px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: calc(100% - 34px) !important;
}

.operation-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.operation-info {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.operation-info small {
    font-size: 11px;
    color: #6c757d;
}

@media (max-width: 1400px) {
    .main-grid {
        grid-template-columns: 350px 1fr 280px;
    }
}

@media (max-width: 1200px) {
    .sidebar-toggle {
        display: block;
    }

    .main-grid {
        grid-template-columns: 1fr;
    }

    .left-panel {
        position: fixed;
        left: -100%;
        top: 0;
        width: 380px;
        height: 100vh;
        background: white;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        padding: 70px 15px 15px 15px;
    }

    .left-panel.show {
        left: 0;
    }

    .middle-panel {
        grid-column: 1;
        gap: 6px;
    }

    .right-panel {
        display: none;
    }

    .history-panel-bottom {
        display: flex;
        flex: 0;
        min-height: 220px;
        max-height: 350px;
    }

    .signal-buttons {
        grid-template-columns: repeat(3, 1fr);
    }

    .chart-wrapper {
        padding: 4px;
        min-height: 200px;
    }
    
    .convolution-mode ~ .chart-wrapper {
        flex: 0.7;
        min-height: 150px;
    }

    .chart-title {
        margin-bottom: 2px;
        font-size: 0.85em;
        padding: 2px 0;
    }
    
    .view-toolbar {
        padding: 4px;
        margin-bottom: 4px;
    }

    .conv-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr 1fr !important;
        gap: 6px !important;
    }
    
    .conv-chart-item {
        min-height: 140px !important;
    }
    
    .conv-chart-label {
        font-size: 11px !important;
        padding: 4px !important;
        margin-bottom: 4px !important;
    }
    
    .conv-chart-item canvas {
        top: 28px !important;
        height: calc(100% - 28px) !important;
    }
}

@media (max-width: 768px) {
    body {
        padding: 6px;
    }
    
    .container {
        padding: 10px;
    }
    
    .left-panel {
        width: 100%;
    }

    .signal-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .param-grid {
        grid-template-columns: 1fr;
    }

    .chart-wrapper {
        padding: 3px;
        min-height: 180px;
    }
    
    .convolution-mode ~ .chart-wrapper {
        flex: 0.6;
        min-height: 130px;
    }

    .chart-title {
        font-size: 0.8em;
        margin-bottom: 1px;
    }
    
    .conv-chart-item {
        min-height: 130px !important;
    }
}